#include<reg51.h>
#include<intrins.h>
#include<lcd.h>
void Delayms() ;
sbit LED1=P2^7;
unsigned int send[4]={0,1,2,3};
unsigned char code digit[ ]={"0123456789"};
unsigned char lcd0,lcd1,lcd2,lcd3;
int zhuan,count=0,msec;
int ge,shi,bai,qian;
void WriteAddress(unsigned char x)
{
LcdWriteCom(x|0x80);
}
void Delayms(unsigned int c)
{
unsigned char a, b;
for (;c>0;c--)
{
for (b=10;b>0;b--)
{
for (a=10;a>0;a--);
}
}
}
void counter(void) interrupt 0
{
EX1=0; //1Øía2¿ÖD¶Ï1
count++;
EX1=1;
Delayms(10); //¿aía2¿ÖD¶Ï1
return;
}
void Timer_0(void) interrupt 1
{
TH0=0x4B; //50ms¶¨ê±
TL0=0xFF;
msec++;
if(msec==20) //50*20=1S
{ EX0=0; //1Øía2¿ÖD¶Ï0
msec=0;
zhuan=count-1;
count=0;
TH0=0x4B; //ÕaàïÖØD¼ÆêyÆ÷¸33õÖμ50ms¶¨ê±
TL0=0xFF;
EX0=1; //¿aía2¿ÖD¶Ï0
}
}
void display_sym(void)
{
WriteAddress(0x00);
LcdWriteData('v');
LcdWriteData('=');
}
void display_unit(void)
{
WriteAddress(0x06);
LcdWriteData('r');
LcdWriteData('/');
LcdWriteData('m');
LcdWriteData('i');
LcdWriteData('n');
}
void uart_init(void)
{
SCON=0X50;
TMOD=0X20;
PCON=0X80;//2¨ìØÂê¼ó±¶
TH1=0XFD;
TL1=0XFD;
TR1=1;
}
void jisuan()
{ int i=0;
zhuan=zhuan*60;
send[0]=zhuan/1000;
send[1]=(zhuan%1000)/100;
send[2]=(zhuan%100)/10;
send[3]=zhuan%10;
for(i=0;i<4;i++)
{
SBUF='0'+send;
while(!TI);
TI=0;
}
lcd0=send[0];
lcd1=send[1];
lcd2=send[2];
lcd3=send[3];
WriteAddress(0x02);
LcdWriteData(digit[lcd0]);
LcdWriteData(digit[lcd1]);
LcdWriteData(digit[lcd2]);
LcdWriteData(digit[lcd3]);
zhuan=0;
Delayms(10) ;
}
void int_all()
{
LED1=1;
zhuan=0;
count=0; //3õê¼»ˉzμÄÖμ
TMOD=0x01; //Äú2¿ÖD¶Ï¶¨ê±Æ÷Ñ¡Ôñ
TH0=0x47; //50ms¶¨ê±
TL0=0xC9;
EA=1; //¿aÖD¶Ï×ü¿a1Ø
ET0=1; //¿aÄú2¿ÖD¶Ï0
TR0=1; //¼Æê±Æ÷¿aê¼1¤×÷
IT0=1; //ía2¿ÖD¶Ï0ÎaϽμÑØê½′¥·¢
EX0=1; //¿aía2¿ÖD¶Ï0
}
void main ()
{
LcdInit();
int_all();
uart_init();
display_sym();
display_unit();
while(1)
{
if(zhuan>0)
{
LED1=0;
jisuan();
}
}
}
|