51单片机控制数码管循环显示0-9程序

如题所述

采用共阴极LED数码管,51单片机P1口输出数据:ORG 0000H
JMP MAIN
ORG 0100H
MAIN:MOV DPTR,#TAB
MOV R1,#00H
DISP:MOV A,R1
MOVC A,@A+DPTR
MOV P1,A
LCALL DELAY
INC R1
CJNE R1,#0AH,DISP
SJMP $
TAB: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FHDELAY: MOV R4,#2
DELAY100MS:MOV R5,#200
DELAY5MS: MOV R6,#250
LOOP: DJNZ R6,LOOP
DJNZ R5,DELAY5MS
DJNZ R4,DELAY100MS
RET
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-05-15
#include<reg52.h>
#define uint unsigned int
void delay7ms(void) //误差 -0.217013888891us
{
unsigned char a,b;
for(b=208;b>0;b--)
for(a=14;a>0;a--);
}
void delay2ms(void) //误差 -0.217013888889us
{
unsigned char a,b;
for(b=80;b>0;b--)
for(a=10;a>0;a--);
}

void main(void)
{
uint led[10]={0xc0,0xf9,0xa4, 0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uint m,n=0,a=0;
for(m=0;m<=10;m++)
{
while(a<30)
{
if(m==10)
{
m=0;
n++ ;
if(n==10)
n=0;
}
P0=led[m];
P2=0x40;
delay7ms();
P2=0x00;
delay2ms();
P0=led[n];
P2=0x80;
delay7ms();
P2=0x00;
delay2ms();

a++;
}
a=0;
}
}
第2个回答  2018-06-28
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit duanxuan=P2^6;
sbit weixuan=P2^7;
uchar num,time;
uchar code biaoge[]=
{
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f
};
/*void yanshi(uint z);*/
void chushihua();
int main(void)
{
chushihua();
weixuan=1;
P0=0xfe;
weixuan=0;
while(time-10)
{
duanxuan=1;
P0=biaoge[time];
duanxuan=0;
}
}
/*void yanshi(uint z)
{
uint x,y;
for(x=100;x>0;x--)
for(y=z;y>0;y--);
}*/
void chushihua()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void zhongduan() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num++;
if(num==20)
{
num=0;
time++;
if(time==10)
{
time=0;
}
}
}
第3个回答  2018-05-22
我问一下为什么有的书上写的程序,在主程序中会有屏蔽高半字节这一句,就是MOV A R3,ANL,A#0FH,
相似回答