📄 clock.bas
字号:
'------------------- AN 4 -----------------------------
' Copyright 1998-2000 MCS Electronics
' CLOCK.BAS
'This AN shows how to use the PCF8583 I2C clock device
'The PCF8583 is a PHILIPS device. Look at the datasheet for more details
'I have used a prototype board from dontronics with the hardware
'simulator to test the program
'------------------------------------------------------
'declare used subs
Declare Sub Settime(s As Byte , M As Byte , H As Byte , D As Byte , Month As Byte)
Declare Sub Gettime
'Declare variables
Dim S As Byte , M As Byte , H As Byte , D As Byte , Month As Byte
Dim Wm As Byte , Yd As Byte
Call Settime(0 , 0 , 0 , 29 , 11) 'set time
Do
Call Gettime 'get time
Loop
End
Sub Gettime
Dim Dum As Byte
I2cstart 'generate start
I2cwbyte &HA0 'write addres of PCF8583
I2cwbyte 2 'select second register
I2cstart 'generate repeated start
I2cwbyte &HA1 'write address for reading info
I2crbyte S , Ack 'read seconds
I2crbyte M , Ack 'read minutes
I2crbyte H , Ack 'read hours
I2crbyte Yd , Ack 'read year and days
I2crbyte Wm , Nack 'read weekday and month
I2cstop 'generate stop
Print "Time " ; Bcd(h) ; ":" ; Bcd(m) ; ":" ; Bcd(s)
Print "Day : " ; Bcd(yd) ; " Month : " ; Bcd(wm)
Rem you can also use the LCD statement
' Cls
' Lcd "Time " ; Bcd(h) ; ":" ; Bcd(m) ; ":" ; Bcd(s)
' Lcd "Day : " ; Bcd(yd) ; " Month : " ; Bcd(wm)
Rem You Could Also Use The Lcd Statement For Displaying The
Rem Time On The Lcd Display
End Sub
Sub Settime(s As Byte , M As Byte , H As Byte , D As Byte , Month As Byte)
'values are stored as BCD values so convert the values first
S = Makebcd(s) 'seconds
M = Makebcd(m) 'minutes
H = Makebcd(h) 'hours
D = Makebcd(d) 'days
Month = Makebcd(month) 'months
I2cstart 'generate start
I2cwbyte &ha0 'write address
I2cwbyte 0 'select control register
I2cwbyte 8 'set year and day bit for masking
I2cstop 'generate stop
I2cstart 'generate start
I2cwbyte &ha0 'write mode
I2cwbyte 2 'select seconds Register
I2cwbyte S 'write seconds
I2cwbyte M 'write minutes
I2cwbyte H 'Write Hours
I2cwbyte D 'write days
I2cwbyte Month 'write months
I2cstop
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -