Sunteți pe pagina 1din 5

'**************************************************************** '* Name : 16F88Clock.

BAS * '* Author : James Cutler VK2TIM * '* Notice : Copyright (c) 2009 James Cutler * '* : All Rights Reserved * '* Date : 1/11/2009 * '* Version : 1.0 * '* Notes : This clock interfaces with a Dallas DS1307 * '* : RTC device using I2C. * '**************************************************************** Device = 16F88 @CONFIG_REQ @__CONFIG _CONFIG1, INTRC_IO & PWRTE_ON & MCLR_ON & BODEN_OFF & LVP_OFF & WRT_PROTECT_OFF & CPD_OFF & DEBUG_OFF & WDT_OFF & CCP1_RB0 & FCMEN_OFF & IESO_OFF OSCCON = OSCCON | %01100000 OSCCON = OSCCON & %11101100 CMCON = 0 TRISA = %11100000 TRISB = %00001111 ALL_DIGITAL = TRUE PORTB_PULLUPS = TRUE Dim SS,MM,HH,DY,MO,YR,CH As Byte SS = 0 : MM = 0 : HH = 0 : DY = 0 : MO = 0 : YR = 0 Declare LCD_DTPIN PORTB.4 'Sets up the high 4 bits of PortB as the data pins for the LCD Low PORTA.3 Declare LCD_ENPIN PORTA.4 'Defines Port A Bit 4 as the LCD's Enable pin Declare LCD_RSPIN PORTA.2 'Defines Port A Bit 2 as the LCD's RS pin Declare LCD_INTERFACE 4 'Specify that we are talking to the LCD in 4 bit mode Declare LCD_LINES 2 Declare SLOW_BUS TRUE BStart BusIn %11010001,00,[CH] BStop If CH > $7F Then CH = CH - $80 BStart BusOut %11010001,00,[CH] BStop Cls Print At 1,1," LCD Clock" Print At 2,1,"V1.0 by VK2TIM" DelayMS 5000 Cls showtime: BStart BusIn %11010001,00,[SS] BusIn %11010001,01,[MM] BusIn %11010001,02,[HH] BusIn %11010001,04,[DY] BusIn %11010001,05,[MO] BusIn %11010001,06,[YR] BStop If YR < 10 Then

Print At 1 , 1 , "Date ", HEX DY ,"/", HEX MO ,"/200", HEX YR Else Print At 1 , 1 , "Date ", HEX DY ,"/", HEX MO ,"/20", HEX YR EndIf If SS<10 And MM<10 Then Print At 2 , 1 , "Time ", HEX HH ,":0",HEX MM ,":0",HEX SS ," " ElseIf SS<10 Then Print At 2 , 1 , "Time ", HEX HH ,":",HEX MM ,":0",HEX SS ," " ElseIf MM<10 Then Print At 2 , 1 , "Time ", HEX HH ,":0",HEX MM ,":",HEX SS ," " Else Print At 2 , 1 , "Time ", HEX HH ,":",HEX MM ,":",HEX SS ," " 'Print date and time, and add leading zero's where needed EndIf GoSub delay GoSub keyscan GoTo showtime sec: SS = $00 GoSub wrtdata Cls Print At 1 , 1 , "Reset seconds " 'Text for instructional value only If SS<10 And MM<10 Then Print At 2 , 1 , HEX HH ,":0",HEX MM ,":0",HEX SS ElseIf SS<10 Then Print At 2 , 1 , HEX HH ,":",HEX MM ,":0",HEX SS ElseIf MM<10 Then Print At 2 , 1 , HEX HH ,":0",HEX MM ,":",HEX SS Else Print At 2 , 1 , HEX HH ,":",HEX MM ,":",HEX SS 'Prints the time in HH:MM:SS EndIf GoSub delay GoSub keyscan Cls GoTo showtime mn: MM = MM + 1 If MM > $59 Then MM = 0 ElseIf MM = $0A Then MM = MM + $06 ElseIf MM = $1A Then MM = MM + $06 ElseIf MM = $2A Then MM = MM + $06 ElseIf MM = $3A Then MM = MM + $06 ElseIf MM = $4A Then MM = MM + $06 EndIf GoSub wrtdata Cls Print At 1 , 1 , "Setting Minutes " 'Text for instructional value only If SS<10 And MM<10 Then

Print At 2 , 1 , HEX HH ,":0",HEX MM ,":0",HEX SS ElseIf SS<10 Then Print At 2 , 1 , HEX HH ,":",HEX MM ,":0",HEX SS ElseIf MM<10 Then Print At 2 , 1 , HEX HH ,":0",HEX MM ,":",HEX SS Else Print At 2 , 1 , HEX HH ,":",HEX MM ,":",HEX SS 'Prints the time in HH:MM:SS EndIf GoSub delay GoSub keyscan Cls GoTo showtime hr: HH = HH + 1 If HH > $23 Then HH = 0 ElseIf HH = $0A Then HH = HH + $06 ElseIf HH = $1A Then HH = HH + $06 EndIf GoSub wrtdata Cls Print At 1 , 1 , "Setting Hours " 'Text for instructional value only If SS<10 And MM<10 Then Print At 2 , 1 , HEX HH ,":0",HEX MM ,":0",HEX SS ElseIf SS<10 Then Print At 2 , 1 , HEX HH ,":",HEX MM ,":0",HEX SS ElseIf MM<10 Then Print At 2 , 1 , HEX HH ,":0",HEX MM ,":",HEX SS Else Print At 2 , 1 , HEX HH ,":",HEX MM ,":",HEX SS 'Prints the time in HH:MM:SS EndIf GoSub delay GoSub keyscan Cls GoTo showtime day: DY = DY + 1 If DY = $0A Then DY = DY + $06 ElseIf DY = $1A Then DY = DY + $06 ElseIf DY = $2A Then DY = DY + $06 EndIf If MO = $09 Then GoSub thirty ElseIf MO = $04 Then GoSub thirty ElseIf MO = $06 Then GoSub thirty ElseIf MO = $11 Then GoSub thirty

ElseIf MO = $02 Then GoSub twentynine Else GoSub thirtyone EndIf GoSub wrtdata Cls Print At 1 , 1 , "Setting Day " 'Text for instructional value only If YR < 10 Then Print At 2 , 1 , HEX DY ,"/", HEX MO ,"/0", HEX YR Else Print At 2 , 1 , HEX DY ,"/", HEX MO ,"/", HEX YR EndIf GoSub delay GoSub keyscan Cls GoTo showtime mnth: MO = MO + 1 If MO > $12 Then MO = $01 ElseIf MO = $0A Then MO = MO + $06 EndIf GoSub wrtdata Cls Print At 1 , 1 , "Setting Month " 'Text for instructional value only If YR < 10 Then Print At 2 , 1 , HEX DY ,"/", HEX MO ,"/0", HEX YR Else Print At 2 , 1 , HEX DY ,"/", HEX MO ,"/", HEX YR EndIf GoSub delay GoSub keyscan Cls GoTo showtime year: YR = YR + 1 If YR > $99 Then YR = $00 ElseIf YR = $0A Then YR = YR + $06 ElseIf YR = $1A Then YR = YR + $06 ElseIf YR = $2A Then YR = YR + $06 ElseIf YR = $3A Then YR = YR + $06 ElseIf YR = $4A Then YR = YR + $06 ElseIf YR = $5A Then YR = YR + $06 ElseIf YR = $6A Then YR = YR + $06 ElseIf YR = $7A Then YR = YR + $06

ElseIf YR = $8A Then YR = YR + $06 EndIf GoSub wrtdata Cls Print At 1 , 1 , "Setting Year " 'Text for instructional value only If YR < 10 Then Print At 2 , 1 , HEX DY ,"/", HEX MO ,"/200",HEX YR Else Print At 2 , 1 , HEX DY ,"/", HEX MO ,"/20", HEX YR EndIf GoSub delay GoSub keyscan Cls GoTo showtime wrtdata: BStart BusOut %11010000,00,[SS] BusOut %11010000,01,[MM] BusOut %11010000,02,[HH] BusOut %11010000,04,[DY] BusOut %11010000,05,[MO] BusOut %11010000,06,[YR] BStop Return thirty: If DY > $30 Then DY = $01 Return thirtyone: If DY > $31 Then DY = $01 Return twentynine: If DY > $29 Then DY = $01 Return keyscan: If PORTB.0 = 0 And PORTB.3 = 1 Then GoTo sec 'If PortB Bit 0 pulled low, jump to routine to set the seconds to 0 If PORTB.1 = 0 And PORTB.3 = 1 Then GoTo mn 'If PortB Bit 1 pulled low, jump to routine to increment Minutes If PORTB.2 = 0 And PORTB.3 = 1 Then GoTo hr 'If PortB Bit 2 pulled low, jump To routine To increment Minutes If PORTB.0 = 0 And PORTB.3 = 0 Then GoTo day 'If PortB Bit 3 pulled low, and PortB Bit 0 is pulled low, set the day If PORTB.1 = 0 And PORTB.3 = 0 Then GoTo mnth 'If PortB Bit 3 pulled low, and PortB Bit 1 is pulled low, set the month If PORTB.2 = 0 And PORTB.3 = 0 Then GoTo year 'If PortB Bit 3 pulled low, and PortB Bit 2 is pulled low, set the year Return delay: DelayMS 500 Return

is is is is is is

S-ar putea să vă placă și