/*
timer 0 controls the flashing time of the LED; counter 1 to control the display of the digital tube
*/
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit DULA = P2^6;
sbit WELA = P2^7;
sbit LED1 = P1^0;
void display(uint i);
void delay(uint z);
uchar code arry[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void delay(uint z)
{
uint a,b;
for(a = z;a > 0;a–){
for(b = 114;b > 0;b–);
}
}
void display(uint i)
{
UINT One, TWO; // Here is two digits. If you set a hundred digits with a three -digit digital tube, then a hundred people are I/100; ten are i%100/10;
one = i / 10;
two = i % 10;
P0 = 0xff;
wela = 1; // Open the seat selection
P0 = 0xfe;
WELA = 0;
dula = 1; // Open the selection
P0 = arry[one];
DULA = 0;
delay(5);
P0 = 0xff;
wela = 1; // Open the seat selection
P0 = 0xfd;
WELA = 0;
dula = 1; // Open Selection
P0 = arry[two];
DULA = 0;
delay(5);
}
void main(void)
{
uchar a;
tr0 = 1; // Open the timer 0
tr1 = 1; // Open the timer 1
tmod = 0x61; // Set T1 to counter, the working method is 2; T0 is the timer, and the working method is 1
TH0 = 0x4b;
TL0 = 0xfc;
Th1 = 0; // This is an 8 -bit automatic reinstalled register
tl1 = 0; // When TL1 is full, re -load the value of TH1
while(1){
if(TF0 == 1){
Th0 = 0x4b; // Re -load the initial value
TL0 = 0xfc;
TF0 = 0;
a++;
}
if(a == 20){
LED1 = ~ LED1; // Light the LED initially, each time it is reversed, it is a transformation state
a = 0;
}
display (TL1); // Use DuPont to connect P10 port with external pins P35 (T1) port;
// The counter is based on each pulse of the outside, and the counter will be +1
// So when the status of LED1 changes once, different level signals will be generated.
// from the DuPont line to let the T1 understand, the counter will be +1
}
}