Home > other >  Novice # # for help
Novice # # for help

Time:11-24

51 single chip microcomputer: want to counter each 1, LED1 can flash once, is the state LED1 is bright - out - on - off,
Already P34 and P10 pick up, but why after burn, the light is on, not destroy the
#include
#include

# define uchar unsigned char
# define uint unsigned int

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


sbit DU=P2^6;
Sbit WE=P2 ^ 7;

Void delay (uint z)//the time delay of the custom function
{
uint x,y;
For (x=z; x> 0; X -)
For (y=114; y> 0; y--);

}

Void the display (uint I)
{
Uchar, bai shi ge;
Bai=I/100;
Shi=I % 100/10;
Ge=I % 10;

P0=0 XFF;//remove break code

WE=1;//open a latch high level open
P0=0 xfe;
WE=0;//latch a selected data low level off

DU=1;//open the clip latch
P0=tabel (bai);
DU=0;//latch segment data
Delay (10);

P0=0 XFF;//remove break code

WE=1;//open a latch high level open
P0=0 XFD;
WE=0;//latch a selected data low level off

DU=1;//open the clip latch
P0=tabel (shi);
DU=0;//latch segment data
Delay (10);

P0=0 XFF;//remove break code

WE=1;//open a latch high level open
P0=0 XFB;//1111 1101
WE=0;//latch a selected data low level off
DU=1;//open the clip latch
P0=tabel (ge),//show 2
DU=0;//latch segment data
Delay (10);
}
//timer 0 initialization function
Void timer0Init ()
{
TR0=1;//start the timer 0
TMOD=0x01;//select 16-bit timer timer 0 first mode, TL0 TH0 full use

//TH0 and TL0 is used to set the initial value, if want to 50 ms, regularly, need to convert unit into a 50, 000 us
//use 50 000/1.085=46082, this is to add so much 1, initial value=65535-46082=19453

//TH0=(19453/256);//this is a high eight, divided by 256 is how many 256
//TL0=19453% (256);//this is low eight
//or you can directly use the calculator to define, in converted to binary calculator in 19453 to 100, 1011, 1111, 1101
//octal is 4 BFD
TH0=0 x4b;
XFD TL0=0;


}

Void main ()//interrupt because there is no use, so the TF will not take the initiative to be hardware reset, the need to use the program query reset
{
Uchar msec=0, the SEC=0;//ms seconds
Timer0Init ();//initialization timer 0
While (1)
{
If (TF0==0)//determine whether to 50 ms
{
TF0=0;//software reset overflow flag bit
//overflow marks a reset after TH0 TL0 also are reset, so let's replay initial

TH0=0 x4b;
XFD TL0=0;

Msec++;//msec plus one, said 50 ms in a
If (msec==20)//20 * 50=1000 ms=1 s
{
Msec=0;//will msec, let table can go up
Sec++;//for a second time to

}
}
The display (SEC);
If (SEC==10)
{
The SEC=0;//the second reset
}
}

}
  • Related