CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Saving-learning signal length, bit numbers

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
king of swords



Joined: 18 Jun 2009
Posts: 7
Location: Türkiye

View user's profile Send private message Send e-mail MSN Messenger

Saving-learning signal length, bit numbers
PostPosted: Thu Jun 18, 2009 6:56 am     Reply with quote

Hi all,

I want to remote all the systems whichis remotes by ir..
I can save the codes, but it doesn't work.

I think the longest bit length is 64 bits. for example sony 12bits, nec 32bits etc..

My air conditioner has 64 bit length.

Here is my code, can you help me where my fault is??

Note: I can't know what the frequency of the receiving data, so when sending, i tried 37,1kHz---38kHz and 40kHz frequencies..

I'm getting crazy pls help Embarassed

Edit: I've added (printf)s to see the codes lengths rise and fall times..

Code:
#include <18f452.h>
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
#use delay (clock=4000000)
#use fast_io(b)
#use fast_io(d)
#use rs232 (baud=9600, xmit=pin_c6, rcv=pin_C7, parity=N, stop=1)
#byte tris_ir          =0x87   //c
int16 headp,heads,xx=0,xx1=0,rise[100]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                            0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                            0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                            0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                  fall[100]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                            0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                            0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                            0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
char protocol;
int rx_status,address=0;
int32 ir_tempbyte_hi;
int16 ir_tempbyte_lo;
int bitcount=0,sayi;
int32 MSB3,MSB2,MSB1,MSB0,LSB1,LSB0;
byte tx_bit;
int tx_c,i;
char y;
int klavye,klavye1,klavye2,dongu=0,say1=0;
int1 k=1;
////////////////////////////////////////////////////////////////////////////////
//#int_timer1
//void timer1_kesme(){
//i++;
//if(i==5){
//k=0;}
//}
////////////////////////////////////////////////////////////////////////////////
void ir_get_fall(void){
setup_counters(RTCC_INTERNAL,RTCC_DIV_1); 
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
set_timer1(0);
while(input(pin_b0));
rise[bitcount] = get_timer1();}
////////////////////////////////////////////////////////////////////////////////
void ir_get_rise(void){
setup_counters(RTCC_INTERNAL,RTCC_DIV_1);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
set_timer1(0);
while(!input(pin_b0));
rise[bitcount] = get_timer1();}
////////////////////////////////////////////////////////////////////////////////
void ir_build_bytes(void){
while(bitcount<65){
ir_get_rise();
ir_get_fall();
bitcount++;}
sayi=bitcount;
PRINTF("%d",SAYI);
printf("receiving datas finished..");delay_ms(20);
printf("rise1=%ld  fall=%ld",  rise[0],fall[0]); delay_ms(20);
printf("rise2=%ld  fall=%ld",  rise[1],fall[1]); delay_ms(20);
printf("rise3=%ld  fall=%ld",  rise[2],fall[2]); delay_ms(20);
printf("rise4=%ld  fall=%ld",  rise[3],fall[3]); delay_ms(20);
printf("rise5=%ld  fall=%ld",  rise[4],fall[4]); delay_ms(20);
printf("rise6=%ld  fall=%ld",  rise[5],fall[5]); delay_ms(20);
printf("rise7=%ld  fall=%ld",  rise[6],fall[6]); delay_ms(20);
printf("rise8=%ld  fall=%ld",  rise[7],fall[7]); delay_ms(20);
printf("rise9=%ld  fall=%ld",  rise[8],fall[8]); delay_ms(20);
printf("rise10=%ld fall=%ld",  rise[9],fall[9]); delay_ms(20);
printf("rise11=%ld fall=%ld", rise[10],fall[10]);delay_ms(20);
printf("rise12=%ld fall=%ld", rise[11],fall[11]);delay_ms(20);
printf("rise13=%ld fall=%ld", rise[12],fall[12]);delay_ms(20);
printf("rise14=%ld fall=%ld", rise[13],fall[13]);delay_ms(20);
printf("rise15=%ld fall=%ld", rise[14],fall[14]);delay_ms(20);
printf("rise16=%ld fall=%ld", rise[15],fall[15]);delay_ms(20);
printf("rise17=%ld fall=%ld", rise[16],fall[16]);delay_ms(20);
printf("rise18=%ld fall=%ld", rise[17],fall[17]);delay_ms(20);
printf("rise19=%ld fall=%ld", rise[18],fall[18]);delay_ms(20);
printf("rise20=%ld fall=%ld", rise[19],fall[19]);delay_ms(20);
printf("rise21=%ld fall=%ld", rise[20],fall[20]);delay_ms(20);
printf("rise22=%ld fall=%ld", rise[21],fall[21]);delay_ms(20);
printf("rise23=%ld fall=%ld", rise[22],fall[22]);delay_ms(20);
printf("rise24=%ld fall=%ld", rise[23],fall[23]);delay_ms(20);
printf("rise25=%ld fall=%ld", rise[24],fall[24]);delay_ms(20);
printf("rise26=%ld fall=%ld", rise[25],fall[25]);delay_ms(20);
printf("rise27=%ld fall=%ld", rise[26],fall[26]);delay_ms(20);
printf("rise28=%ld fall=%ld", rise[27],fall[27]);delay_ms(20);
printf("rise29=%ld fall=%ld", rise[28],fall[28]);delay_ms(20);
printf("rise30=%ld fall=%ld", rise[29],fall[29]);delay_ms(20);
printf("rise31=%ld fall=%ld", rise[30],fall[30]);delay_ms(20);
printf("rise32=%ld fall=%ld", rise[31],fall[31]);delay_ms(20);
printf("rise33=%ld fall=%ld", rise[32],fall[32]);delay_ms(20);
printf("rise34=%ld fall=%ld", rise[33],fall[33]);delay_ms(20);
printf("rise35=%ld fall=%ld", rise[34],fall[34]);delay_ms(20);
printf("rise36=%ld fall=%ld", rise[35],fall[35]);delay_ms(20);
printf("rise37=%ld fall=%ld", rise[36],fall[36]);delay_ms(20);
printf("rise38=%ld fall=%ld", rise[37],fall[37]);delay_ms(20);
printf("rise39=%ld fall=%ld", rise[38],fall[38]);delay_ms(20);
printf("rise40=%ld fall=%ld", rise[39],fall[39]);delay_ms(20);}

////////////////////////////////////////////////////////////////////////////////
void ir_tx(void){

setup_ccp2(CCP_PWM);
setup_timer_2(T2_DIV_BY_1,26,1);    // 37,1 kHz square wave on CCP1
set_pwm2_duty(13);

for(tx_c=0;tx_c!=sayi;tx_c++){
set_tris_c(0xfc);
delay_us(rise[sayi]);
set_tris_c(0xfe);
delay_us(fall[sayi]);}
printf("sent %d",sayi);
delay_ms(500);

setup_ccp2(CCP_PWM);
setup_timer_2(T2_DIV_BY_1,24,1);    // 40 kHz square wave on CCP1
set_pwm2_duty(12);

for(tx_c=0;tx_c!=sayi;tx_c++){
set_tris_c(0xfc);
delay_us(rise[sayi]);
set_tris_c(0xfe);
delay_us(fall[sayi]);}
printf("sent %d",sayi);
delay_ms(500);

setup_ccp2(CCP_PWM);
setup_timer_2(T2_DIV_BY_1,25,1);   //38kHz square wave on CCP1
set_pwm2_duty(52);
 
for(tx_c=1;tx_c!=sayi;tx_c++){
set_tris_c(0xfc);
delay_us(rise[sayi]);
set_tris_c(0xfe);
delay_us(fall[sayi]);}
printf("sent %d",sayi);
}
////////////////////////////////////////////////////////////////////////////////
#int_rda
void seri_kesme(){
klavye=getch();


if(klavye=='0''){
printf("learn mode opened..");set_tris_c(0xfe);k=1;bitcount=0;ir_build_bytes();}
if(klavye=='1'){
printf("send the data..");ir_tx();}}

////////////////////////////////////////////////////////////////////////////////
void main ()
{
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_CCP1(CCP_OFF);
   setup_CCP2(CCP_OFF);
   enable_interrupts(int_rda);
   enable_interrupts(int_timer1);
   enable_interrupts(GLOBAL);
   set_tris_b(0b00000001);
   output_b(0x00);
   output_low(PIN_C1); // Set CCP2 output low
   setup_ccp2(CCP_PWM);
   setup_timer_2(T2_DIV_BY_1,26,1);    // 37,1 kHz square wave on CCP1
   set_pwm2_duty(13);
   set_tris_c(0xfe);
while(1){
;}}


Last edited by king of swords on Thu Jun 18, 2009 10:07 am; edited 1 time in total
king of swords



Joined: 18 Jun 2009
Posts: 7
Location: Türkiye

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Thu Jun 18, 2009 7:06 am     Reply with quote

To save the datas, I will use external or internal eeprom. I'm trying to make it work at first.
mskala



Joined: 06 Mar 2007
Posts: 100
Location: Massachusetts, USA

View user's profile Send private message

PostPosted: Thu Jun 18, 2009 9:42 am     Reply with quote

Unless I am reading the code wrong, you don't understand the protocol and/or the modulation frequency.

There are various protocols, and they ride on top of a carrier which can be 38KHz, 40KHz, probably others. This does not mean you can either capture data or clock out data at this frequency.

Also, to make things easier, there are IR transmitters or IR receivers which already contain the modulator or demodulator, which makes coding very much easier. Look up TSOP2238 for example.

Also, using the TRIS bits is not useful for this application. Just use STANDARD_IO and let the compiler set the direction for you. It makes the code infinitely more readable.
king of swords



Joined: 18 Jun 2009
Posts: 7
Location: Türkiye

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Thu Jun 18, 2009 10:10 am     Reply with quote

mskala wrote:
Unless I am reading the code wrong, you don't understand the protocol and/or the modulation frequency.

There are various protocols, and they ride on top of a carrier which can be 38KHz, 40KHz, probably others. This does not mean you can either capture data or clock out data at this frequency.

Also, to make things easier, there are IR transmitters or IR receivers which already contain the modulator or demodulator, which makes coding very much easier. Look up TSOP2238 for example.

Also, using the TRIS bits is not useful for this application. Just use STANDARD_IO and let the compiler set the direction for you. It makes the code infinitely more readable.


Thank you so much mskala.. I'll go on working on it
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group