【041】四位数码管计数演示2007-05-05 16:28:00
【评论】
【打印】
【字体:大 中 小】
本文链接:http://blog.pfan.cn/wentao/25595.html
org 0000h
ajmp start
org 0030h
start: mov 30h,#0
mov 31h,#0
mov 32h,#0
mov 33h,#0
mov p2,#0xff
mov dptr,#table
lop: lcall display
inc 30h
mov a,30h
cjne a,#10,over
mov 30h,#0
inc 31h
mov a,31h
cjne a,#10,over
mov 31h,#0
inc 32h
mov a,32h
cjne a,#10,over
mov 32h,#0
inc 33h
mov a,33h
cjne a,#10,over
mov 33h,#0
over: ajmp lop
display:
mov r0,#50
d_lop:
mov a,30h
movc a,@a+dptr
mov p0,a
mov p2,#0x7f
lcall d_1ms
mov a,31h
movc a,@a+dptr
mov p0,a
mov p2,#0xbf
lcall d_1ms
mov a,32h
movc a,@a+dptr
mov p0,a
mov p2,#0xdf
lcall d_1ms
mov a,33h
movc a,@a+dptr
mov p0,a
mov p2,#0xef
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 = 0;
uchar data dis_1 = 0;
uchar data dis_2 = 0;
uchar data dis_3 = 0;
void main()
{
P2 = 0xff;
while(1)
{
display();
dis_0++;
if(dis_0 != 10)
continue;
dis_0 = 0;
dis_1++;
if(dis_1 != 10)
continue;
dis_1 = 0;
dis_2++;
if(dis_2 != 10)
continue;
dis_2 = 0;
dis_3++;
if(dis_3 != 10)
continue;
dis_3 = 0;
}
}
void display()
{
uchar data i = 50;
while(i--)
{
P0 = dis_code[dis_0];
P2 = 0x7f;
delay_ms(1);
P0 = dis_code[dis_1];
P2 = 0xbf;
delay_ms(1);
P0 = dis_code[dis_2];
P2 = 0xdf;
delay_ms(1);
P0 = dis_code[dis_3];
P2 = 0xef;
delay_ms(1);
}
}
void delay_ms(uchar ms)
{
uchar i;
while(ms--)
for(i = 0; i < 124; i++);
}
阅读(7633) | 评论(3)
版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!
评论