我的程序会将 IR 信号作为“0”或“1”存储到 DS89C450 的 xdata 1kByte SRAM 中,然后将其显示在我的 MTK 上。
但是,无论我在红外遥控器上按什么按钮,显示的数据都只显示字符“F”。(我有一个将数据转换为 ASCII 码的 CASE 函数,对于这种情况,“F”= 0x0F)。 http://img193.imageshack.us/img193/1410/66647882.png
首先:当接收到 IR 信号时,下降沿中断将触发,每 38us 将每个数据从 pin 存储到 x[i],并且 Data_Ready 设置为 1。
/******************************FALLING EDGE INTERRUPT*************************/
void ex_int0(void)interrupt 0
{
unsigned char p;
unsigned int u;
unsigned int i;
EA=0;
for(i=0;i<500;i++) //Loop for 500 bytes
{
for(u=0;u<8;u++) //Bit Shift Loop
{
timer0(); //Call timer0 function(38us)
x[i] = x[i] << 1; //Left Bit Shift by 1
p = Tsignal; //Store Tsignal to Buffer p
x[i] |= p; //OR Masking of p with x[i]
}
}
EA=1;
IE1 = 0;
Data_Ready = 1; //Set Data_Ready = 1
}//end
接下来,将存储数据逐字节转换为 ASCII 码。(例如 1111 1111 = FF)
/******************************DISPLAY_BYTE***********************************/
void Display_Byte()
{
unsigned char Data_LK;
unsigned char MSB;
unsigned char LSB;
unsigned int v;
TR1=1; //Enable Serial Port
for(v=0;v<500;v++)
{
Data_LK = x[v]; //Store x[v] in Data_LK
MSB = Data_LK >> 4; //Shift Right Bits by 4
MSB &= 0x0F; //Mask bits of MSB
MSB = lookuptable(MSB); //Send MSB to lookuptable function
SerialTx(MSB); //Send Converted Data to transmit
LSB = x[v]; //Store x[v] in LSB
LSB &= 0x0F; //Mask bits of LSB
LSB = lookuptable(LSB); //Send LSB to lookuptable
SerialTx(LSB); //Send converted data to transmit
}
Data_Ready = 0; //Set Data_Ready to 0
TR1 = 0; //Turn off Serial Port
}
这是查找表:
/***********************LOOKUP TABLE*************************************/
unsigned char lookuptable(unsigned char t)
{
switch(t)
{
case 0x00 : return '0';
break;
case 0x01 : return '1';
break;
case 0x02 : return '2';
break;
case 0x03 : return '3';
break;
case 0x04 : return '4';
break;
case 0x05 : return '5';
break;
case 0x06 : return '6';
break;
case 0x07 : return '7';
break;
case 0x08 : return '8';
break;
case 0x09 : return '9';
break;
case 0x0A : return 'A';
break;
case 0x0B : return 'B';
break;
case 0x0C : return 'C';
break;
case 0x0D : return 'D';
break;
case 0x0E : return 'E';
break;
case 0x0F : return 'F';
break;
default: break;
}// end switch
}// end function