设计了17个独立按键发送数据。P1^0至P1^7和 P0^0至P0^6 设为独i立按键,按下后发送数据,按起又发送数据。但是P1^0至P1^7能够正常的发送数据,但是P0^0至P0^6 却不能发送数据。代码在keil软件中编译通过了。不知道问题在哪里?
#include<reg52.h>
typedef unsigned char BYTE;
typedef unsigned int uint;
//sbit LED0=P0^0;
sbit Input10=P1^0;
//sbit LED1=P0^1;
sbit Input11=P1^1;
//sbit LED2=P0^2;
sbit Input12=P1^2;
//sbit LED3=P0^3;
sbit Input13=P1^3;
//sbit LED4=P0^4;
sbit Input14=P1^4;
//sbit LED5=P0^5;
sbit Input15=P1^5;
sbit Input16=P1^6;
sbit Input17=P1^7;
sbit Input00=P0^0;
sbit Input01=P0^1;
sbit Input02=P0^2;
sbit Input03=P0^3;
sbit Input04=P0^4;
sbit Input05=P0^5;
sbit Input06=P0^6;
uint fg10=10, fg11=0, fg12=0,fg13=0, fg14=0, fg15=0,fg16=0,fg17=0;
uint fg00=0,fg01=0,fg02=0,fg03=0,fg04=0,fg05=0,fg06=0;
void SendByte(unsigned char *sent);//′®¿ú·¢ËíoˉêyéùÃ÷
void delay(uint sms);
InitUART()
{ //IO3õê¼»ˉoˉêy
SCON = 0x50; // SCON: Ä£ê½ 1, 8-bit UART
TMOD |= 0x20; // TMOD: timer 1, mode 2, 8-bit ÖØ×°
TH1 = 0xFD; // TH1: ÖØ×°ÖμFD£¬12MHZ,2¨ìØÂê9600
TR1 = 1; // TR1: timer 1 ′ò¿a
EA = 1; //′ò¿a×üÖD¶Ï
}
void main (void)
{
BYTE code E_CarEMPB_0[6]={0x02,0x01,0x00,0x02,0x06,0x03};//3μÏá½ô¼±í£3μ°′Å¥
BYTE code E_CarEMPB_F[6]={0x02,0x01,0xFF,0x02,0x06,0x03};
BYTE code E_CarEMPB_2_0[6]={0x02,0x01,0x00,0x03,0x04,0x03};//3μÏá½ô¼±í£3μ°′Å¥
BYTE code E_CarEMPB_2_F[6]={0x02,0x01,0xFF,0x03,0x04,0x03};
BYTE code E_ObstacleDetector_0[6]={0x02,0x02,0x00,0x03,0x00,0x03};//3μÔØÕÏ°-Îï¼ì2aÆ÷
BYTE code E_ObstacleDetector_F[6]={0x02,0x02,0xFF,0x03,0x00,0x03};
BYTE code E_ObstacleDetector_2_0[6]={0x02,0x02,0x00,0x06,0x00,0x03};//3μÔØÕÏ°-Îï¼ì2aÆ÷
BYTE code E_ObstacleDetector_2_F[6]={0x02,0x02,0xFF,0x06,0x00,0x03};
BYTE code E_StationEMPB_0[6]={0x02,0x03,0x00,0x01,0x02,0x03};//3μվվ쨽ô¼±í£3μ°′Å¥
BYTE code E_StationEMPB_F[6]={0x02,0x03,0xFF,0x01,0x02,0x03};
BYTE code E_StationEMPB_2_0[6]={0x02,0x03,0x00,0x02,0x01,0x03};//3μվվ쨽ô¼±í£3μ°′Å¥
BYTE code E_StationEMPB_2_F[6]={0x02,0x03,0xFF,0x02,0x01,0x03};
BYTE code E_StationEMPB_3_0[6]={0x02,0x03,0x00,0x03,0x01,0x03};//3μվվ쨽ô¼±í£3μ°′Å¥
BYTE code E_StationEMPB_3_F[6]={0x02,0x03,0xFF,0x03,0x01,0x03};
BYTE code E_StationFire_0[6]={0x02,0x04,0x00,0x01,0x00,0x03};//3μÕ¾»eÔÖ
BYTE code E_StationFire_F[6]={0x02,0x04,0xFF,0x01,0x00,0x03};
BYTE code E_StationFire_2_0[6]={0x02,0x04,0x00,0x02,0x00,0x03};//3μÕ¾»eÔÖ
BYTE code E_StationFire_2_F[6]={0x02,0x04,0xFF,0x02,0x00,0x03};
BYTE code E_StationFire_3_0[6]={0x02,0x04,0x00,0x03,0x00,0x03};//3μÕ¾»eÔÖ
BYTE code E_StationFire_3_F[6]={0x02,0x04,0xFF,0x03,0x00,0x03};
BYTE code E_SectionIntrusion_0[6]={0x02,0x05,0x00,0x01,0x00,0x03};//Çø¼äèËÔ±èëÇÖ
BYTE code E_SectionIntrusion_F[6]={0x02,0x05,0xFF,0x01,0x00,0x03};
BYTE code E_SectionIntrusion_2_0[6]={0x02,0x05,0x00,0x02,0x00,0x03};//Çø¼äèËÔ±èëÇÖ
BYTE code E_SectionIntrusion_2_F[6]={0x02,0x05,0xFF,0x02,0x00,0x03};
BYTE code E_SectionFire_0[6]={0x02,0x06,0x00,0x01,0x00,0x03};//Çø¼ä»eÔÖ
BYTE code E_SectionFire_F[6]={0x02,0x06,0xFF,0x01,0x00,0x03};
BYTE code E_SectionFire_2_0[6]={0x02,0x06,0x00,0x02,0x00,0x03};//Çø¼ä»eÔÖ
BYTE code E_SectionFire_2_F[6]={0x02,0x06,0xFF,0x02,0x00,0x03};
BYTE code E_SectionFire_3_0[6]={0x02,0x06,0x00,0x03,0x00,0x03};//Çø¼ä»eÔÖ
BYTE code E_SectionFire_3_F[6]={0x02,0x06,0xFF,0x03,0x00,0x03};
Input10=1;
Input11=1;
Input12=1;
Input13=1;
Input14=1;
Input15=1;
Input16=1;
Input17=1;
Input00=1;
Input01=1;
Input02=1;
Input03=1;
Input04=1;
Input05=1;
Input06=1;
InitUART();
ES=1;//′ò¿a′®¿úÖD¶ÏÔêDí
while(1)
{
if(Input10==0) //°′Ï£¬·¢°ü,3μÏá½ô¼±í£3μ°′Å¥
{
delay(5);//Ñó3ù£¬è¥¶¶¶ˉ
if(Input10==0&&fg10==0)
{
SendByte(&E_CarEMPB_0[0]);
// LED0=0;
fg10=1; //Ôö¼óÕa¸ö±êÖ¾£¬
}
}
else
{
delay(5);//Ñó3ù襶¶¶ˉ
if(Input10==1&&fg10==1)
{
SendByte(&E_CarEMPB_F[0]); //°′Æe£¬·¢°ü
// LED0=1;
fg10=0;
}
}
if(Input11==0) //°′Ï£¬·¢°ü,3μÏá½ô¼±í£3μ°′Å¥
{
delay(5);//Ñó3ù£¬è¥¶¶¶ˉ
if(Input11==0&&fg11==0)
{
SendByte(&E_CarEMPB_2_0[0]);
// LED1=0;
fg11=1; //Ôö¼óÕa¸ö±êÖ¾£¬£¬
}
}
else
{
delay(5);//Ñó3ù襶¶¶ˉ
if(Input11==1&&fg11==1)
{
SendByte(&E_CarEMPB_2_F[0]); //°′Æe£¬·¢°ü
// LED1=1;
fg11=0;
}
}
if(Input12==0) //°′Ï£¬·¢°ü
{
delay(5);//Ñó3ù£¬è¥¶¶¶ˉ
if(Input12==0&&fg12==0)
{
SendByte(&E_ObstacleDetector_0[0]);
// LED2=0;
fg12=1; //Ôö¼óÕa¸ö±êÖ¾£¬
}
}
else
{
delay(5);//Ñó3ù襶¶¶ˉ
if(Input12==1&&fg12==1)
{
SendByte(&E_ObstacleDetector_F[0]); //°′Æe£¬·¢°ü
// LED2=1;
fg12=0;
}
}
if(Input13==0) //°′Ï£¬·¢°ü
{
delay(5);//Ñó3ù£¬è¥¶¶¶ˉ
if(Input13==0&&fg13==0)
{
SendByte(&E_ObstacleDetector_2_0[0]);
// LED3=0;
fg13=1; //Ôö¼óÕa¸ö±êÖ¾£¬£¬
}
}
else
{
delay(5);//Ñó3ù襶¶¶ˉ
if(Input13==1&&fg13==1)
{
SendByte(&E_ObstacleDetector_2_F[0]); //°′Æe£¬·¢°ü
// LED3=1;
fg13=0;
}
}
if(Input14==0) //°′Ï£¬·¢°ü
{
delay(5);//Ñó3ù£¬è¥¶¶¶ˉ
if(Input14==0&&fg14==0)
{
SendByte(&E_StationEMPB_0[0]);
// LED4=0;
fg14=1; //Ôö¼óÕa¸ö±êÖ¾£¬£¬
}
}
else
{
delay(5);//Ñó3ù襶¶¶ˉ
if(Input14==1&&fg14==1)
{
SendByte(&E_StationEMPB_F[0]); //°′Æe£¬·¢°ü
// LED4=1;
fg14=0;
}
}
if(Input15==0) //°′Ï£¬·¢°ü
{
delay(5);//Ñó3ù£¬è¥¶¶¶ˉ
if(Input15==0&&fg15==0)
{
SendByte(&E_StationEMPB_2_0[0]);
// LED5=0;
fg15=1; //Ôö¼óÕa¸ö±êÖ¾£¬£¬
}
}
else
{
delay(5);//Ñó3ù襶¶¶ˉ
if(Input15==1&&fg15==1)
{
SendByte(&E_StationEMPB_2_F[0]); //°′Æe£¬·¢°ü
// LED5=1;
fg15=0;
}
}
if(Input16==0) //°′Ï£¬·¢°ü
{
delay(5);//Ñó3ù£¬è¥¶¶¶ˉ
if(Input16==0&&fg16==0)
{
SendByte(&E_StationEMPB_3_0[0]);
fg16=1; //Ôö¼óÕa¸ö±êÖ¾£¬
}
}
else
{
delay(5);//Ñó3ù襶¶¶ˉ
if(Input16==1&&fg16==1)
{
SendByte(&E_StationEMPB_3_F[0]); //°′Æe£¬·¢°ü
fg16=0;
}
}
if(Input17==0) //°′Ï£¬·¢°ü
{
delay(5);//Ñó3ù£¬è¥¶¶¶ˉ
if(Input17==0&&fg17==0)
{
SendByte(&E_StationFire_0[0]);
fg17=1; //Ôö¼óÕa¸ö±êÖ¾
}
}
else
{
delay(5);//Ñó3ù襶¶¶ˉ
if(Input17==1&&fg17==1)
{
SendByte(&E_StationFire_F[0]); //°′Æe£¬·¢°ü
fg17=0;
}
}
if(Input00==0) //°′Ï£¬·¢°ü
{
delay(5);//Ñó3ù£¬è¥¶¶¶ˉ
if(Input00==0&&fg00==0)
{
SendByte(&E_StationFire_2_0[0]);
fg00=1; //Ôö¼óÕa¸ö±êÖ¾
}
}
else
{
delay(5);//Ñó3ù襶¶¶ˉ
if(Input00==1&&fg00==1)
{
SendByte(&E_StationFire_2_F[0]); //°′Æe£¬·¢°ü
fg00=0;
}
}
if(Input01==0) //°′Ï£¬·¢°ü
{
delay(5);//Ñó3ù£¬è¥¶¶¶ˉ
if(Input01==0&&fg01==0)
{
SendByte(&E_StationFire_3_0[0]);
fg01=1; //Ôö¼óÕa¸ö±êÖ¾£¬
}
}
else
{
delay(5);//Ñó3ù襶¶¶ˉ
if(Input01==1&&fg01==1)
{
SendByte(&E_StationFire_3_F[0]); //°′Æe£¬·¢°ü
fg01=0;
}
}
if(Input02==0) //°′Ï£¬·¢°ü
{
delay(5);//Ñó3ù£¬è¥¶¶¶ˉ
if(Input02==0&&fg02==0)
{
SendByte(&E_SectionIntrusion_0[0]);
fg02=1; //Ôö¼óÕa¸ö±êÖ¾£¬
}
}
else
{
delay(5);//Ñó3ù襶¶¶ˉ
if(Input02==1&&fg02==1)
{
SendByte(&E_SectionIntrusion_F[0]); //°′Æe£¬·¢°ü
fg02=0;
}
}
if(Input03==0) //°′Ï£¬·¢°ü
{
delay(5);//Ñó3ù£¬è¥¶¶¶ˉ
if(Input03==0&&fg03==0)
{
SendByte(&E_SectionIntrusion_2_0[0]);
fg03=1; //Ôö¼óÕa¸ö±êÖ¾£¬
}
}
else
{
delay(5);//Ñó3ù襶¶¶ˉ
if(Input03==1&&fg03==1)
{
SendByte(&E_SectionIntrusion_2_F[0]); //°′Æe£¬·¢°ü
fg03=0;
}
}
if(Input04==0) //°′Ï£¬·¢°ü
{
delay(5);//Ñó3ù£¬è¥¶¶¶ˉ
if(Input04==0&&fg04==0)
{
SendByte(&E_SectionFire_0[0]);
fg04=1; //Ôö¼óÕa¸ö±êÖ¾£¬
}
}
else
{
delay(5);//Ñó3ù襶¶¶ˉ
if(Input04==1&&fg04==1)
{
SendByte(&E_SectionFire_F[0]); //°′Æe£¬·¢°ü
fg04=0;
}
}
if(Input05==0) //°′Ï£¬·¢°ü
{
delay(5);//Ñó3ù£¬è¥¶¶¶ˉ
if(Input05==0&&fg05==0)
{
SendByte(&E_SectionFire_2_0[0]);
fg05=1; //Ôö¼óÕa¸ö±êÖ¾£¬
}
}
else
{
delay(5);//Ñó3ù襶¶¶ˉ
if(Input05==1&&fg05==1)
{
SendByte(&E_SectionFire_2_F[0]); //°′Æe£¬·¢°ü
fg05=0;
}
}
if(Input06==0) //°′Ï£¬·¢°ü
{
delay(5);//Ñó3ù£¬è¥¶¶¶ˉ
if(Input06==0&&fg06==0)
{
SendByte(&E_SectionFire_3_0[0]);
fg06=1; //Ôö¼óÕa¸ö±êÖ¾£¬
}
}
else
{
delay(5);//Ñó3ù襶¶¶ˉ
if(Input06==1&&fg06==1)
{
SendByte(&E_SectionFire_3_F[0]); //°′Æe£¬·¢°ü
fg06=0;
}
}
}
}
void SendByte(BYTE *sent) //·¢Ëíoˉêy
{
uint i;
BYTE SE[6];
for(i=0;i<6;i++)
{
SE
=*(sent++);
}
for(i=0;i<6;i++)
{
SBUF=SE;
while(!TI); //μè′y8 bitμÄêy¾Yè«2¿′æ′¢μ½SBUFÖD£¬è»oóTI=1
TI=0;
}
}
void delay(uint sms)
{
uint x,y;
for(x=sms;x>0;x--)
for(y=110;y>0;y--);
}
[ 本帖最后由 ml0943 于 2013-1-7 12:46 编辑 ]
此帖出自小平头技术问答
一周热门 更多>