单片机源程序如下:
#include <reg52.h>
#include <stdio.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit LEDR=P1^0;//???
sbit LEDY=P1^1;//???
sbit LEDG=P1^2;//???
sbit DU = P2^6;
sbit WE = P2^7;
uchar code tabel[]= {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F,};
void delay (uint i)
{
uint x,y;
for (x=0;x<i;x++)
for (y=0;y<110;y++);
}
void UARTInit()
{
SM0 = 0; SM1 = 1;
TR1 = 1;
TMOD |= 0x20;
TH1 = 0xfd;
TL1 = 0xfd;
}
uchar k;
void display(uchar i)
{
uchar shi, ge;
shi = i % 100 / 10; //236 % 100 / 10 = 3
ge = i % 10;//236 % 10 =6
P0 = 0XFF;
WE = 1;
P0 = 0XFE;
WE = 0;
DU = 1;
P0 = tabel[shi];//
DU = 0;
delay(5);
//???λ?????
P0 = 0XFF;//???????
WE = 1;//??λ???????
P0 = 0XFD; //1111 1101
WE = 0;//????λ?????
DU = 1;//???????????
P0 = tabel[ge];//
DU = 0;//??????????
delay(5);
}
//?????0?????
void timer0Init()
{
TR0 = 1; //????????0
TMOD = 0X01; //???????????1??16λ???????????
TH0 =(65535-46082 ) / 256;
TL0 =(65535-46082 ) % 256; //???50ms
}
void main()
{
UARTInit();
{
TI = 1;
puts("?????");
while(!TI);
TI = 0;
delay(15000);
TI= 1;
puts("?????");
while(!TI);
TI=0;
delay(3000);
TI=1;
puts("?????");
delay(10000);
TI=0;
}
LEDR=0;
{
uchar mSec, Sec;//????????????
Sec=15;
timer0Init();//?????0?????
while(1)
{
if(TF0 == 1)//?ж???????
{
TF0 = 0;//?????????????λ
TH0 =(65535-46082 ) / 256;
TL0 = (65535-46082) % 256; //???50ms
mSec++;//50ms??
if(mSec == 20)
{
mSec = 0;
Sec--;//1?????
}
}
display(Sec); //????????????
}
}
delay(12000);
LEDR=1;
LEDR=0;
delay(250);
LEDR=1;
delay(250);
LEDR=0;
delay(250);
LEDR=1;
delay(250);
LEDR=0;
delay(250);
LEDR=1;
delay(250);
LEDR=0;
delay(250);
LEDR=1;
delay(250);
LEDR=0;
delay(250);
LEDR=1;
delay(250);
LEDR=0;
delay(250);
LEDR=1;
delay(250);
LEDY=0;
delay(3000);
LEDY=1;
LEDG=0;
delay(10000);
for(k=0;k<3;k++);
{
LEDG=0;
delay(250);
LEDG=1;
delay(250);
LEDG=0;
delay(250);
LEDG=1;
delay(250);
LEDG=0;
delay(250);
LEDG=1;
delay(250);
LEDG=0;
delay(250);
LEDG=1;
delay(250);
LEDG=0;
delay(250);
LEDG=1;
delay(250);
LEDG=0;
delay(250);
LEDG=1;
delay(250);
}
}
|