求单片机数码管显示学号如(07091140)的程序及protues的图~ 共阴极。。

2025-01-01 05:34:05
推荐回答(2个)
回答1:

#include

#define uchar unsigned char

#define uint unsigned int

sbit DATA=P3^0;

sbit CLK=P3^1;

sbit EN=P1^3;

uchar code seg_tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};

void delay10ms(uint x);

void send_hc164(uchar dat);

void display(uchar a1,uchar a2,uchar a3,uchar a4,uchar a5,uchar a6,uchar a7,uchar a8);

void main()

{

EN=0;

while(1)

{

display(0,1,2,3,4,5,6,7);

}

}

void delay10ms(uint x)

{

uint i,j;

for(i=x;i>0;i--)

for(j=149;j>0;j--);

}

void send_hc164(uchar dat)

{

uchar i;

for(i=0;i<8;i++)

{

CLK=0;

DATA=dat&0x80;

CLK=1;

dat<<=1;

}

}

void display(uchar a1,uchar a2,uchar a3,uchar a4,uchar a5,uchar a6,uchar a7,uchar a8)

{

EN=0;

send_hc164(seg_tab[a1]);

P1=0x00;

EN=1;

delay10ms(1);

EN=0;

send_hc164(seg_tab[a2]);

P1=0x01;

EN=1;

delay10ms(1);

EN=0;

send_hc164(seg_tab[a3]);

P1=0x02;

EN=1;

delay10ms(1);

EN=0;

send_hc164(seg_tab[a4]);

P1=0x03;

EN=1;

delay10ms(1);

EN=0;

send_hc164(seg_tab[a5]);

P1=0x04;

EN=1;

delay10ms(1);

EN=0;

send_hc164(seg_tab[a6]);

P1=0x05;

EN=1;

delay10ms(1);

EN=0;

send_hc164(seg_tab[a7]);

P1=0x06;

EN=1;

delay10ms(1);

EN=0;

send_hc164(seg_tab[a8]);

P1=0x07;

EN=1;

delay10ms(1);

EN=0;

}

回答2:

DISL EQU 30H
DISH EQU 31H
DAT EQU 32H
T0L EQU 3AH
T0H EQU 3BH
SCANLED EQU 3CH
ORG 0000H
LJMP MAIN
ORG 000BH
LJMP T0ISR
ORG 0030H
MAIN:
MOV SP,#5FH
MOV TMOD,#01H
MOV T0L,#048H
MOV T0H,#0F4H
MOV TH0,#0F4H
MOV TL0,#048H
MOV P2,#00H
MOV SCANLED,#0
MOV 32H,#0
MOV 33H,#7
MOV 34H,#0
MOV 35H,#9
MOV 36H,#1
MOV 37H,#1
MOV 38H,#4
MOV 39H,#0
MOV DISL,#0
MOV DISH,#0
SETB EA
SETB ET0
SETB TR0
SETB 00H
SJMP $
;--------------------T0ISR:
PUSH ACC
CLR TR0
MOV TH0,T0H
MOV TL0,T0L
SETB TR0
MOV DPTR,#LEDTAB1
T000:
MOV R0,#DAT
MOV A,SCANLED
ADD A,R0
MOV R0,A
MOV A,SCANLED
JNZ T001
MOV P2,#80H
SJMP T0DIS
T001:
DEC A
JNZ T002
MOV P2,#01H
SJMP T0DIS
T002:
DEC A
JNZ T003
MOV P2,#02H
SJMP T0DIS
T003:
DEC A
JNZ T004
MOV P2,#04H
SJMP T0DIS
T004:
DEC A
JNZ T005
MOV P2,#08H
SJMP T0DIS
T005:
DEC A
JNZ T006
MOV P2,#10H
SJMP T0DIS
T006:
DEC A
JNZ T007
MOV P2,#20H
SJMP T0DIS
T007:
DEC A
JNZ T0DIS
MOV P2,#40H
T0DIS:
MOV A,@R0
MOVC A,@A+DPTR
CPL A
MOV P0,A
INC SCANLED
MOV A,SCANLED
ANL A,#07H
MOV SCANLED,A
POP ACC
RETI
;--------------------LEDTAB1:
DB 0C0H ;"0" 00H
DB 0F9H ;"1" 01H
DB 0A4H ;"2" 02H
DB 0B0H ;"3" 03H
DB 99H ;"4" 04H
DB 92H ;"5" 05H
DB 82H ;"6" 06H
DB 0F8H ;"7" 07H
DB 80H ;"8" 08H
DB 90H ;"9" 09H
DB 88H ;"A" 0AH
DB 83H ;"B" 0BH
DB 0C6H ;"C" 0CH
DB 0A1H ;"D" 0DH
DB 86H ;"E" 0EH
DB 8EH ;"F" 0FH
DB 0FFH ;" " 10H
;--------------------
END