【038】两位数码管计数演示2007-05-05 16:24:00
【评论】
【打印】
【字体:大 中 小】
本文链接:http://blog.pfan.cn/wentao/25592.html
dis_0 equ 30h
dis_1 equ 31h
count equ 32h
org 0000h
ajmp start
org 0030h
start: mov count,#0
mov p2,#0xff
lop: lcall display
inc count
mov a,count
cjne a,#100,lop
ajmp start
display:
mov a,count
mov b,#10
div ab
mov dis_0,b
mov dis_1,a
mov r0,#200
d_lop: mov dptr,#table
mov a,dis_0
movc a,@a+dptr
mov p0,a
mov p2,#0x7f
lcall d_1ms
mov a,dis_1
movc a,@a+dptr
mov p0,a
mov p2,#0xbf
lcall d_1ms
djnz r0,d_lop
ret
d_1ms:
mov r7,#250
temp: nop
nop
djnz r7,temp
ret
table: db 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90
end
#include <reg51.h>
#define uchar unsigned char
void delay_ms(uchar ms);
void display();
uchar code dis_code[10] = {0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90};
uchar data dis_0;
uchar data dis_1;
uchar data count;
void main()
{
count = 0;
P2 = 0xff;
while(count != 100)
{
display();
count++ ;
}
}
void display()
{
uchar data i = 200;
dis_1 = count / 10;
dis_0 = count % 10;
while(i--)
{
P0 = dis_code[dis_0];
P2 = 0x7f;
delay_ms(1);
P0 = dis_code[dis_1];
P2 = 0xbf;
delay_ms(1);
}
}
void delay_ms(uchar ms)
{
uchar i;
while(ms--)
for(i = 0; i < 124; i++);
}
阅读(7147) | 评论(8)
版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!
评论