Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
07/22/02 11:39
Read: times


 
#26113 - RE: Receiving data from External Interru
Hi Shahid,

on the IR-code the data bits are defined by the pulse or pause length. So an external interrupt was not a good way. You need something to measure the pulse length. E.g. use a timer interrupt every 256 cycle (T0 in mode 3) to count the pulse and pause duration.
Following my solution:

<pre>
#pragma cd pl(9999)
#include < reg51.h >

#define uint unsigned int
#define uchar unsigned char

sbit xRC5_IN = P3^2; // IR input low active

#define XTAL 11.0592e6

#define RC5CLOCK (144e3 / 128) // 889usec


#define PULSE1_2 (uchar)(XTAL / 12 / 256 / RC5CLOCK * 1.0 + 1)
#define PULSE2MAX (uchar)(XTAL / 12 / 256 / RC5CLOCK * 2.5 + 1)


bit rc5_bit; // bit value
bit rc5_busy; // receive in progress
bit rc5_done; // receive done

uchar rc5_time; // count bit time
uint rc5_tmp; // shift bits in
uint rc5_data; // store result


void t0_int( void ) interrupt INT_T0

{
if( --rc5_time == 0 ) // count down
rc5_busy = 0; // timeout

if( xRC5_IN == rc5_bit ){ // change detect
rc5_bit = ~rc5_bit; // store new state
if( rc5_busy == 0 ){
if( rc5_bit == 1 ){ // start pulse detect
rc5_busy = 1;
rc5_tmp = 1; // == 0x2000 after 13 shift
}
}else{
if( rc5_time > PULSE1_2 ) // if to short
return; // then continue

rc5_tmp <<= 1; // shift
if( rc5_bit )
rc5_tmp |= 1; // add new bit
if( rc5_tmp & 0x2000 ){ // after shifted 13 times
rc5_data = rc5_tmp;
rc5_busy = 0;
rc5_done = 1;
}
}
rc5_time = PULSE2MAX;
}
}


Peter



List of 9 messages in thread
TopicAuthorDate
Receiving data from External Interrupts            01/01/70 00:00      
RE: Receiving data from External Interrupts            01/01/70 00:00      
RE: Receiving data from External Interrupts            01/01/70 00:00      
RE: Receiving data from External Interrupts            01/01/70 00:00      
RE: Receiving data from External Interrupts            01/01/70 00:00      
RE: Receiving data from External Interrupts            01/01/70 00:00      
RE: Receiving data from External Interrupts            01/01/70 00:00      
RE: Receiving data from External Interrupts            01/01/70 00:00      
RE: Receiving data from External Interru            01/01/70 00:00      

Back to Subject List