This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C123GH6PZ红外接收有问题



我目前在做一个红外接收的程序,参考了51和STM32的程序,如果延时没有问题,那问题会出在哪里呢?

main()中做了IO设置

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // ʹÄÜÍâÉèGPIOG

GPIOPadConfigSet(GPIO_PORTB_BASE,GPIO_PIN_2,
GPIO_STRENGTH_8MA,
GPIO_PIN_TYPE_STD_WPU);// ÉèÖÃPG0Ϊ2MA£¬ÉÏÀ­ÊäÈë

GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_DIR_MODE_IN); //PG0 ÉèΪºìÍâÊäÈë

GPIOIntTypeSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_FALLING_EDGE); // °´¼üÖжÏÉèΪϽµÑØ´¥·¢

GPIOPinIntEnable(GPIO_PORTB_BASE, GPIO_PIN_2); // ʹÄÜKEYËùÔڹܽŵÄÖжÏ

IntEnable(INT_GPIOB); // ʹÄÜGPIOG¶Ë¿ÚÖжÏ
IntMasterEnable(); // ʹÄÜ´¦ÀíÆ÷ÖжÏ

然后中断程序如下,但是却无法获取正确的红外编码(通过在LCD上显示接收到的数据),这是为什么呢?

void GPIO_INT_B(void)
{
unsigned char num;
ulStatus = GPIOPinIntStatus(GPIO_PORTB_BASE, true);
GPIOPinIntClear(GPIO_PORTB_BASE, ulStatus);
IntMasterDisable();

num=0;
inInt = 1;
while(1){
SysCtlDelay((SysCtlClockGet()/3)/20000); // ÑÓʱԼ0.1ms
num++;
if(num>86){
break;
}
}
num = 0;
while(0x04==RDATA){
SysCtlDelay((SysCtlClockGet()/3)/20000); // ÑÓʱԼ0.1ms
num++;
if(num>44) //45*0.1ms=4.5ms

IR_GET = RDATA;
//return;
num=0;
ok++;
return;
}
}

if(num>40&&num<50){
for (four=0;four<4;four++) 

for (one=0;one<8;one++) 
{
num=0;
while ((0x04!=RDATA)){
SysCtlDelay((SysCtlClockGet()/3)/20000); // ÑÓʱԼ0.1ms
num++;
if (num>=6) //18*0.1ms=1.8ms

ulStatus = GPIOPinIntStatus(GPIO_PORTB_BASE, true);
GPIOPinIntClear(GPIO_PORTB_BASE, ulStatus);

return;
}
}
while (0x04==RDATA) 

SysCtlDelay((SysCtlClockGet()/3)/20000); // ÑÓʱԼ0.1ms
num++;
if (num>=11) //18*0.1ms=1.8ms

ulStatus = GPIOPinIntStatus(GPIO_PORTB_BASE, true);
GPIOPinIntClear(GPIO_PORTB_BASE, ulStatus);
//ok++;
return;
}
}

RXDDATA[four]>>=1;
if(num>15&&num<18) 
{
RXDDATA[four]|=0x80;

}
}
ulStatus = GPIOPinIntStatus(GPIO_PORTB_BASE, true);
GPIOPinIntClear(GPIO_PORTB_BASE, ulStatus);
if (RXDDATA[2]!=~RXDDATA[3])

return; 
}
ldata=RXDDATA[2]&0x0F; 
hdata=RXDDATA[2]>>4; 
}
}