- 阅读权限
- 150
- UID
- 7
- 帖子
- 140
- 精华
- 0
- 注册时间
- 2013-2-26
- 在线时间
- 20 小时
- UID
- 7
- 帖子
- 140
- 精华
- 0
- 注册时间
- 2013-2-26
- 在线时间
- 20 小时
|
'///////////////////////////////////////////////
'/// 目 的:1602 LCD时钟,按键调整 ///
'/// 实 验 板:M16精品试验板V3.0 ///
'/// 编 译 器:BASCOM-AVR 1.11.8.2 ///
'/// 文 件 名:LCD-KEY-SY2.BAS ///
'/// 日 期:2006年12月02日 ///
'/// 作 者:铜河 ///
'/// 编译情况:通过,364 words ///
'/// 联线情况:J42-12,J43-12 ///
'///////////////////////////////////////////////
$regfile = "m16def.dat" '使用CPU为M16
$crystal = 7372800 '晶体频率
$baud = 9600
Config Sda = Portc.1
Config Scl = Portc.0 '定义I2C端口
Config I2cdelay = 5
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , Rs = Portb.4 , E = Portb.2
Config Lcd = 16 * 2
Ddra.6 = 1
Spk Alias Porta.6
'/////////////////变量声明///////////////////
Dim A As Byte , K As Byte , K1 As Byte
Dim K2 As Byte , K3 As Byte
Dim S As Byte , M As Byte , H As Byte
Dim Day As Byte , Mouth As Byte , Week As Byte
Dim Nian As Byte , D As Byte
Dim Sj_sj As Bit , Set_bz As Bit
Dim Tm(10) As Byte '时间日历数据
Dim Show(7) As String * 3 '调整时显示字符
'/////////////////常量声明///////////////////
Show(1) = "sec"
Show(2) = "min"
Show(3) = "hou"
Show(4) = "day"
Show(5) = "wek"
Show(6) = "mon"
Show(7) = "yer"
'//////////////////主程序////////////////////
Set Spk
Cls
Locate 1 , 5
Lcd "Velecom!"
Waitms 50
Locate 2 , 2
Lcd "Zhou-changhong"
Wait 1
'//////////////////主循环////////////////////
Do
Gosub Rd_key
If K <> 0 Then
K3 = K
Waitms 20
Gosub Rd_key
If K = K3 Then
Gosub Spk_1ds
Select Case K
Case 1
' Gosub Time_stop
Case 2
Case 4
' Gosub Time_start
Case 8
' Gosub Wr_time
End Select
While K = K3 '等待按键释放
Gosub Rd_key
Wend
End If
End If
Gosub Rd_time
Waitms 20
Gosub Szxs
Waitms 20
Loop
'///////////////时钟显示子程序///////////////
Szxs:
Locate 1 , 1
If Sj_sj = 0 Then
Lcd 20
Else
Lcd 19
End If
Locate 1 , 3
Lcd Hex(nian) ; "/" ; Hex(mouth) ; "th/" ; Hex(day) ; "day"
Print "20" ; Hex(nian); "/" ; Hex(mouth) ; "th/" ; Hex(day) ; "day"
Locate 2 , 1
Lcd Hex(h) ; ":" '显示时数据
Locate 2 , 4
Lcd Hex(m) ; ":" '显示分数据
Locate 2 , 7
Lcd Hex(s) ; " " ; "Week" '显示秒数据
Locate 2 , 14
Lcd Hex(week) '显示星期数据
Print Hex(h) ; ":" ; Hex(m) ; ":" ; Hex(s) ; " " ; "Week" ; Hex(week)
' print hex(\n)
Return
'////////////蜂鸣器响一短声子程序///////////
Spk_1ds:
Reset Spk
Waitms 100
Set Spk
Waitms 100
Return
'///////////////读取按键子程序///////////////
Rd_key:
Ddrc = 0 '端口C改为输入
Portc = Portc Or &HF0 '键盘端口上拉
Waitms 10
K = Pinc Or &H0F '读入C口按键数据
K = Not K
Shift K , Right , 4
' Swap K
Ddrc = 255 '端口C恢复为输出
Return
'///////////////写入时间子程序///////////////
Wr_time:
I2cstart
I2cwbyte &HA2 'PCF8563的器件识别地址
I2cwbyte 1 '选择寄存器2
Waitms 6
I2cwbyte 0 '写入控制寄存器2
Waitms 6
I2cwbyte 0 '写入秒数据(地址2)
Waitms 6
I2cwbyte &H31 '写入分数据(地址3)
Waitms 6
I2cwbyte &H11 '写入小时数据(地址4)
Waitms 6
I2cwbyte &H03 '写入日数据(地址5)
Waitms 6
I2cwbyte 0 '写入星期数据(地址6)
Waitms 6
I2cwbyte &H12 '写入月/世纪数据(地址7)
Waitms 6
I2cwbyte &H06 '写入年数据(地址8)
Waitms 6
I2cstop
Return
'///////////////读取时间子程序///////////////
Rd_time:
I2cstart
I2cwbyte &HA2 'PCF8563的器件识别地址
I2cwbyte 2 '选择寄存器2
I2cstart 'PCF8563的器件识别地址
I2cwbyte &HA3
I2crbyte S , Ack '读秒数据
S = S And &H7F '保留低7位有效数字
I2crbyte M , Ack '读分数据
M = M And &H7F '保留低7位有效数字
I2crbyte H , Ack '读时数据
H = H And &H3F '保留低6位有效数字
I2crbyte Day , Ack '读日数据
Day = Day And &H3F '保留低6位有效数字
I2crbyte Week , Ack '读星期数据
Week = Week And &H03 '保留低3位有效数字
If Week = 0 Then Week = 7 '将星期天转换为week7
I2crbyte Mouth , Ack '读月数据
Sj_sj = Mouth.7 '世纪数据
Mouth = Mouth And &H1F '保留低5位有效数字
I2crbyte Nian , Nack '读年数据
I2cstop '停止I2C
Return
'///////////////启动计时子程序///////////////
Time_start:
I2cstart
I2cwbyte &HA2 'PCF8563的器件识别地址
I2cwbyte 0 '地址
Waitms 6
I2cwbyte 0 '启动数据
Waitms 6
I2cstop
Return
'///////////////停止计时子程序///////////////
Time_stop:
I2cstart
I2cwbyte &HA2 'PCF8563的器件识别地址
I2cwbyte 0
Waitms 6
I2cwbyte &H20 '停止数据
Waitms 6
I2cstop
Return |
|