实验要求
1、有两个ADD和SUB两个按键,每按动一次按键,P0口输出的数据自动加1 (减1);
2、程序必须使用中断方式完成;
3、若在开发板上完成,P0口可以根据开发板修改为对应IO口。
电路连接
元件清单
80C52、LED-BIBY、电阻res、可弹起开关button
实验代码
org 00h
sjmp main
org 03h
sjmp plus
org 13h
sjmp sub
org 30h
main:
setb it0
setb it1
mov ie,#10000101b
mov sp,#40h
mov dptr,#tab
lcall xs
ret
loop:
lcall xs
sjmp loop
plus:
inc a
reti
sub:
dec a
reti
xs:
movc a,@a+dptr
mov p0,a
ret
delay:
mov r7,#255
dl2:
mov r6,#255
dl1:
nop
nop
nop
djnz r6,dl1
djnz r7,dl2
ret
tab:db 0h,01h,02h,03h,04h,05h,06h,07h,08h,09h,0ah,0bh,0ch,0dh,0eh,0fh
db 010h,011h,012h,013h,014h,015h,016h,017h,018h,019h,01ah,01bh,01ch,01dh,01eh,01fh
db 020h,021h,022h,023h,024h,025h,026h,027h,028h,029h,02ah,02bh,02ch,02dh,02eh,02fh
db 030h,031h,032h,033h,034h,035h,036h,037h,038h,039h,03ah,03bh,03ch,03dh,03eh,03fh
db 040h,041h,042h,043h,044h,045h,046h,047h,048h,049h,04ah,04bh,04ch,04dh,04eh,04fh
db 050h,051h,052h,053h,054h,055h,056h,057h,058h,059h,05ah,05bh,05ch,05dh,05eh,05fh
db 060h,061h,062h,063h,064h,065h,066h,067h,068h,069h,06ah,06bh,06ch,06dh,06eh,06fh
db 070h,071h,072h,073h,074h,075h,076h,077h,078h,079h,07ah,07bh,07ch,07dh,07eh,07fh
db 080h,081h,082h,083h,084h,085h,086h,087h,088h,089h,08ah,08bh,08ch,08dh,08eh,08fh
db 090h,091h,092h,093h,094h,095h,096h,097h,098h,099h,09ah,09bh,09ch,09dh,09eh,09fh
db 0a0h,0a1h,0a2h,0a3h,0a4h,0a5h,0a6h,0a7h,0a8h,0a9h,0aah,0abh,0ach,0adh,0aeh,0afh
db 0b0h,0b1h,0b2h,0b3h,0b4h,0b5h,0b6h,0b7h,0b8h,0b9h,0bah,0bbh,0bch,0bdh,0beh,0bfh
db 0c0h,0c1h,0c2h,0c3h,0c4h,0c5h,0c6h,0c7h,0c8h,0c9h,0cah,0cbh,0cch,0cdh,0ceh,0cfh
db 0d0h,0d1h,0d2h,0d3h,0d4h,0d5h,0d6h,0d7h,0d8h,0d9h,0dah,0dbh,0dch,0ddh,0deh,0dfh
db 0e0h,0e1h,0e2h,0e3h,0e4h,0e5h,0e6h,0e7h,0e8h,0e9h,0eah,0ebh,0ech,0edh,0eeh,0efh
db 0f0h,0f1h,0f2h,0f3h,0f4h,0f5h,0f6h,0f7h,0f8h,0f9h,0fah,0fbh,0fch,0fdh,0feh,0ffh
end
学习内容
这个小程序用到了单片机的中断,中断是计算机自动响应一个中断请求信号,暂时停止当前程序的执行,转而为外部设备服务的程序,并且在执行完服务程序后自动返回原程序执行的过程(就是打断当前进行的事情,继而进行更为紧急的事情)。
实验总结
其实有关这种端口数据有规律变化的要求,都可以用查表的方法实现,当然,这种查表的方式缺点也显而易见,因此,完成此任务其他的代码思路将在后续发出,欢迎点赞关注。有不同的想法或者改进的建议欢迎留言、私信!
|