圣龙扬特-AVR电子

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

8255的仿真

[复制链接]

11

主题

0

好友

3245

积分

版主

Rank: 7Rank: 7Rank: 7

UID
45
帖子
31
精华
0
注册时间
2013-2-27
在线时间
29 小时
跳转到指定楼层
楼主
发表于 2013-2-27 23:03:56 |只看该作者 |倒序浏览
'当A1=0,A0=0时,PA口被选择;
'当A1=0,A0=1时,PB口被选择;
'当A1=1,A0=0时,PC口被选择;
'当A1=1.A0=1时,控制寄存器被选择.
'CS:芯片选择信号线,当这个输入引脚为低电平时,即/CS=0时,表示芯片被选中,允许8255与CPU进行通讯;/CS=1时,8255无法与CPU做数据传输.
'RD:读信号线,当这个输入引脚为低跳变沿时,即/RD产生一个低脉冲且/CS=0时,允许8255通过数据总线向CPU发送数据或状态信息,即CPU从8255读取信息或数据。
'WR:写入信号,当这个输入引脚为低跳变沿时,即/WR产生一个低脉冲且/CS=0时,允许CPU将数据或控制字写入8255

$regfile = "m8515.dat"
$crystal = 2000000
Config Timer1 = Timer , Prescale = 64
Timer1 = 64599
Ddre = &B00000010
Porte.1 = 1
Ddra = &B11111111
Porta = &B11111111
Scun Alias Porte.1
Scun = 1
A0 Alias Porta.0
A1 Alias Porta.1
Cs Alias Porta.2
Sj Alias Porta
Config Pind.6 = Output
Config Pind.7 = Output
Wr Alias Portd.6
Wr = 1
Rd Alias Portd.7
Rd = 1
Cs = 0
'数码馆显示变量
Dim H As Byte
Dim M As Byte
Dim D As Byte
H = 13
M = 2
D = 14
Dim Hg As Byte
Dim Hs As Byte
Dim Mg As Byte
Dim Ms As Byte
Dim Dg As Byte
Dim Ds As Byte
'定时器
Dim Dsq As Byte
'按键
Dim Aj As Byte
'装入数组
Dim I As Byte
On Ovf1 Timer1_isr
Enable Timer1
Start Timer1
Enable Interrupts
'''''''''''''''''''''''''''''''
Dim A(10) As Byte
Restore Daima
For I = 1 To 10
Read A(i)
Next
'-----------------------------------------------------------------
Do
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Hg = H Mod 10
Hg = Hg + 1
Hs = H / 10
Hs = Hs + 1
Gosub Wei
Sj = &B00000010
Gosub Xie
'Waitms 10
Gosub Shuju
Sj = A(hg)
Gosub Xie
Waitms 5
Gosub Wei
Sj = &B00000001
Gosub Xie
'Waitms 10
Gosub Shuju
Sj = A(hs)
Gosub Xie
Waitms 5
'''''''''''''''''''''''''''''''''
Mg = M Mod 10
Mg = Mg + 1
Ms = M / 10
Ms = Ms + 1
Gosub Wei
Sj = &B00001000
Gosub Xie
'Waitms 10
Gosub Shuju
Sj = A(ms)
Gosub Xie
Waitms 5
Gosub Wei
Sj = &B00010000
Gosub Xie
'Waitms 10
Gosub Shuju
Sj = A(mg)
Gosub Xie
Waitms 5
''''''''''''''''''''''''''''''
Dg = D Mod 10
Dg = Dg + 1
Ds = D / 10
Ds = Ds + 1
Gosub Wei
Sj = &B01000000
Gosub Xie
'Waitms 10
Gosub Shuju
Sj = A(ds)
Gosub Xie
Waitms 5
Gosub Wei
Sj = &B10000000
Gosub Xie
'Waitms 10
Gosub Shuju
Sj = A(dg)
Gosub Xie
Waitms 5
''''''''''''''''''''''''''''''''''
Gosub Wei
Sj = &B00000100
Gosub Xie
'Waitms 10
Gosub Shuju
Sj = &B10111111
Gosub Xie
Waitms 5
'''''''''''''''''''''''''''''
Gosub Wei
Sj = &B00100000
Gosub Xie
'Waitms 10
Gosub Shuju
Sj = &B10111111
Gosub Xie
Waitms 5
Gosub Du
Loop

End

Shuju:
'
Wr = 1
Sj = &B11111111
A1 = 0
A0 = 0
Cs = 0
Scun = 1
Scun = 0
Waitus 5
Wr = 0
Return
Wei:
Wr = 1
Sj = &B00000000
A1 = 0
A0 = 1
Cs = 0
'Waitus 30
Scun = 1
Scun = 0
Waitus 5
Wr = 0
'Waitus 10
'Scun = 1
'Cs = 0
Return
Xie:
'Cs = 0
Wr = 1
Wr = 0
Waitus 5
'Wr = 1
Return
'==================================================================================
Du:
'读C 口数据的子程序
Sj = &B11111111
A1 = 1
A0 = 0
Cs = 0
Wr = 1
Scun = 1
Scun = 0
'以上选中C口
Waitus 5
'Scun = 1
Ddra = &B00000000
Sj = &B11111111
''''''''''''''''''''''''''''''''''''''''''''''''''''''
Rd = 0
Waitus 20
Aj = Pina
Rd = 1
If Aj = &B11111110 Then
Start Timer1
End If
If Dsq > 6 And Aj = &B11111110 Then
Incr H
Dsq = 0
Stop Timer1
End If
If Aj = &B11111011 Then
Start Timer1
End If
If Dsq > 6 And Aj = &B11111011 Then
Incr M
Stop Timer1
Dsq = 0
End If
If Aj = &B11101111 Then
Start Timer1
End If
If Dsq > 6 And Aj = &B11101111 Then
Incr D
Stop Timer1
Dsq = 0
End If

Ddra = &B11111111
Return
Timer1_isr:
Timer1 = 64599
Incr Dsq
Return
Daima:
Data &B11000000 , &B11111001 , &B10100100 , &B10110000 , &B10011001
Data &B10010010 , &B10000010 , &B11111000 , &B10000000 , &B10011000

本帖子中包含更多资源

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

回复

使用道具 举报

0

主题

1

好友

3101

积分

超级版主

Rank: 8Rank: 8

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

使用道具 举报

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

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

GMT+8, 2024-12-22 23:29 , Processed in 0.205181 second(s), 18 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部