程序清单(汇编):
;2011 04 05 D:\DPJ\数码管段显\数码管段显2.asm
S0 BIT P3.7
ORG 00H
AJMP MAIN
ORG 0BH
AJMP T0INT
ORG 30H
MAIN:
MOV TMOD,#01H
MOV TH0,#3CH
MOV TL0,#0B0H
SETB EA
SETB ET0
SETB TR0
MOV R0,#10
MOV DPTR,#TAB
MAIN1:
ACALL DISP
JB S0,$-2
ACALL DISP
JNB S0,$-2
INC R1
INC R1
CJNE R1,#16,MAIN1
MOV R1,#0
AJMP MAIN1
DISP:
MOV A,R1
MOVC A,@A+DPTR
MOV P2,A
CLR P3.0
ACALL D1MS
SETB P3.0
INC R1
JNB F0,RT
CLR F0
MOV A,R1
MOVC A,@A+DPTR
MOV P2,A
CLR P3.1
ACALL D1MS
SETB P3.1
RT:
MOV A,R1
DEC A
MOV R1,A
RET
T0INT:
MOV TH0,#3CH
MOV TL0,#0B0H
DJNZ R0,RTI
MOV R0,#10
SETB F0
RTI:
RETI
D1MS:
MOV R7,#25
MOV R6,#20
DJNZ R6,$
DJNZ R7,$-4
RET
TAB:
DB 077H;A
DB 001H;A
DB 07CH;b
DB 002H;b
DB 039H;C
DB 004H;C
DB 05EH;d
DB 008H;d
DB 079H;E
DB 010H;E
DB 071H;F
DB 020H;F
DB 06FH;g
DB 040H;g
DB 076H;H
DB 080H;H
END
程序清单(51c):
//2011 04 05 D:\DPJ_C\数码管段显\数码管段显c2.c
- #include <reg51.h>
- #define uchar unsigned char
- uchar code tab[ ]={0x77,0x01,0x7c,0x02,0x39,0x04,0x5e,0x08,
- 0x79,0x10,0x71,0x20,0x6f,0x40,0x76,0x80};
- uchar i,j,a,b;
- sbit P3_0=P3^0;
- sbit P3_1=P3^1;
- sbit S0=P3^7;
- void delay_ms(unsigned int ms)
- {
- while(ms--)
- for(j=123;j>0;j--);
- }
- void disp( )
- {
- P2=tab[i];
- P3_0=0;
- delay_ms(2);
- P3_0=1;
- if(b==1)
- {
- b=0;
- P2=tab[i+1];
- P3_1=0;
- delay_ms(2);
- P3_1=1;
- }
- }
- void t0init( )
- {
- TMOD=0x01;
- TH0=0x3c;
- TL0=0xb0;
- EA=1;
- ET0=1;
- TR0=1;
- }
- void main( )
- {
- t0init();
- while(1)
- {
- disp( );
- while(S0==0)
- {
- disp( );
- if(S0==1)
- i=i+2;
- if(i==16)
- i=0;
- }
- }
- }
- void t0int() interrupt 1
- {
- TH0=0x3c;
- TL0=0xb0;
- a++;
- if(a==10)
- {
- b=1;
- a=0;
- }
- }
复制代码