'-------------------------------------------------------------- ' (c)1997-1999 Mirko Pelcl ' Slovenie '-------------------------------------------------------------- ' CLOCK with the LED display ' ' Demo project ' '-------------------------------------------------------------- 'Connect common cathode LED displays as following : 'a = P1.0 f = P1.5 ones display P3.7 'b = P1.1 g = P1.6 thens display P3.5 'c = P1.2 'd = P1.3 'e = P1.4 '-------------------------------------------------------------- Dim Clock As Byte , Clock1 As Byte , Mux As Byte , X As Byte , Sekunde As Byte Dim Pomozna_v As Byte , Segmenti As Byte , Enice As Byte , Desetice As Byte Dim Prikaz As Bit , Izracun As Bit Config Timer0 = Timer , Gate = Internal , Mode = 2 'Timer0 use timer 0 'Gate = Internal no external interrupt 'Mode = 2 8 bit auto reload On Timer0 Timer_0_int 'interrupt routine Load Timer0 , 250 Priority Set Timer0 'highest priority Enable Interrupts Enable Timer0 Start Timer0 'TR0 = 1 Clock = 0 Clock1 = 0 Sekunde = 0 Do If Izracun = 1 Then ' Izracun=calculation every second Izracun = 0 Desetice = Sekunde / 10 Pomozna_v = Desetice * 10 Enice = Sekunde - Pomozna_v Print Sekunde 'remark this line for none serial output End If If Prikaz = 1 Then Prikaz = 0 ' multipleks speed is 5ms (20*250us) P3.5 = 1 ' P3.5 and P3.7 are digit drivers (for ones&tens) P3.7 = 1 ' 1 , 1 both digits OFF If Mux = 0 Then Pomozna_v = Desetice Gosub Prikaz P3.5 = 0 ' tens display End If If Mux = 2 Then Pomozna_v = Enice Gosub Prikaz P3.7 = 0 ' ones display End If End If Loop End Timer_0_int: Inc Clock If Clock > 19 Then Clock = 0 Prikaz = 1 Inc Mux If Mux > 3 Then Mux = 0 End If Inc Clock1 If Clock1 > 199 Then Clock1 = 0 Izracun = 1 Inc Sekunde If Sekunde > 59 Then Sekunde = 0 End If End If End If Return Prikaz: ' data for LED output Restore Tabela For X = 0 To 9 Read Segmenti If X = Pomozna_v Then 'this is the right value P1 = Segmenti 'set LEDS on Exit For 'found it so abort End If Next Return '---- data for LED human output ------ Tabela: Data 192 , 249 , 164 , 176 , 153 , 146 , 130 , 248 , 128 , 144