请问你的代码是怎样的?这是我的代码,帮我看看是什么问题,谢谢。。
#define uchar unsigned char
#define uint unsigned int
#include <reg52.h>
/*****¶¨Òå¿ØÖÆλ**********************/
sbit Time_Show_LED2=P2^5;//Time_Show_LED2¿ØÖÆλ
sbit Time_Show_LED1=P2^4;//Time_Show_LED1¿ØÖÆλ
sbit EW_LED2=P2^3; //EW_LED2¿ØÖÆλ
sbit EW_LED1=P2^2; //EW_LED1¿ØÖÆλ
sbit SN_LED2=P2^1; //SN_LED2¿ØÖÆλ
sbit SN_LED1=P2^0; //SN_LED1¿ØÖÆλ
sbit SN_Yellow=P1^6;//SN»ÆµÆ
sbit EW_Yellow=P1^2;//EW»ÆµÆ
sbit EW_Red=P1^3;//EWºìµÆ
sbit SN_Red=P1^7;//SNºìµÆ
sbit EW_Redlift=P2^6;//EW×óתºìµÆ
sbit SN_Redlift=P2^7;//SN×óתºìµÆ
sbit SN_ManGreen=P3^0;//SNÈËÐеÀÂ̵Æ
sbit EW_ManGreen=P3^1;//EWÈËÐеÀÂ̵Æ
sbit SN_ManRed=P3^2;//SNÈËÐеÀºìµÆ
sbit EW_ManRed=P3^5;//EWÈËÐеÀºìµÆ
sbit Busy_Btton=P3^6;//½»Í¨·±Ã¦°´¼ü
sbit Special_Btton=P3^7;//½»Í¨ÌØÊâ°´¼ü
sbit Add_Button=P3^3;//ʱ¼ä¼Ó
sbit Reduces_Button=P3^4;//ʱ¼ä¼õ
bit Flag_SN_Yellow; //SN»ÆµÆ±ê־λ
bit Flag_EW_Yellow;//EW»ÆµÆ±ê־λ
bit flag_jinji;
char Time_EW;//¶«Î÷·½Ïòµ¹¼Æʱµ¥Ôª
char Time_SN;//Äϱ±·½Ïòµ¹¼Æʱµ¥Ôª
uchar EW=60,SN=40,EWL=19,SNL=19; //³ÌÐò³õʼ»¯¸³Öµ£¬Õý³£Ä£Ê½
uchar EW1=60,SN1=40,EWL1=19,SNL1=19;//ÓÃÓÚ´æ·ÅÐÞ¸ÄÖµµÄ±äÁ¿
uchar code table[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};//1~~~~9¶ÎÑ¡Âë
uchar code S[9]={0X28,0X48,0X98,0X48,0X82,0X84,0X89,0X84,0x88};//½»Í¨ÐźŵƿØÖÆ´úÂë
/**********************ÑÓʱ×Ó³ÌÐò************************/
void delay(uint x)
{
uint p;
uchar q;
for(p=0;p<x;p++)
for(q=0;q<125;q++);
}
/*****************ÏÔʾ×Óº¯Êý**************************/
void Display(void)
{
char h,l;
h=Time_EW/10;
l=Time_EW%10;
P0=table[l];
EW_LED2=1;
delay(1);
EW_LED2=0;
P0=table[h];
EW_LED1=1;
delay(1);
EW_LED1=0;
h=Time_SN/10;
l=Time_SN%10;
P0=table[l];
SN_LED2=1;
delay(1);
SN_LED2=0;
P0=table[h];
SN_LED1=1;
delay(1);
SN_LED1=0;
h= EW1/10;
l= EW1%10;
P0=table[l];
Time_Show_LED1=1;
delay(1);
Time_Show_LED1=0;
P0=table[h];
Time_Show_LED2=1;
delay(1);
Time_Show_LED2=0;
}
void KEY()
{
if(Add_Button==0) //ʱ¼ä¼Ó
{
delay(20);
if(Add_Button==0)
{
EW1+=5;
SN1+=5;
SN1=EW1-10;
EWL1=19;
SNL1=19;
if(EW1>=100)
{
EW1=99;
SN1=89;
}
}
while(Add_Button==0) Display();
}
if(Reduces_Button==0) //ʱ¼ä¼õ
{
delay(20);
if(Reduces_Button==0)
{
EW1-=5;
SN1-=5;
SN1=EW1-10;
EWL1=19;
SNL1=19;
if(EW1<=40)
{
EW1=40;
SN1=30;
}
}
while(Reduces_Button==0) Display();
}
if(Busy_Btton==0) //²âÊÔ°´¼üÊÇ·ñ°´Ï£¬°´ÏÂΪ·±Ã¦×´Ì¬
{
delay(20);
if(Busy_Btton==0)
{
EW1=45;
SN1=30;
EWL1=14;
SNL1=14;
}
while(Busy_Btton==0) Display();
}
if(Special_Btton==0)
{
delay(50);
if(Special_Btton==0)
flag_jinji=~flag_jinji;
while(Special_Btton==0) Display();
}
}
/**********************T0ÖжϷþÎñ³ÌÐò*******************/
void timer0() interrupt 1 using 1
{
static uchar count;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
if(count==10)
{
if(Flag_SN_Yellow==1) //²âÊÔÄϱ±»ÆµÆ±ê־λ
{
SN_Yellow=~SN_Yellow;
}
if(Flag_EW_Yellow==1) //²âÊÔ¶«Î÷»ÆµÆ±ê־λ
{
EW_Yellow=~EW_Yellow;
}
}
if(count==20)
{
Time_EW--;
Time_SN--;
if(Flag_SN_Yellow==1)//²âÊÔÄϱ±»ÆµÆ±ê־λ
{
SN_Yellow=~SN_Yellow;
}
if(Flag_EW_Yellow==1)//²âÊÔ¶«Î÷»ÆµÆ±ê־λ
{
EW_Yellow=~EW_Yellow;
}
count=0;
}
}
/*********************Ö÷³ÌÐò¿ªÊ¼**********************/
void main(void)
{
TMOD=0x01;//¶¨Ê±Æ÷¹¤×÷ÓÚ·½Ê½1
TH0=(65536-50000)/256;//¶¨Ê±Æ÷¸³³õÖµ
TL0=(65536-50000)%256;
EA=1; //CPU¿ªÖжÏ×ÜÔÊÐí
ET0=1;//¿ª¶¨Ê±ÖжÏ
TR0=1;//Æô¶¯¶¨Ê±
while(1)
{
if(flag_jinji==0)
{
/*******S0״̬**********/
Time_EW=EW;
Time_SN=SN;
while(Time_SN>=3&&flag_jinji==0)
{
P1=S[0]; //SNͨÐУ¬EWºìµÆ
SN_Redlift=1; //SN×óתºìµÆÁÁ
EW_Redlift=1; //EW×óתºìµÆÁÁ
SN_Yellow=0;
EW_Yellow=0;
EW_ManGreen=1; //EWÈËÐеÀ½ûÖ¹
SN_ManGreen=0; //SNÈËÐеÀͨÐÐ
EW_ManRed=0; //
SN_ManRed=1; //
Flag_EW_Yellow=0; //EW¹Ø»ÆµÆÏÔʾÐźÅ
Display();
KEY();
}
/*******S1״̬**********/
P1=0x00;
while(Time_SN>=0&&flag_jinji==0)
{
Flag_SN_Yellow=1; //SN¿ª»ÆµÆÐźÅλ
SN_ManGreen=0;
EW_ManGreen=0;
EW_Red=1; //SN»ÆµÆÁÁ£¬µÈ´ý×ó¹ÕÐźţ¬EWºìµÆ
SN_Red=0; //
EW_ManRed=1; //
SN_ManRed=1; //
SN_Redlift=0; //SN×óתºìµÆÃð
EW_Redlift=1; //EW×óתºìµÆÁÁ
Display();
KEY();
}
/*******S2״̬**********/
Time_SN=SNL;
while(Time_SN>=3&&flag_jinji==0)
{
P1=S[2];//SN×ó¹ÕÂ̵ÆÁÁ£¬EWºìµÆ SNºìµÆ 10011000
Flag_SN_Yellow=0; //SN¹Ø»ÆµÆÏÔʾÐźÅ
SN_Yellow=0;
EW_Yellow=0;
SN_ManGreen=0;//SNÈËÐеÀjinzhi
EW_ManGreen=0;
EW_ManRed=1; //
SN_ManRed=1; //
SN_Redlift=0; //SN×óתºìµÆÃð
EW_Redlift=1; //EW×óתºìµÆÁÁ
Display();
KEY();
}
/*******S3״̬**********/
P1=0x00;
Flag_SN_Yellow=1; //SN¿ª»ÆµÆÐźÅλ
Flag_EW_Yellow=1; //EW¿ª»ÆµÆÐźÅλ
while(Time_SN>=0&&flag_jinji==0)
{
EW_Red=0; //SN»ÆµÆÁÁ,µÈ´ýÍ£Ö¹Ðźţ¬EWºìµÆ
SN_Red=0;
SN_ManGreen=0;
EW_ManGreen=0;
EW_ManRed=1;
SN_ManRed=1;
SN_Redlift=0; //SN×óתºìµÆÃð
EW_Redlift=0; //EW×óתºìµÆÃð
Display();
KEY();
}
/***********¸³Öµ**********/
EW=EW1;
SN=SN1;
EWL=EWL1;
SNL=SNL1;
/*******S4״̬**********/
Flag_SN_Yellow=0; //SN¹Ø»ÆµÆÏÔʾÐźÅ
Time_EW=SN;
Time_SN=EW;
while(Time_EW>=3&&flag_jinji==0)
{
P1=S[4]; //EWͨÐУ¬SNºìµÆ
SN_Redlift=1; //SN×óתºìµÆÁÁ
EW_Redlift=1; //EW×óתºìµÆÁÁ
SN_Yellow=0;
EW_Yellow=0;
EW_ManGreen=0;//EWÈËÐеÀͨÐÐ
SN_ManGreen=1;//SNÈËÐеÀ½ûÖ¹
EW_ManRed=1;
SN_ManRed=0;
Display();
KEY();
}
/*******S5״̬**********/
P1=0X00;
while(Time_EW>=0&&flag_jinji==0)
{
Flag_EW_Yellow=1;//EW¿ª»ÆµÆÐźÅλ
SN_ManGreen=0;
EW_ManGreen=0;
SN_Red=1;//EW»ÆµÆÁÁ£¬µÈ´ý×ó¹ÕÐźţ¬SNºìµÆ
EW_Red=0;
EW_ManRed=1;
SN_ManRed=1;
SN_Redlift=1; //SN×óתºìµÆÃð
EW_Redlift=0; //EW×óתºìµÆÃð
Display();
KEY();
}
/*******S6״̬**********/
Flag_EW_Yellow=0; //EW¹Ø»ÆµÆÏÔʾÐźÅ
Time_EW=EWL;
while(Time_EW>=3&&flag_jinji==0)
{
SN_Yellow=0;
EW_Yellow=0;
P1=S[6];//EW×ó¹ÕÂ̵ÆÁÁ£¬SNºìµÆ 10001001
EW_ManGreen=0;
SN_ManGreen=0;
EW_ManRed=1;
SN_ManRed=1;
SN_Redlift=1; //SN×óתºìµÆÁÁ
EW_Redlift=0; //EW×óתºìµÆÃð
Display();
KEY();
}
/*******S7״̬**********/
P1=0X00;
while(Time_EW>=0&&flag_jinji==0)
{
Flag_EW_Yellow=1; //EW¿ª»ÆµÆÐźÅλ
Flag_SN_Yellow=1; //SN¿ª»ÆµÆÐźÅλ
SN_Red=0;//EW»ÆµÆÁÁ£¬µÈ´ýÍ£Ö¹Ðźţ¬SNºìµÆ
EW_Red=0;
EW_ManGreen=0;
SN_ManGreen=0;
EW_ManRed=1;
SN_ManRed=1;
SN_Redlift=0; //SN×óתºìµÆÃð
EW_Redlift=0; //EW×óתºìµÆÃð
Display();
KEY();
}
/***********¸³Öµ**********/
EW=EW1;
SN=SN1;
EWL=EWL1;
SNL=SNL1;
}
else
{
P1=S[8];
EW_ManGreen=0;//EWÈËÐеÀͨÐÐ
SN_ManGreen=0;
KEY();
}
}
} |