Vous êtes sur la page 1sur 4

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

BAS * '* Author : James Cutler VK2TIM * '* Notice : Copyright (c) 2009 James Cutler * '* : All Rights Reserved * '* Date : 1/11/2009 * '* Version : 1.1 * '* 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_PR OTECT_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,BCD 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 f or 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 mod e 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.1 by VK2TIM" DelayMS 5000 Cls getrtc: 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 Cursor 1,1 GoSub showtime Cursor 2,1 GoSub showdate GoSub delay GoSub keyscan

GoTo getrtc sec: SS = $00 GoSub wrtdata Cls Print At 1 , 1 , "Reset seconds " 'Text for instructional value only Cursor 2,1 GoSub showtime GoSub delay GoSub keyscan Cls GoTo getrtc mn: BCD = $00 MM = MM + 1 BCD = MM & $0F If MM > $59 Then MM = 0 ElseIf BCD = $0A Then MM = MM + $06 EndIf GoSub wrtdata Cls Print At 1 , 1 , "Setting Minutes " 'Text for instructional value only Cursor 2,1 GoSub showtime 'Jump to routine to show the time in HH:MM:SS GoSub delay GoSub keyscan 'Check for buttonpress Cls GoTo getrtc hr: BCD = $00 HH = HH + 1 BCD = HH & $0F If HH > $23 Then HH = 0 ElseIf BCD = $0A Then HH = HH + $06 EndIf GoSub wrtdata Cls Print At 1 , 1 , "Setting Hours " 'Text for instructional value only Cursor 2,1 GoSub showtime 'Prints the time in HH:MM:SS GoSub delay GoSub keyscan Cls GoTo getrtc day: BCD = $00 DY = DY + 1 BCD = DY & $0F If BCD = $0A 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 Cursor 2,1 GoSub showdate GoSub delay GoSub keyscan Cls GoTo getrtc mnth: BCD = $00 MO = MO + 1 BCD = MO & $0F If MO > $12 Then MO = $01 ElseIf BCD = $0A Then MO = MO + $06 EndIf GoSub wrtdata Cls Print At 1 , 1 , "Setting Month Cursor 2,1 GoSub showdate GoSub delay GoSub keyscan Cls GoTo getrtc year: BCD = $00 YR = YR + 1 BCD = YR & $0F If YR > $99 Then YR = $00 ElseIf BCD = $0A Then YR = YR + $06 EndIf GoSub wrtdata Cls Print At 1 , 1 , "Setting Year Cursor 2,1 GoSub showdate GoSub delay GoSub keyscan Cls GoTo getrtc wrtdata: BStart BusOut %11010000,00,[SS] BusOut %11010000,01,[MM] BusOut %11010000,02,[HH] BusOut %11010000,04,[DY] BusOut %11010000,05,[MO]

"

'Text for instructional value only

"

'Text for instructional value only

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 showdate: If YR < 10 Then Print "Date ", HEX DY ,"/", HEX MO ,"/200", HEX YR Else Print "Date ", HEX DY ,"/", HEX MO ,"/20", HEX YR EndIf Return showtime: If SS<10 And MM<10 Then Print "Time ", HEX HH ,":0",HEX MM ,":0",HEX SS ," " ElseIf SS<10 Then Print "Time ", HEX HH ,":",HEX MM ,":0",HEX SS ," " ElseIf MM<10 Then Print "Time ", HEX HH ,":0",HEX MM ,":",HEX SS ," " Else Print "Time ", HEX HH ,":",HEX MM ,":",HEX SS ," " 'Print date and d leading zero's where needed EndIf Return keyscan: If PORTB.0 = 0 And PORTB.3 = 1 Then GoTo sec 'If PortB Bit 0 w, jump to routine to set the seconds to 0 If PORTB.1 = 0 And PORTB.3 = 1 Then GoTo mn 'If PortB Bit 1 w, jump to routine to increment Minutes If PORTB.2 = 0 And PORTB.3 = 1 Then GoTo hr 'If PortB Bit 2 w, jump To routine To increment Minutes If PORTB.0 = 0 And PORTB.3 = 0 Then GoTo day 'If PortB Bit 3 w, 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 w, 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 w, and PortB Bit 2 is pulled low, set the year Return delay: DelayMS 500 Return

time, and ad

is pulled lo is pulled lo is pulled lo is pulled lo is pulled lo is pulled lo

Vous aimerez peut-être aussi