通过8051单片机,在p1口接一位数码管,让数码管从0显示到9,循环显示。试画出AT89S51与外设的连接图
答案:2 悬赏:0 手机版
解决时间 2021-02-09 02:41
- 提问者网友:容嬷嬷拿针来
- 2021-02-08 09:17
通过8051单片机,在p1口接一位数码管,让数码管从0显示到9,循环显示。试画出AT89S51与外设的连接图
最佳答案
- 五星知识达人网友:千杯敬自由
- 2021-02-08 10:41
ORG 0000H
LJMP START
ORG 000BH
LJMP INTERRUPT_T0
ORG 0030H
START:
MOV SP,#60H
MOV TMOD,#01H
MOV TH0,#4CH
MOV TL0,#00H
MOV R7,#00H
MOV R6,#00H
SETB ET0
SETB EA
SETB TR0
MOV DPTR,#TAB
MAIN:
MOV A,R6
MOVC A,@A+DPTR
MOV P1,A
LJMP MAIN
INTERRUPT_T0:
MOV TH0,#4CH
MOV TL0,#00H
INC R7
CJNE R7,#20,LOOP1
MOV R7,#00H
INC R6
CJNE R6,#10,LOOP1
MOV R6,#00H
LOOP1:
RETI
TAB:
DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H
END
LJMP START
ORG 000BH
LJMP INTERRUPT_T0
ORG 0030H
START:
MOV SP,#60H
MOV TMOD,#01H
MOV TH0,#4CH
MOV TL0,#00H
MOV R7,#00H
MOV R6,#00H
SETB ET0
SETB EA
SETB TR0
MOV DPTR,#TAB
MAIN:
MOV A,R6
MOVC A,@A+DPTR
MOV P1,A
LJMP MAIN
INTERRUPT_T0:
MOV TH0,#4CH
MOV TL0,#00H
INC R7
CJNE R7,#20,LOOP1
MOV R7,#00H
INC R6
CJNE R6,#10,LOOP1
MOV R6,#00H
LOOP1:
RETI
TAB:
DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H
END
全部回答
- 1楼网友:走死在岁月里
- 2021-02-08 11:53
这是一个十进制计数器,但是只循环显示0~9,显示位数可以设定,按键按下,开始循环。
#include
#define uchar unsigned char
#define uint unsigned int
#define dispseg P0
#define dispbit P2
#define disnum 3
uchar dispp[disnum],TimeCount,count;
sbit sb=P1^0;
sbit ssb=P1^0;
uint ttt,i,ii;
uchar duan[ ]={0xc0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
uchar xuan[ ]={0x01,0x02,0x04,0x08,0x10,0x20};
void delay(uint z)
{ uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--) ;
}
void outside_init(void)
{ TMOD=0x01;
TH0=(65536-50000)/256; //定时
TL0=(65536-50000)%256;
IE=0x00;
ET0=1;
EA=0;
TR0=1;
}
void outside_int(void) interrupt 1
{ ET0=0;
TH0=(65536-50000)/256; //定时
TL0=(65536-50000)%256;
count++;
if(count>15)
{count=0;
ttt++;
if(ttt>10)
ttt=0;
}
ET0=1;
}
void displayy()
{ uint ii;
dispp[0]=duan[ttt%10];
dispp[1]=duan[ttt/10];
for(ii=0;ii<2;ii++)
{ P0=0xff;
P2=xuan[ii];
P0=dispp[ii] ;
}
P0=0xff;
P2=0xff;
}
void main()
{ outside_init();
delay(1);
while(1)
{ if(sb==0)
{delay(1);
if(sb==0)
{ EA=~EA ;
while(sb==0)
{ displayy();
ET0=0;}
ttt=0;
}
}
ET0=1;
displayy();
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯