圣龙扬特-AVR电子
标题:
bascom 读取1302的仿真
[打印本页]
作者:
赵彬
时间:
2013-2-27 22:54
标题:
bascom 读取1302的仿真
$regfile = "m16def.dat"
$crystal = 4000000
'定义液晶显示器
Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portd.6 , Db7 = Portd.7 , E = Portd.1 , Rs = Portd.0
Config Lcd = 16 * 2
'引脚输出
Ddrb.0 = 1
'数据引脚
Ddrb.1 = 1
'时钟
Ddrb.2 = 1
Dim X As Byte
'片选
Dim Writeml As Byte
'写的命令
Dim Writesj As Byte
'写数据 (写人的时间数据)
Dim Readml As Byte
'读芯片的命令
Dim Readsj As Byte
'芯片读出来的数据(显示的数据)
Ce Alias Portb.2
Sj Alias Portb.0
Sck Alias Portb.1
Dim Nian As Byte
Dim Yue As Byte
Dim Ri As Byte
Dim Xiaoshi As Byte
Dim Fen As Byte
Dim Miao As Byte
Const Nianml = &H8D
Const Yueml = &H89
Const Riml = &H87
Const Fenml = &H83
Const Xiaoshiml = &H85
Const Miaoml = &H81
'初始化
Gosub Csh
Cursor Off Noblink
Cls
Do
Readml = Nianml
Gosub Readds
Nian = Readsj
Readsj = 0
Locate 1 , 3
Lcd "20" ; Nian ; "-"
Readml = Yueml
Gosub Readds
Yue = Readsj
Readsj = 0
Readml = Riml
Gosub Readds
Ri = Readsj
Readsj = 0
If Yue < 10 Then
Locate 1 , 8
Lcd "0" ; Yue ; "-"
Else
Locate 1 , 8
Lcd Yue ; "-"
End If
Readml = Riml
Gosub Readds
Ri = Readsj
Readsj = 0
If Ri < 10 Then
Locate 1 , 11
Lcd "0" ; Ri
Else
Locate 1 , 11
Lcd Ri
End If
'========================================
Readml = Xiaoshiml
Gosub Readds
Xiaoshi = Readsj
Readsj = 0
If Xiaoshi <= 10 Then
Locate 2 , 4
Lcd "0" ; Xiaoshi ; "-"
Else
Locate 2 , 4
Lcd Xiaoshi ; "-"
End If
Readml = Fenml
Gosub Readds
Fen = Readsj
Readsj = 0
If Fen < 10 Then
Locate 2 , 7
Lcd "0" ; Fen ; "-"
Else
Locate 2 , 7
Lcd Fen ; "-"
End If
Readml = Miaoml
Gosub Readds
Miao = Readsj
Readsj = 0
If Miao < 10 Then
Locate 2 , 10
Lcd "0" ; Miao
Else
Locate 2 , 10
Lcd Miao
End If
Loop
End
'====================================================================
Writeds:
Ddrb.0 = 1
Ddrb.1 = 1
Ddrb.2 = 1
Dim I As Byte
''''''''''
Sj = 0
nop
Ce = 0
Sck = 0
nop
Ce = 1
Waitus 5
nop
''''''''''''''''''''
For I = 0 To 7
Sck = 0
If Writeml.i = 1 Then
Sj = 1
Else
Sj = 0
End If
Waitus 5
Sck = 1
Next
For I = 0 To 7
Sck = 0
If Writesj.i = 1 Then
Sj = 1
Else
Sj = 0
End If
Waitus 5
Sck = 1
Next
''''''''''''''''''''''''
Ce = 0
nop
nop
Ce = 0
Return
'===============================================================
Readds:
Ddrb.0 = 1
Ddrb.1 = 1
Ddrb.2 = 1
'''''''''''''''''''''''''
''''''''''''''''''''''''''''''''
Sj = 0
nop
Sck = 0
nop
Ce = 0
nop
Ce = 1
Waitus 5
'''''''''''''''''''''''''''''''''''''
'写命令
For I = 0 To 7
'准备上升沿
Sck = 0
nop
nop
If Readml.i = 1 Then
Sj = 1
Waitus 5
Else
Sj = 0
Waitus 5
End If
'上升沿写入
Sck = 1
Next
'读取数据
Ddrb.0 = 0
For I = 0 To 7
Sj = 0
'准备下降沿
Sck = 1
nop
'下降沿读取数据
Sck = 0
If Pinb.0 = 1 Then
Set X.i
Waitus 5
Else
Reset X.i
Waitus 5
End If
Sck = 1
Next
'bcd码转成十进制数据
Readsj = Makedec(x)
'''''''''''''''''''''''''''''''''''''
Sck = 1
nop
'读取完成
Ce = 0
nop
Return
Csh:
'''打开写保护wp位置0
Writeml = &H8E
Writesj = &B00000000
Gosub Writeds
''''''''
Writeml = &H90
Writesj = &B10101010
Gosub Writeds
Waitms 5
'Waitms 5
'充电设置
Writeml = &H8C
Writesj = Makebcd(13)
Gosub Writeds
'年
Writeml = &H8A
Writesj = Makebcd(2)
Gosub Writeds
'星期
'Waitms 10
Writeml = &H88
Writesj = Makebcd(2)
Gosub Writeds
'月
Writeml = &H86
Writesj = Makebcd(19)
Gosub Writeds
'日
'''''''''''''''''''''''''''''''''''''''''''''
Writeml = &H84
Writesj = Makebcd(19)
Gosub Writeds
'时
''''''''''''''''''''''''''''''''
Writeml = &H82
Writesj = Makebcd(59)
Gosub Writeds
' 分
'''''''''''''''''''''''''''''''''''
Writeml = &H81
Writesj = Makebcd(50)
Gosub Writeds
'秒
Return
作者:
ba1731
时间:
2013-2-28 14:15
表四鄙人纯属随机路过。。。顺带帮顶。。。
作者:
oneway
时间:
2013-2-28 18:19
来学习了
欢迎光临 圣龙扬特-AVR电子 (http://avr.cnta.net/)
Powered by Discuz! X2.5