Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

Help me solve this RC5 C source code error

Status
Not open for further replies.

z543g

Junior Member level 1
Joined
Jan 2, 2002
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
222
rc5_send

/** IR_LED TEST for 89c2051 **/

#define IR_LED P1.0

void delay_us(int tt)
{
while(tt--);
}

void delay_ms(int tt)
{
while(tt>0)
{
delay_us(160);
delay_us(160);
tt--;
}
}

void rc5_send_pulses(void)
{
unsigned char i;

i = 32;

while(i--)
{
IR_LED = 0;
delay_us(7);
IR_LED = 1;
delay_us(19);
}
}

void rc5_send_0(void)
{
rc5_send_pulses();
delay_us(889);
}

void rc5_send_1(void)
{
delay_us(889);
rc5_send_pulses();
}

void rc5_send(char address,char command)
{
unsigned int rc5_code;
unsigned char i;

rc5_code = 0x07;
rc5_code <<= 5;
rc5_code |= (address & 0x1f);
rc5_code <<= 6;
rc5_code |= (command & 0x3f);
rc5_code <<= 2;

i = 14;
while(i--) {
if(rc5_code & 0x8000)
rc5_send_1();
else
rc5_send_0();

rc5_code <<= 1;
}
}

void main(void)
{
while(1)
{
rc5_send(5,53);
delay_ms(114);
}
}


---------------------------------------------------------------------------
/** RC5_RECEIVE for 89c2051 **/

typedef unsigned char BYTE;
typedef unsigned int WORD;

#define RC5_IN P1.0

void delay_us(int tt)
{
while(tt--);
}

void delay_ms(int tt)
{
while(tt>0)
{
delay_us(160);
delay_us(160);
tt--;
}
}

BYTE read_SBUF(void)
{
while(RI == 0) {}
RI = 0;
return SBUF;
}

void write_SBUF(BYTE ch)
{
while(TI == 0) {}
TI = 0;
SBUF = ch;
}

void scu_str(char s[])
{
BYTE i;

i=0;

while(s != '\0')
{
write_SBUF(s[i++]);
}
}

void scu_init(void)
{
SCON = 0x52;
TMOD = TMOD & 0x0f;
TMOD = TMOD | 0x20;
TH1 = 0xfd;
TR1 = 1;
}

int rc5_receive(void)
{
int rc5_code;
unsigned char i;
unsigned char q;

rc5_code = 1;

while(RC5_IN) continue;

delay_us(444);

if(RC5_IN) return RC5_ERR;

i = 13;

while(i--)
{
q = 0;
rc5_code <<= 1;
delay_us(889);

if(RC5_IN) q= 2;
delay_us(889);

if(RC5_IN) q++;

switch(q)
{
case 1: rc5_code |= 0; break;
case 2: rc5_code |= 1; break;
defualt: return RC5_ERR;
}
}
return rc5_code & 0x07ff;
}

void main(void)
{
unsigned int i;

scu_init()

while(1)
{
i = rc5_receive();
printf("%d %d\n\r",i>>6,i & 0x003f);
}
}

answer:

16384 63
0 0
16384 63
16384 63 <-- i do not know about rc5 code.


please who :( . error rc5 code source?

:( :( help me... help me... :( :(
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top