remote control decoder code

Status
Not open for further replies.

sayf alawneh

Junior Member level 3
Joined
Aug 15, 2014
Messages
27
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
256
hello guys , i tried to do it all my self and i have to tell u that i have a terrible headache
any ways this code is to decode any remote control's signal protocol using mikroc pro and pic 16f877a and am sure there are lot of mistakes there please help me i think no body tried it before i couldnt find any info on the web :bang:
RC2(ccp1) is recieving the signal


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
int m ;char txt1[5],txt2[5];
int time1=0,time2=0;
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D7_Direction at TRISB7_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB4_bit;
void main() 
{
CMCON=7;//disable comparator
TRISC=255;// portc as input.
TRISB=0;portb as output.
PORTC=0;
PORTB=0;
T1CON=0B00000101;//enabling timer one  in asynchronized timer mode. 
INTCON=0B11000000;//enabling GIE and PEIE bits to allow interrupts
PIR1=0; //CCP1IF and TMR1IF are both zeros  
TMR1L=0;
TMR1H=0;// initializing TMR1L and TMR1H
LCD_INIT();
LCD_CMD(_LCD_CLEAR);
LCD_CMD(_LCD_CURSOR_OFF);
while(1){
CCP1CON=0B00000101; capture every  rising edge (the first one) and as i understood when first rising edge is captured CCP1IF will be 1 
PIE1=0B00000101;//TMR1IE and CCP1IE bits are enabled
if(CCP1IF_BIT==1){// when this bit is 1 the first rising edge is captured
time1=CCPR1L+(256*CCPR1H);//the time of the first rising edge
TMR1IF_BIT=0;//set the interrupt flag to zero to enable another oncoming one
CCP1IF_BIT=0;
}
CCP1CON=0B00000100;// capture every falling edge () the first falling edge)
PIE1=0B00000101;// CCP1IE and TMR1IE bits are enabled
if(CCP1IF_BIT==1){ if the first falling edge is captured
time2=CCPR1L+(256*CCPR1H);// the time of the first falling edge 
TMR1IF_BIT=0;//set the interrupt flag to zero to enable another oncoming one
CCP1IF_BIT=0;
}                                                                                                             ____
m=time2-time1;// m presents the time of an on pulse only i mean the 1 part (the positive part of the pulse)  |    |
inttostr(m,txt1);
LCD_OUT(1,1,txt1);
delay_ms(1000);
}
}


where is/are the problems guys ?
isnt this code supposed to give me the time for every positive pulse in the remote signal ?
i used a signal generator in proteus but look what i had
 
Last edited:

Hi,

On your LCD it shows a value of more than 150.000. How can this be?

The max for a 16 bit value is 65.535. Or are you working with more than 16 bits resolution?

Klaus
 

Hi,

On your LCD it shows a value of more than 150.000. How can this be?

The max for a 16 bit value is 65.535. Or are you working with more than 16 bits resolution?

Klaus

the prescalar is 1:1 am working with 16 bit resolution ;
i did a little change to the program in the lower side just to view more details on the LCD i solved the problem of the reading is being strange but still have other problems

Code:
int m ;int txt1[10],txt2[10],txt3[10];
int time1=0,time2=0;
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D7_Direction at TRISB7_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB4_bit;
void main() 
{
CMCON=7;
TRISC=255;
TRISB=0;
PORTC=0;
PORTB=0;
T1CON=0B00000101;
INTCON=0B11000000;
PIR1=0;
TMR1L=0;
TMR1H=0;
LCD_INIT();
LCD_CMD(_LCD_CLEAR);
LCD_CMD(_LCD_CURSOR_OFF);
while(1){
CCP1CON=0B00000101;
PIE1=0B00000101;
if(CCP1IF==1){
time1=CCPR1L+(256*CCPR1H);
TMR1IF_BIT=0;
CCP1IF_BIT=0;
}
CCP1CON=0B00000100;
PIE1=0B00000101;
if(CCP1IF_BIT==1){
time2=CCPR1L+(256*CCPR1H);
TMR1IF_BIT=0;
CCP1IF_BIT=0;
}
inttostr(time1,txt3);
inttostr(time2,txt2);
m=time2-time1;
inttostr(m,txt1);
LCD_OUT(1,1,txt3);//view the time of rising edges 
LCD_OUT(1,7,txt2);//view the time of falling edges
LCD_OUT(2,1,txt1);// view the positive part of the pulse time 
delay_ms(100);
}
}

notice that the time of falling edges always negative
the time of rising edges is always zero
 

please hep me guys
i didnt find any info about this project on the web
 

Hi,

you didn´t answer how to get a value of 150.000 out of an 16 bit value. It is impossible.


Falling edge is negative: A capture value is desired to be positive. So declare your variable to be unsigned instead of signed.

Klaus
 

hi back
if i know the poroblem i wouldnt ask
i think u didnt even read the code please give me aa real help not only short comments , am getting a negative pulse peroid and some times positive if the pulse starts with a falling edge then i should always get a positive time if i subtract the time of falling edge from the time of rising edge
but thats not happening
that problem of 150000 was solved and i think the problem was in the variables
so is there any problem in my code ?
am using a stable pulse source so shouldnt i get a constant time period and thats not happening !?
why that code dont do the desird purpose ?
also i dont understand the time thing
does the CCPR1L+(256*CCPR1H) introduces the time and what is the unit of the time
 
Last edited:

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…