Device 16F886 ;De 16F886 wordt gebruikt Config WDT_OFF, PWRTE_ON, LVP_OFF, MCLRE_OFF, HS_OSC ALL_DIGITAL TRUE ;Alle ingangen digitaal XTAL 4 ;Kristal van 20MHz Symbol num = PORTB ;B poorten noemen nu num Symbol Dig1 = PORTA.0 ;uren10 = portA.0 Symbol Dig2 = PORTA.1 ;uren1 = portA.1 Symbol Dig3 = PORTA.2 ;minuten10 = portA.2 Symbol Dig4 = PORTA.3 ;minuten1 = portA.3 Symbol Dig5 = PORTA.4 ;seconden10 = portA.4 Symbol Dig6 = PORTA.5 ;seconden1 = portA.5 Symbol U1 = PORTC.7 ;uren + 1 Symbol U10 = PORTC.6 ;uren + 10 Symbol M1 = PORTC.5 ;minuten + 1 Symbol M10 = PORTC.4 ;minuten + 10 Symbol S1 = PORTC.3 ;seconden + 1 Symbol S10 = PORTC.2 ;seconden + 10 Symbol Slapen = PORTC.1 ;display uit + enable alle toetsen Symbol Reset = PORTC.0 ;reset de klok Dim Klok[6] As Byte ;Maak variabele voor klok (voor de 6 digits) Dim Teller As Word ;Maak variabele voor teller aan ;interrupts Symbol GIE = INTCON.7 ;global interrupt enable Symbol T0IE = INTCON.5 ;TMR0 overflow interrupt enable Symbol T0IF = INTCON.2 ;TMR0 overflow interrupt flag bit Symbol RBIE = INTCON.3 ;PortB change interrupt enable bit Symbol RBIF = INTCON.5 ;PortB change interrupt flag bit Symbol PS0 = OPTION_REG.0 ;Prescaler ratio bit-0 Symbol PS1 = OPTION_REG.1 ;Prescaler ratio bit-1 Symbol PS2 = OPTION_REG.2 ;Prescaler ratio bit-2 Symbol PSA = OPTION_REG.3 ;Prescaler Assignment (1=assigned to WDT 0=assigned to oscillator) Symbol T0CS = OPTION_REG.5 ;Timer0 Clock Source Select (0=Internal instruction cycle clock 1= Transition on T0CKI pin) Clear ; 76543210 PORTA = %00111111 ;PIC opstarten met alle PORTA poorten laag PORTB = %11111111 ;PIC opstarten met alle PORTB poorten laag TRISA = %11000000 ;Maak PORTA.7 en 6 ingang voor kristal TRISB = %00000000 ;Maak PORTB uitgang voor segmenten Klok = 0 ;zet alles op 0 (00:00:00) GIE = 0 ;disable all global interrupts PSA = 0 ;Assign the prescaler to oscillator PS0 = 1 ;Set the prescaler PS1 = 0 ;to increment TMR0 PS2 = 0 ;every 4th instruction cycle T0CS = 0 ;Assign TMR0 clock to internal source T0IE = 1 ;TMR0 overflow interrupt enable T0IF = 1 ;TMR0 overflow interrupt flag bit RBIE = 1 ;portB change interrupt enable RBIF = 1 ;portB change interrupt flag bit GIE = 1 ;enable all global interrupts GoTo Main ; interrupt handler Context SAVE If T0IF = 1 Then ;als timer overloopt dan Inc Teller ;seconde bijtellen If Teller = 977 Then Inc Klok[1] ;timer0 flag bit clearen If Klok[1] >= 10 Then Inc Klok[2] ;hier wordt de klok If Klok[2] >= 6 Then Inc Klok[3] ;gevormd zodat bv na If Klok[3] >= 10 Then Inc Klok[4] ;60 seconden er een If Klok[4] >= 6 Then Inc Klok[5] ;minuut bijgeteld wordt If Klok[5] >= 10 Then Inc Klok[6] If Klok[1] >= 10 Then Clear Klok[1] If Klok[2] >= 6 Then Clear Klok[2] If Klok[3] >= 10 Then Clear Klok[3] If Klok[4] >= 6 Then Clear Klok[4] If Klok[5] >= 10 Then Clear Klok[5] If Klok[6] >= 3 Then Clear Klok[6] If Klok[6] * 10 + Klok[5] >= 24 Then Clear Klok[5] If Klok[6] * 10 + Klok[5] >= 24 Then Clear Klok[6] EndIf T0IF = 0 Context Restore Main: If Slapen = 0 Then GoTo Sleep ;het hoofdprogramma If Klok[1] = 0 Then num = %11111100 ;aansturing van de segmenten If Klok[1] = 1 Then num = %01100000 If Klok[1] = 2 Then num = %11011010 If Klok[1] = 3 Then num = %11110010 If Klok[1] = 4 Then num = %01100110 If Klok[1] = 5 Then num = %10110110 If Klok[1] = 6 Then num = %10111110 If Klok[1] = 7 Then num = %11100000 If Klok[1] = 8 Then num = %11111110 If Klok[1] >= 9 Then num = %11111101 ;extra beveiliging voor als High Dig6 ;de variabele rare dingen DelayMS 1 ;doet Low Dig6 If Klok[2] = 0 Then num = %11110111 If Klok[2] = 1 Then num = %01000101 If Klok[2] = 2 Then num = %11011011 If Klok[2] = 3 Then num = %11011101 If Klok[2] = 4 Then num = %01101101 If Klok[2] = 5 Then num = %11111100 If Klok[2] = 6 Then num = %11111110 If Klok[2] = 7 Then num = %01010101 If Klok[2] = 8 Then num = %11111111 If Klok[2] >= 9 Then num = %11111101 High Dig5 DelayMS 1 Low Dig5 If Klok[3] = 0 Then num = %11110111 If Klok[3] = 1 Then num = %01000101 If Klok[3] = 2 Then num = %11011011 If Klok[3] = 3 Then num = %11011101 If Klok[3] = 4 Then num = %01101101 If Klok[3] = 5 Then num = %11111100 If Klok[3] = 6 Then num = %11111110 If Klok[3] = 7 Then num = %01010101 If Klok[3] = 8 Then num = %11111111 If Klok[3] >= 9 Then num = %11111101 High Dig4 DelayMS 1 Low Dig4 If Klok[4] = 0 Then num = %11110111 If Klok[4] = 1 Then num = %01000101 If Klok[4] = 2 Then num = %11011011 If Klok[4] = 3 Then num = %11011101 If Klok[4] = 4 Then num = %01101101 If Klok[4] = 5 Then num = %11111100 If Klok[4] = 6 Then num = %11111110 If Klok[4] = 7 Then num = %01010101 If Klok[4] = 8 Then num = %11111111 If Klok[4] >= 9 Then num = %11111101 High Dig3 DelayMS 1 Low Dig3 If Klok[5] = 0 Then num = %11110111 If Klok[5] = 1 Then num = %01000101 If Klok[5] = 2 Then num = %11011011 If Klok[5] = 3 Then num = %11011101 If Klok[5] = 4 Then num = %01101101 If Klok[5] = 5 Then num = %11111100 If Klok[5] = 6 Then num = %11111110 If Klok[5] = 7 Then num = %01010101 If Klok[5] = 8 Then num = %11111111 If Klok[5] >= 9 Then num = %11111101 High Dig2 DelayMS 1 Low Dig2 If Klok[6] = 0 Then num = %11111100 If Klok[6] = 1 Then num = %01100000 If Klok[6] = 2 Then num = %11011010 If Klok[6] = 3 Then num = %11110010 If Klok[6] = 4 Then num = %01100110 If Klok[6] = 5 Then num = %10110110 If Klok[6] = 6 Then num = %10111110 If Klok[6] = 7 Then num = %11100000 If Klok[6] = 8 Then num = %11111110 If Klok[6] >= 9 Then num = %11111101 High Dig1 DelayMS 1 Low Dig1 GoTo Main Sleep: While Slapen = 0 Wend While Slapen = 1 Wend GoTo Main End