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 Nul: 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 Opnieuw ; 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 ; segmentenlijst Seg0: ;segmentenlijst (voor de segmenten zonder DP) num = %11111100 Return Seg1: num = %01100000 Return Seg2: num = %11011010 Return Seg3: num = %11110010 Return Seg4: num = %01100110 Return Seg5: num = %10110110 Return Seg6: num = %10111110 Return Seg7: num = %11100000 Return Seg8: num = %11111110 Return Seg9: num = %11110110 Return Seg00: ;segmentenlijst (voor de segmenten met DP) num = %11110111 Return Seg01: num = %01000101 Return Seg02: num = %11011011 Return Seg03: num = %11011101 Return Seg04: num = %01101101 Return Seg05: num = %11111100 Return Seg06: num = %11111110 Return Seg07: num = %01010101 Return Seg08: num = %11111111 Return Seg09: num = %11111101 Return Hs1: ;instructies voor knoppen Inc Klok[6] GoTo Main Hs10: Inc Klok[5] GoTo Main Mn1: Inc Klok[3] GoTo Main Mn10: Inc Klok[4] GoTo Main Sn1: Inc Klok[1] GoTo Main Sn10: Inc Klok[2] GoTo Main rst: Clear GoTo Main Schak: If U1 = 0 Then GoTo Hs1 If U10 = 0 Then GoTo Hs10 If M1 = 0 Then GoTo Mn1 If M10 = 0 Then GoTo Mn10 If S1 = 0 Then GoTo Sn1 If S10 = 0 Then GoTo Sn10 If Slapen = 0 Then GoTo Sleep If Reset = 0 Then GoTo rst GoTo Main Main: ;het hoofdprogramma If Klok[1] = 0 Then GoSub Seg0 ;aansturing van de segmenten If Klok[1] = 1 Then GoSub Seg1 If Klok[1] = 2 Then GoSub Seg2 If Klok[1] = 3 Then GoSub Seg3 If Klok[1] = 4 Then GoSub Seg4 If Klok[1] = 5 Then GoSub Seg5 If Klok[1] = 6 Then GoSub Seg6 If Klok[1] = 7 Then GoSub Seg7 If Klok[1] = 8 Then GoSub Seg8 If Klok[1] >= 9 Then GoSub Seg9 ;extra beveiliging voor als High Dig6 ;de variabele rare dingen DelayMS 1 ;doet Low Dig6 If Klok[2] = 0 Then GoSub Seg00 If Klok[2] = 1 Then GoSub Seg01 If Klok[2] = 2 Then GoSub Seg02 If Klok[2] = 3 Then GoSub Seg03 If Klok[2] = 4 Then GoSub Seg04 If Klok[2] = 5 Then GoSub Seg05 If Klok[2] = 6 Then GoSub Seg06 If Klok[2] = 7 Then GoSub Seg07 If Klok[2] = 8 Then GoSub Seg08 If Klok[2] >= 9 Then GoSub Seg09 High Dig5 DelayMS 1 Low Dig5 If Klok[3] = 0 Then GoSub Seg00 If Klok[3] = 1 Then GoSub Seg01 If Klok[3] = 2 Then GoSub Seg02 If Klok[3] = 3 Then GoSub Seg03 If Klok[3] = 4 Then GoSub Seg04 If Klok[3] = 5 Then GoSub Seg05 If Klok[3] = 6 Then GoSub Seg06 If Klok[3] = 7 Then GoSub Seg07 If Klok[3] = 8 Then GoSub Seg08 If Klok[3] >= 9 Then GoSub Seg09 High Dig4 DelayMS 1 Low Dig4 If Klok[4] = 0 Then GoSub Seg00 If Klok[4] = 1 Then GoSub Seg01 If Klok[4] = 2 Then GoSub Seg02 If Klok[4] = 3 Then GoSub Seg03 If Klok[4] = 4 Then GoSub Seg04 If Klok[4] = 5 Then GoSub Seg05 If Klok[4] = 6 Then GoSub Seg06 If Klok[4] = 7 Then GoSub Seg07 If Klok[4] = 8 Then GoSub Seg08 If Klok[4] >= 9 Then GoSub Seg09 High Dig3 DelayMS 1 Low Dig3 If Klok[5] = 0 Then GoSub Seg00 If Klok[5] = 1 Then GoSub Seg01 If Klok[5] = 2 Then GoSub Seg02 If Klok[5] = 3 Then GoSub Seg03 If Klok[5] = 4 Then GoSub Seg04 If Klok[5] = 5 Then GoSub Seg05 If Klok[5] = 6 Then GoSub Seg06 If Klok[5] = 7 Then GoSub Seg07 If Klok[5] = 8 Then GoSub Seg08 If Klok[5] >= 9 Then GoSub Seg09 High Dig2 DelayMS 1 Low Dig2 If Klok[6] = 0 Then GoSub Seg0 If Klok[6] = 1 Then GoSub Seg1 If Klok[6] = 2 Then GoSub Seg2 If Klok[6] = 3 Then GoSub Seg3 If Klok[6] = 4 Then GoSub Seg4 If Klok[6] = 5 Then GoSub Seg5 If Klok[6] = 6 Then GoSub Seg6 If Klok[6] = 7 Then GoSub Seg7 If Klok[6] = 8 Then GoSub Seg8 If Klok[6] >= 9 Then GoSub Seg9 High Dig1 DelayMS 1 Low Dig1 GoTo Main Sleep: While Slapen = 0 Wend While Slapen = 1 Wend GoTo Main End