新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 315M單片機(jī)無線解碼--HS2262

315M單片機(jī)無線解碼--HS2262

作者: 時間:2016-11-18 來源:網(wǎng)絡(luò) 收藏
發(fā)上程序前記一個C語言小知識,免得下次犯同樣錯誤!
unsigned char i=0x01;
i=i<<1+1;
其結(jié)果i的值為4,而不是3。
C語言除法運(yùn)算中,余數(shù)的符合要求和被除數(shù)的符號一致,比如:2/(-2); 結(jié)果為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);
}
}
}


評論


技術(shù)專區(qū)

關(guān)閉