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 CCS Technical Support

RC5 Code to ascii

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
walid shogun
Guest







RC5 Code to ascii
PostPosted: Tue Apr 22, 2003 2:55 am     Reply with quote

Has anybody an idea how to convert rc5 code to ASCII
many thanks in advance
___________________________
This message was ported from CCS's old forum
Original Post ID: 13906
Marcin
Guest







Re: RC5 Code to ascii
PostPosted: Thu Apr 24, 2003 7:44 am     Reply with quote

This is full code to reactive all of IR codes.

#include <16F84A.H>
#fuses HS,NOPROTECT,NOWDT
#use delay(clock=12000000)
#include <lcd.c>
#define BUT PIN_A2
#DEFINE RED_LED PIN_A0
#define IR_SENSOR PIN_B0
#define RED_ON output_high(RED_LED)
#define RED_OFF output_low(RED_LED)
#define IR (!input(IR_SENSOR))

typedef struct
{
int8 bajt[6];
int8 std;
} int48;

int48 code;

pulse()
{
output_high(RED_LED);
delay_ms(200);
output_low(RED_LED);
}

int1 get_ir(void)
{
int16 tmp;
int t,t4,j,i,k,ofset;
short bit;
set_timer0(0);
while(IR==1);
t=get_timer0(); //RC-5 -> t=30-60
//Sony -> t=98-128
//NEC80 & REC80 -> t=155-185
tmp=0;
//NEC80 & REC80
if (code.std<2)
{
if (t>155) if (t<185);
else return (0);
if (code.std==0) ofset=5;
else ofset=3;
while(IR==0);
set_timer0(0);
while(IR==1);
t=get_timer0();
t=t*2;
t4=t*2;
for (i=0;i<((code.std==0) ? 48 : 32);i++)
{
set_timer0(0);
while(IR==0)
{
j=get_timer0();
if (j>t4) return (0);
}
k=ofset-(i/8);
code.bajt[k]<<=1;
if (j>t) code.bajt[k]++;
while(IR==1);
}
}
else
//RC-5
if (code.std==2)
{
if (t>30) if (t<60);
else return;
for (i=0;i<13;i++)
{
bit=IR;
set_timer0(0);
while (IR==bit)
{
j=get_timer0();
if (j>60) return (0);
}
tmp<<=1;
if (bit==0) tmp++;
set_timer0(0);
while (get_timer0()<53);
}
tmp=tmp | 0x3000; // add start bits
tmp=tmp & 0x37ff; // cut togle bit
}
//Sony-12 Sony-15
else
{
if (t>98) if (t<128);
else return;
for (i=0;i<((code.std==3) ? 15 : 12);i++)
{
set_timer0(0);
while(IR==0)
{
t=get_timer0();
if (t>100) return (0);
}
t=t+15;
set_timer0(0);
while(IR==1)
{
j=get_timer0();
if (t>100) return (0);
}
tmp<<=1;
if (j>t) tmp++;
}
}

if (code.std>1)
{
code.bajt[0]=tmp & 0xff;
tmp>>=8;
code.bajt[1]=tmp & 0xff;
}

//display code
lcd_putc("\f");
if (code.std<2)
{
if (code.std==0) printf(lcd_putc,"R80:\%X\%X",code.bajt[5],code.bajt[4]);
else lcd_putc("N80:");
printf(lcd_putc,"\%X\%X",code.bajt[3],code.bajt[2]);
}
else if (code.std==2) lcd_putc("RC5:");
else if (code.std==3) lcd_putc("S15:");
else lcd_putc("S12:");
printf(lcd_putc,"\%X\%X",code.bajt[1],code.bajt[0]);
pulse();
return (1);
}


#int_ext
interrupt()
{
get_ir();
}

recognize_code()
{
pulse();
disable_interrupts(int_ext);
code.std=0;
while(get_ir()==0)
{
delay_ms(100);
code.std++;
if (code.std>4) code.std=0;
while (IR==0);
}
pulse();
enable_interrupts(int_ext);
}

main()
{
lcd_init();
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_64);
enable_interrupts(global|int_ext);
ext_int_edge(H_TO_L);
printf(lcd_putc,"\fOK");
while(1) if (input(BUT)==0) {pulse();recognize_code();}
}

Device: SFH506XX or TSOP17XX
where xx-frequency (recommended 38)
You must connect out pin from IR device to PIN_B0.
___________________________
This message was ported from CCS's old forum
Original Post ID: 13966
jruibarroso



Joined: 07 Jan 2006
Posts: 64
Location: Braga

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

Excelente code , works 100 %
PostPosted: Sat Oct 14, 2006 6:07 am     Reply with quote

Can you kindly convert this code only to read RC5 remotes and transform all code into a "driver" code to add to my project and ex. Code=read_remote() from main()
? Thank you in advance
bsodmike



Joined: 05 Aug 2006
Posts: 52

View user's profile Send private message Visit poster's website AIM Address MSN Messenger

PostPosted: Sat Oct 14, 2006 6:30 am     Reply with quote

I don't know about others around here, but I find that posts of this sort are best filed under the "Do my homework for me" forum :S
jruibarroso



Joined: 07 Jan 2006
Posts: 64
Location: Braga

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

this is no " do my homework for me " this is pleas
PostPosted: Sat Oct 14, 2006 6:48 am     Reply with quote

this is no " do my homework for me " this is please help me because i don't know as much to do such a code

thank you anyway bsodmike
rberek



Joined: 10 Jan 2005
Posts: 207
Location: Ottawa, Canada

View user's profile Send private message

PostPosted: Sat Oct 14, 2006 7:53 am     Reply with quote

Well, how do you expect to learn enough to write this stuff if you never try to write any yourself?

As bsodmike pointed out, it is unlikely anybody will actually do this work for you. Most posts like this remain unanswered, or receive responses like this. If it is not important enough for you to put effort into it, it won't be important enough for anybody else either.

Make an honest attempt to make the changes to the code that you want, test the code, and then ask for help with specific issues. That what the forum is for.

I'm not trying to be mean, just trying to tell you why your last two posts have received little attention.
jruibarroso



Joined: 07 Jan 2006
Posts: 64
Location: Braga

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

for those who have dificulties like me , here's an example
PostPosted: Sat Oct 14, 2006 2:56 pm     Reply with quote

for those who have dificulties like me , here's an good piece of code

http://www.loginway.com/rc5_decoder.htm

for those who have knowledgement and not want to share , keep it that way..
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