下面是程序部分
#include "traffic.h"
#include "lcdA.h"
#include "lcdB.h"
bit FLAG=0;
void menu()
{
int i;
LCD1602_Init_A();
LCD1602_Init_B();
while(1)
{
char TIME=20;
if(TIME>15)
{
N_S_GREEN=ON;N_S_RED=OFF;N_S_YELLOW=OFF;W_E_GREEN=OFF;W_E_RED=ON;W_E_YELLOW=OFF;
LCD_Str_A("RUN! TIME: S",1,1);
LCD_Str_B("STOP! TIME: S",1,1);
LCD_Str_A("COUNT:",2,1);
LCD_Str_B("COUNT:",2,1);
}
else if(TIME>10)
{
N_S_YELLOW=ON;N_S_RED=OFF;N_S_GREEN=OFF;W_E_GREEN=OFF;W_E_RED=ON;W_E_YELLOW=OFF;
LCD_Str_A("STOP! TIME: S",1,1);
LCD_Str_B("STOP! TIME: S",1,1);
LCD_Str_A("COUNT:",2,1);
LCD_Str_B("COUNT:",2,1);
}
else if(TIME>5)
{
N_S_GREEN=OFF;N_S_RED=ON;N_S_YELLOW=OFF;W_E_GREEN=ON;W_E_RED=OFF;W_E_YELLOW=OFF;
LCD_Str_A("STOP! TIME: S",1,1);
LCD_Str_B("RUN! TIME: S",1,1);
LCD_Str_A("COUNT:",2,1);
LCD_Str_B("COUNT:",2,1);
}
else if(TIME>0)
{
N_S_YELLOW=OFF;N_S_RED=ON;N_S_GREEN=OFF;W_E_GREEN=OFF;W_E_RED=OFF;W_E_YELLOW=ON;
LCD_Str_A("STOP! TIME: S",1,1);
LCD_Str_B("STOP! TIME: S",1,1);
LCD_Str_A("COUNT:",2,1);
LCD_Str_B("COUNT:",2,1);
}
else if(TIME<=0)
{
TIME=20;
}
if(TIME>10)
{
TIMEE=TIME-10;
}
else
{
TIMEE=TIME;
}
for(i=100;i>0;i--)
{
LCD_Write_3_Float_A(TIMEE,1,12);
LCD_Write_3_Float_B(TIMEE,1,12);
LCD_Write_3_Float_A(COUNTA,2,7);
LCD_Write_3_Float_B(COUNTB,2,7);
}
}
}void Timer0Init()
{
TMOD=0X01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
ET0=1;
TR0=1;
EA=1;
}
void timer0( ) interrupt 1
{
int i;
static char COUNT_1S=0;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
COUNT_1S++;
if(COUNT_1S==20)
{
COUNT_1S=0;
TIME--;
if(TIME=0)
TIME=TIMERED;
}
}
void ExtiInit()
{
EX0=1;
EX1=1;
IT0=1;
IT1=1;
EA=1;
}
void Exti0() interrupt 0
{
COUNTA++;
if(COUNTA==100)
COUNTA=0;
}
void Exti1() interrupt 2
{
COUNTB++;
if(COUNTB==100)
COUNTB=0;
}
|