微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 315M单片机无线解码--HS2262

315M单片机无线解码--HS2262

时间:11-18 来源:互联网 点击:
发上程序前记一个C语言小知识,免得下次犯同样错误!

unsigned char i=0x01;

i=i<1+1;

其结果i的值为4,而不是3。

C语言除法运算中,余数的符合要求和被除数的符号一致,比如:2/(-2); 结果为FF(-1), 2%(-2)=0

/********************************************************/

#include

unsigned char counter=0;

unsigned char Receive[3];

sbit RemPin=P0^0;

static bit flag=0;

sbit LED=P2^0;

sbit LED1=P2^5;

void delay( )

{

unsigned char i;

for(i=0;i<50;i++);

}

void delay_nms(unsigned int n)

{

unsigned int i=0,j=0;

for (i=n;i>0;i--)

for (j=0;j<1140;j++);

}

void scan()

{

unsigned char i=0;

unsigned char j=0;

unsigned char Time=10;

unsigned int count=0;

Receive[0]=Receive[1]=Receive[2]=0;

while(--Time)

{

count=0;

while(RemPin)

{

count++;

delay();

if(count>30)

{

break;

}

}

if((count>25)||(count<10))

{

continue;

}

count=0;

while(!RemPin)

{

count++;

delay( );

if(count>660)

{

break;

}

}

if((count>655)||(count<600))

{

continue;

}

count=0;

for(j=0;j<3;j++)

{

for(i=0;i<8;i++)

{

while(RemPin);

count=0;

while(!RemPin)

{

count++;

delay( );

if(count>=85)

{

return;

}

}

if((count>15)&&(count<42))

{

//counter=count;

Receive[j]=Receive[j]<1;

Receive[j]=Receive[j]+0x01;

}

else if((count>45)&&(count<75))

{

Receive[j]=Receive[j]<1;

//counter=count;

}

else

{

//LED1=~LED1;

Receive[0]=Receive[1]=Receive[2]=0;

counter=count;

return;

}

while(RemPin);

}

}

flag=1;

//LED=~LED;

}

}

void main()

{

while(1)

{

scan();

//P1=counter;

if(flag)

{

flag=0;

P1=Receive[2];

P1=~P1;

delay_nms(100);

}

}

}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top