1. As shown in the figure below, two common cathode nixie tubes are connected to ports P0 and P2 of AT89S51 single chip microcomputer respectively. Port P0 drives ten bits of second time, while port P2 drives one bit of second time.

2. Circuit schematic diagram

Design of 00-59 second timer based on AT89S51 single chip microcomputer

Figure 4.11.1

3. Hardware connection on the system board

(1) connect p0.0/ad0-p0.7/ad7 port in “single chip microcomputer system” area to any A-H port in “four channel static digital display module” area with 8-core flat cable; requirements: p0.0/ad0 corresponds to a, p0.1/ad1 corresponds to B,…, p0.7/ad7 corresponds to H.

(2) connect p2.0/a8-p2.7/a15 port in “single chip microcomputer system” area to any A-H port in “four channel static digital display module” area with 8-core flat cable; requirements: p2.0/a8 corresponds to a, p2.1/a9 corresponds to B,…, and p2.7/a15 corresponds to H.

4. Program design content

(1) in the design process, we use a storage unit as the second counting unit. When a second arrives, we will add 1 to the second counting unit. When the second count reaches 60, it will automatically return to 0 and count from the new second.

(2) for the data in the second counting unit, its tens and numbers shall be separated, and the method still adopts the division of 10 and the remainder of 10.

(3) the digital display is still completed by looking up the table.

(4) the generation of one second time is completed here by using the method of accurate software delay. After accurate calculation, the time of one second is 1.002 seconds.

DELY1S: MOV R5,#100

D2: MOV R6,#20

D1: MOV R7,#248

DJNZ R7,$

DJNZ R6,D1

Design of 00-59 second timer based on AT89S51 single chip microcomputer

DJNZ R5,D2

RET

5. Program block diagram

Figure 4.11.2

6. Assemble source program

Second EQU 30H

ORG 0

START: MOV Second,#00H

NEXT: MOV A,Second

MOV B,#10

DIV AB

MOV DPTR,#TABLE

MOVC A,@A+DPTR

MOV P0,A

MOV A,B

MOVC A,@A+DPTR

MOV P2,A

LCALL DELY1S

INC Second

MOV A,Second

CJNE A,#60,NEXT

LJMP START

DELY1S: MOV R5,#100

D2: MOV R6,#20

D1: MOV R7,#248

DJNZ R7,$

DJNZ R6,D1

DJNZ R5,D2

RET

TABLE: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH

END

7. C language source program

#include

unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,

0x6d,0x7d,0x07,0x7f,0x6f};

unsigned char Second;

void delay1s(void)

{

unsigned char i,j,k;

for(k=100;k》0;k–)

for(i=20;i》0;i–)

for(j=248;j》0;j–);

}

void main(void)

{

Second=0;

P0=table[Second/10];

P2=table[Second%10];

while(1)

{

delay1s();

Second++;

if(Second==60)

{

Second=0;

}

P0=table[Second/10];

P2=table[Second%10];

}

}

Leave a Reply

Your email address will not be published. Required fields are marked *