51单片机控制数码管循环显示0-9程序
4个回答
推荐于2017-05-18
展开全部
采用共阴极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
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
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;
}
}
#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;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#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;
}
}
}
#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;
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
引用jbpfd59aced38的回答:
采用共阴极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
采用共阴极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
展开全部
我问一下为什么有的书上写的程序,在主程序中会有屏蔽高半字节这一句,就是MOV A R3,ANL,A#0FH,
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询