圣龙扬特-AVR电子

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1298|回复: 2
打印 上一主题 下一主题

bascom 读取1302的仿真

[复制链接]

11

主题

0

好友

3245

积分

版主

Rank: 7Rank: 7Rank: 7

UID
45
帖子
31
精华
0
注册时间
2013-2-27
在线时间
29 小时
跳转到指定楼层
楼主
发表于 2013-2-27 22:54:50 |只看该作者 |倒序浏览
$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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

回复

使用道具 举报

0

主题

1

好友

3101

积分

超级版主

Rank: 8Rank: 8

UID
31
帖子
36
精华
0
注册时间
2013-2-27
在线时间
5 小时
沙发
发表于 2013-2-28 14:15:52 |只看该作者
表四鄙人纯属随机路过。。。顺带帮顶。。。
回复

使用道具 举报

1

主题

0

好友

652

积分

高级会员

Rank: 4

UID
21
帖子
45
精华
0
注册时间
2013-2-26
在线时间
11 小时
板凳
发表于 2013-2-28 18:19:59 |只看该作者
来学习了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

Archiver|手机版|圣龙扬特-AVR电子 ( 鲁ICP备05022832号 )

GMT+8, 2024-12-22 17:28 , Processed in 0.206505 second(s), 19 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部