查看: 1925|回复: 15
|
AT89C51 LCD 倒数时间(程序有错误,请纠正)
[复制链接]
|
|
本帖最后由 raysim88 于 3-8-2010 07:47 PM 编辑
各位大大,谁会用AT89C51 interface LCD来写倒数时间(assembly language).
这是我从其他网站找的,可是有错误,请各位来纠正下!多谢!
比如可以从60秒倒数到0秒.
;p1 LCD data pins
;p2.0 connected to RS pin
;p2.1 connected to R/W pin
;p2.2 connected to E pin
org 0h
ljmp main
org 30h
main:
mov r0,#0 ;initializing seconds
mov r1,#0 ;initializing minutes
mov r2,#0 ;initializing hours
;command codes for LCD
mov a,#38 ;2 lines and 5*7 matrix
acall command
mov a,#0eh ;display on cursor blinking
acall command
mov a,#01h ;clear display screen
acall command
mov a,#06 ;move cursor to right
acall command
mov a,#80 ;cursor start on first line
acall command
abc: mov a,r2 ;Display hours
acall datadisplay
mov a,#06 ;moving cursor
acall command
mov a,#':' ;display semi colon
acall datadisplay
mov a,#06 ;moving cursor
acall command
mov a,r1 ;Display minutes
acall datadisplay
mov a,#06 ;moving cursor
acall command
mov a,#':' ;display semi colon
acall datadisplay
mov a,#06 ;moving cursor
acall command
mov a,r0 ;Display seconds
acall datadisplay
mov a,#80 ;cursor start on first line
acall command
jb p0.0,abc ;check for stopping the watch
jb p0.1,main ;p0.1 for resetting clock
|
|
|
|
|
|
|
|

楼主 |
发表于 3-8-2010 05:43 PM
|
显示全部楼层
time: ;for timer
acall delay ;i second delay
inc r0 ;increamenting seconds after 1 second
cjne r0,#60,abc ;check if seconds are 60 or not
mov r0,#0 ;if 60 seconds past than increament minute and initialize seconds to zero
inc r1
cjne r1,#60,abc ;check if 60 minutes have been past or not
mov r1,#0 ;if 60 seconds past than increament hours and initialize minutes to zero
inc r2
cjne r2,#24,abc ;check if hours are 24 (you can make it 12 hourse mode)
mov r2,#0 ;if 24 than initializa it ot 0
sjmp abc
delay: ;delay in timer for 1 sec
mov r3,#46 ;we have to make a delay of 921600 instructions
lop: mov r4,#50 ;djnz take 2 instruction cycles
loop: mov r5,#50
loop1: djnz r5,loop1
djnz r4,loop
djnz r3,lop
ret
command: ;to use in LCD
acall ready
mov p1,a
clr p2.0 ;make RS 0 to execute command code on LCD
clr p2.1 ;make R/W 0 for writing
setb p2.2
clr p2.2
ret
datadisplay: ;to display data on LCD
acall ready
mov p1,a
setb p2.0 ;make RS 1 to execute data display on LCD
clr p2.1 ;make R/W 0 for writing
setb p2.2 ;high-to-low pulse to E pin of LCD
clr p2.2
ret
ready: ;for LCD that if it is ready
setb p1.7
clr p2.0
setb p2.1
back:
clr p2.2 ;low=to-high pulse to LCD
setb p2.2
jb p1.7,back
ret
end |
|
|
|
|
|
|
|
发表于 27-8-2010 01:35 PM
|
显示全部楼层
我也是有做这个。。。
你们组的做到怎样了?
你有去参考8051cook book的code吗?
那里有一个for countdown的。。。
网上找到的多数不能用的 因为不是port不一样就是用的chip也不一样 要改得来都很麻烦 |
|
|
|
|
|
|
|

楼主 |
发表于 27-8-2010 01:45 PM
|
显示全部楼层
回复 3# CristianoRooney
那个是废物来,全部要自己想。我的到数时间很有问题,你的怎样了?我的hardware还没solder! |
|
|
|
|
|
|
|
发表于 27-8-2010 01:59 PM
|
显示全部楼层
回复 CristianoRooney
那个是废物来,全部要自己想。我的到数时间很有问题,你的怎样了?我的ha ...
raysim88 发表于 27-8-2010 01:45 PM  我们的hardware做好了。。。剩下programming。。。还没头绪 时间又要到了。。。
课本的那个code不能用的吗?我还在想要怎样modify去给lcd用
下个星期要交了 能做多少就做多少了
你倒数时间有什么问题?lcd有display吗? |
|
|
|
|
|
|
|

楼主 |
发表于 27-8-2010 02:40 PM
|
显示全部楼层
回复 5# CristianoRooney
你先要知道你是用8bits data line 还是4bits data line, 两个的写法不一样,我用的是4bits的。你呢?你是马六甲人吗? |
|
|
|
|
|
|
|
发表于 27-8-2010 05:36 PM
|
显示全部楼层
我原本打算用8bit因为我想参考课本的code...可是没有simulator ...我也不会8052simulator
你是用那个edsim51的simulator吗?那个lcd display 是4bit的吧
我不是马六甲人 |
|
|
|
|
|
|
|

楼主 |
发表于 27-8-2010 05:40 PM
|
显示全部楼层
回复 7# CristianoRooney
是的我用edsim51来写program,你是cyber还是马六甲的?由于下个星期五有急事所以要会槟城,不知道能不能赶完! |
|
|
|
|
|
|
|
发表于 27-8-2010 05:49 PM
|
显示全部楼层
可惜我的组已经做好hardware了 所以port不能跟着edsim51了
所以我们的一定要用8bit。。。
可是如果课本的code真的没用的话 我也不会了 自己想我是想不出啦
不过刚才我去问老师了 他讲就算到时system不能function但至少要明白整个project的东西 因为他讲他也没有指望我们的东西能完全function。。 |
|
|
|
|
|
|
|

楼主 |
发表于 27-8-2010 07:13 PM
|
显示全部楼层
回复 9# CristianoRooney
幸好是这样 。他有说会扣分还是什么吗?假如无法完成全部的part? |
|
|
|
|
|
|
|
发表于 28-8-2010 02:30 AM
|
显示全部楼层
回复 CristianoRooney
幸好是这样。他有说会扣分还是什么吗?假如无法完成全部的part?
raysim88 发表于 27-8-2010 07:13 PM  他没有讲会不会扣分 做不出最重要会解释咯我觉得啦。。。给分这种是很主观也很FLEXIBLE的东西 做不出来至少也要会解释你写的PROGRAM和DESIGN的HARDWARE
不要那种叫别人做出来会FUNCTION但是却不会解释
重点是PRESENTATION那天他问的东西你会答应该就没问题
如果SYSTEM会FUNCTION又会解释那分数当然是最好啦 |
|
|
|
|
|
|
|
发表于 28-8-2010 05:14 PM
|
显示全部楼层
回复 2# raysim88
你程式有两点大问题:
1. 你那个程式原本功能是做进数,下面是秒数的倒数的写法,其它的以此类推。
- dec r0 ;increamenting seconds after 1 second
- cjne r0,#00,abc ;check if seconds are 60 or not
- mov r0,#59 ;if 60 seconds past than increament minute and initialize
复制代码
2. LCD对R0,R1,R2显示,应该转换成ASCII code 后才发给P1。请参考alphanumeric LCD使用手册。
3.如何让LCD显示59,请把5的ASCII code 和 9的ASCII code,分别输出。
4.至于如何把R0的#59值换成ASCII code,只需用到2暂存器,DIV,shift register(RL,RR)指令。
楼主请自个研究吧!
把答案公布的话,就失去自我学习的意义了。
祝你好运! |
|
|
|
|
|
|
|
发表于 7-9-2010 01:44 PM
|
显示全部楼层
各位大大,谁会用AT89C51 interface LCD来写倒数时间(assembly language).
这是我从其他网站找的,可是有 ...
raysim88 发表于 3-8-2010 05:43 PM 
可以把电路图方上来看吗?
我帮你的code compile 了,没有error啊?
http://rapidshare.com/files/417560209/51LCD.HEX |
|
|
|
|
|
|
|

楼主 |
发表于 7-9-2010 02:57 PM
|
显示全部楼层
回复 13# qweeer
其实里面暗藏了很多小错误,就比如mov a, #38, 其实是hexa来,不是decimal, compile没问题,不代表没有错,可是还是谢谢你,因为我研究到了 |
|
|
|
|
|
|
|
发表于 7-9-2010 04:16 PM
|
显示全部楼层
本帖最后由 qweeer 于 7-9-2010 04:32 PM 编辑
回复 qweeer
其实里面暗藏了很多小错误,就比如mov a, #38, 其实是hexa来,不是decimal, compil ...
raysim88 发表于 7-9-2010 02:57 PM 
恭喜恭喜
但是,据我所知,
mov a, #38 是 decimal 38 mov 进 a 哦!
如果要mov hexa 的 因该是 mov a, #038h 。
还有你的crystal是多少?这个如何算到 921600 instructions?如何算到 1 sec?
delay: ;delay in timer for 1 sec
mov r3,#46 ;we have to make a delay of 921600 instructions
lop: mov r4,#50 ;djnz take 2 instruction cycles
loop: mov r5,#50
loop1: djnz r5,loop1
djnz r4,loop
djnz r3,lop
ret
可以分享你的Program 有哪些小错误吗?还是可以分享你的经验吗? |
|
|
|
|
|
|
|

楼主 |
发表于 7-9-2010 05:28 PM
|
显示全部楼层
回复 15# qweeer
对,mov a, #38 是decimal来,我要的是38h, 因为LCD的datasheet里 38h 是define entry mode来,假如mov 30 decimal肯定我能work, delay 1s 我是用timer 1来写, 把timer 1 写成2.5ms 让后乘4有乘100(一直loop它),一秒后才增加一个register variable。 |
|
|
|
|
|
|
| |
本周最热论坛帖子
|