Maker Pro
Maker Pro

PIC decoding NEC signal with TIMER1 problem

R1S8k

Jul 28, 2018
22
Joined
Jul 28, 2018
Messages
22
Hello,

I'm trying to decode NEC remote control signal with my PIC18F4550, I started learning this couple days ago.
I've tried CCP capture mode, then IOC, then INT0, but all these ways were hard for me to start.

By searching I decided to follow a strategy by a programmer doing the project on his website, with different compiler.

I tried to copy his way but didn't work for me, with some modifications and tweaks I started to get some readings.

But the problem is that all the buttons give the same code! I don't know why.

I get like 0xFFFFFFF00.

I don't know what's wrong, but this is the best I could get, and this is my code in MPLAB XC8.

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
DECODING function:

uint32_t PIN_POLLING_VS1838b(uint16_t *arr)
{
TMR1=0;
while ((!PORTBbits.RB2) && (TMR1 < 10000)); // test 9ms low 9182
if ((TMR1 > 10000) || (TMR1 < 9000))
return 1;
TMR1 = 0;
while ((PORTBbits.RB2) && (TMR1 < 5000)); // test 4.5ms high ~4480
if ((TMR1 > 4600) || (TMR1 < 4300))
return 2;
TMR1 = 0;
/////////////////////////////////////////////////////////////////////
for(i=0;i<32;i++){ // 2.25ms & 1.25ms test
TMR1 = 0;
while ((!PORTBbits.RB2) && (TMR1 < 800));
TMR1 = 0;
while ((PORTBbits.RB2) && (TMR1 < 2000));
//arr=TMR1;
if((TMR1 < 700) && (TMR1 > 400))
ir_code_INT &= ~(1<<i);
else if((TMR1 < 2000) && (TMR1 > 1000))
ir_code_INT |= (1<<i);
}
/////////////////////////////////////////////////////////////////////
return ir_code_INT;//
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
MAIN function:

uint8_t val_arr[20],i_sprint[2];
uint16_t TMR1_RET[32];
uint32_t capture_val,ir_code_REC;
uint8_t i;

void main(void) {
INTOSC_4MHz;
AN_DISABLE;
//DISABLE_INT;
//ENABLE_INT_IOC;

i2c_init();
i2c_start();
LCD_Init();
TRISBbits.RB2=1;
TRISDbits.RD2=0;
TRISDbits.RD3=0;
INTCONbits.GIE=0;
INTCONbits.PEIE=0;
INTCONbits.INT0IE=0;
INTCON2bits.INTEDG0=0;
INTCON2bits.RBPU=1;
T1CON=0x80; // timer1 16-bits
T1CONbits.TMR1ON=1; // turn on timer1
while(1){

while (PORTBbits.RB2);
capture_val = PIN_POLLING_VS1838b(TMR1_RET);
sprintf(val_arr,"%lx",capture_val);
LCD_string("remote code:");
move_cursor(2,0);
LCD_string(val_arr);
__delay_ms(500);
sendCMD(clear_display);

}
}
 

Delta Prime

Jul 29, 2020
1,914
Joined
Jul 29, 2020
Messages
1,914
I take it...You have solved this problem, only because of the time span. Anyway, I'm here, I beat you, I win the race.!
 

R1S8k

Jul 28, 2018
22
Joined
Jul 28, 2018
Messages
22
Yep I solved the problem, and it was a good lesson to set up a certain code to test something.

And thank you for the motivational support :)
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
Anyway, I'm here, I beat you, I win the race.!
@Delta Prime : Not the first time I noticed you doing this. Please stop. This forum is not about being the first to reply. It is about helping others and this your style of commenting is no help at all. Stick to the topic, please.

If you feel the need to get rid of some issue off-topic, then create a thread of your own in the off-topic section. Otherwise you risk being banned from this forum.
 
Top