|
|
View previous topic :: View next topic |
Author |
Message |
ymoona
Joined: 20 Mar 2005 Posts: 32 Location: Heiloo, the Netherlands
|
infrared RC5 problem |
Posted: Mon Jun 05, 2006 10:52 am |
|
|
Hi
Im using an tsop 1736 to recieve rc5 codes. The out is connected to RB0 (int). im using an 18f2550 on an 20mhz xtal (internal freq is 48mhz)
the code I use I found on
http://www.ccsinfo.com/forum/viewtopic.php?t=4215&highlight=rc5+sony
and actualy it is working bit...
the only problem is that I have to push a button a few times (5 times or more) and then my USB is not working any more,
does anyone have working RC5 recieve and decode software wich is fully interupt driver? _________________ checkout my site: www.ymoona.com/wiki |
|
|
Ringo42
Joined: 07 May 2004 Posts: 263
|
|
Posted: Mon Jun 05, 2006 1:35 pm |
|
|
Does this code really work? It looks like it is missing something. For example there is a #include with nothing following it, and I don;t see a #use232 type statement anywhere. Does anyone have to full code for this, it looks like fun to play with.
Ringo _________________ Ringo Davis |
|
|
ymoona
Joined: 20 Mar 2005 Posts: 32 Location: Heiloo, the Netherlands
|
|
Posted: Mon Jun 05, 2006 2:24 pm |
|
|
Ringo42 wrote: | Does this code really work? It looks like it is missing something. For example there is a #include with nothing following it, and I don;t see a #use232 type statement anywhere. Does anyone have to full code for this, it looks like fun to play with.
Ringo |
im not verry patient so I wrote some code that does decode rc5 codes
this one workt much better, but only it does not read the adress of the remote, ik shoult but it doesnot work. my code so far.
Code: |
#include <18F2550.h>
#fuses NOMCLR,HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
//#fuses NOMCLR,HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL1,CPUDIV1,VREGEN
#use delay(clock=48000000)
//#use delay(clock=20000000)
#define ADC = 8
/////////////////////////////////////////////////////////////////////////////
//
// CCS Library dynamic defines. For dynamic configuration of the CCS Library
// for your application several defines need to be made. See the comments
// at usb.h for more information
//
/////////////////////////////////////////////////////////////////////////////
#define USB_HID_DEVICE FALSE //deshabilitamos el uso de las directivas HID
#define USB_EP1_TX_ENABLE USB_ENABLE_BULK //turn on EP1(EndPoint1) for IN bulk/interrupt transfers
#define USB_EP1_RX_ENABLE USB_ENABLE_BULK //turn on EP1(EndPoint1) for OUT bulk/interrupt transfers
#define USB_EP1_TX_SIZE 1 //size to allocate for the tx endpoint 1 buffer
#define USB_EP1_RX_SIZE 3 //size to allocate for the rx endpoint 1 buffer
#include <pic18_usb.h> //Microchip PIC18Fxx5x Hardware layer for CCS's PIC USB driver
#include <Z:\Hobby\PC remote en LCD\software\firmware\USB_descriptor.h>
#include <usb.c> //handles usb setup tokens and get descriptor reports
#include <Z:\Hobby\PC remote en LCD\software\firmware\flex_lcd420.c>
#define IR_SENSOR PIN_B0
#define IR (!input(IR_SENSOR))
/////////////////////////////////////////////////////////////////////////////
//
// funtion prototypes
//
/////////////////////////////////////////////////////////////////////////////
// hardware pin defines
#define modo recive[0]
#define param1 recive[1]
#define param2 recive[2]
#define data send[0]
int8 pwm1=0; // LCD backlite
int8 pwm2=0; // contrast
int8 knipper=0;
int8 recive[3]; //declaramos variables
//int8 send[1];
int8 send[1];
int1 irReady = false;
int8 irStart = 0;
int8 irCodeAdress =0;
int8 irCodeCommand = 0;
int i=0;
int32 iraantal= 0;
//externe interrupt door tsop
#int_ext
interrupt(){
// based om http://www.xs4all.nl/~sbp/knowledge/ir/rc5.htm
// zet de interrupts uit
disable_interrupts(int_ext);
irStart = 0;
irCodeAdress =0;
irCodeCommand = 0;
// lees het eerste bit
delay_us(480);
if(IR){
irStart += 1;
}
irStart <<=1;
// lees het twee bit
delay_us(1778);
if(IR){
irStart += 1;
}
irStart <<=1;
// lees het derde bit
delay_us(1778);
if(IR){
irStart += 1;
}
//niet meer schuifen
//irStart <<=1;
// lees het vierde bit
delay_us(1778);
if(IR){
irCodeAdress += 1;
}
irCodeAdress <<=1;
// lees het vijfde bit
delay_us(1778);
if(IR){
irCodeAdress += 1;
}
irCodeAdress <<=1;
// lees het zesde bit
delay_us(1778);
if(IR){
irCodeAdress += 1;
}
irCodeAdress <<=1;
// lees het zevende bit
delay_us(1778);
if(IR){
irCodeAdress += 1;
}
irCodeAdress <<=1;
// lees het achtste bit
delay_us(1778);
if(IR){
irCodeAdress += 1;
}
// irCodeAdress <<=1;
// lees het negende bit
delay_us(1778);
if(IR){
irCodeCommand += 1;
}
irCodeCommand <<=1;
// lees het tiende bit
delay_us(1778);
if(IR){
irCodeCommand += 1;
}
irCodeCommand <<=1;
// lees het elfde bit
delay_us(1778);
if(IR){
irCodeCommand += 1;
}
irCodeCommand <<=1;
// lees het twaalfde bit
delay_us(1778);
if(IR){
irCodeCommand += 1;
}
irCodeCommand <<=1;
// lees het dertiende bit
delay_us(1778);
if(IR){
irCodeCommand += 1;
}
irCodeCommand <<=1;
// lees het veertiende bit
delay_us(1778);
if(IR){
irCodeCommand += 1;
}
//irCodeCommand <<=1;
// klaar
irReady = true;
}
void main(void) {
setup_adc_ports(AN0_TO_AN1|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_4, 127, 1);// PWM timer
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_low_volt_detect(FALSE);
setup_oscillator(False);
enable_interrupts(int_ext);
ext_int_edge(H_TO_L); //falling edge
enable_interrupts(global); //enable interrupts
setup_ccp1(CCP_PWM); // zet beide Compare units op PWM
setup_ccp2(CCP_PWM);
set_pwm1_duty(100);// backlite
set_pwm2_duty(0); // contrast
lcd_init();
delay_ms(10);
lcd_putc("\f");
lcd_putc(" USB remote and LCD \n");
lcd_putc(" made by \n");
lcd_putc(" Hans de Groot \n");
lcd_putc("Versie 0.1 04/06/06 \n");
usb_init(); //init USB
usb_task(); //hoort ook bij de init
usb_wait_for_enumeration(); //wacht op herkenning door de host PC
while (TRUE)
{
if(irReady){
irReady = false;
printf(lcd_putc,"\fstart:%u \nadress:%u\ncommand:%u \nir:%Lu",irStart, irCodeAdress, irCodeCommand, iraantal);
iraantal++;
enable_interrupts(int_ext);
}
if(usb_enumerated()) //zolang de USB is geconfigureert
{
if (usb_kbhit(1)) //if endpoint of exit contains data of host
{
usb_get_packet(1, recive, 3); //cojemos the package of size 3bytes of the EP1 and we stored in receives
// welke modus is gestuurt?
if (modo == 0) {// PWM moet aangestuurt worden
if (param1 == 1) {
set_pwm1_duty(param2);
}
if (param1 == 2) {
set_pwm2_duty(param2);
}
}
if (modo == 1 || modo == 2 || modo == 3 || modo == 4){ // lcd
if(param1 <= 20){
lcd_gotoxy(param1,modo);
lcd_putc((char)param2);
}
}
}
}
}
}
|
_________________ checkout my site: www.ymoona.com/wiki |
|
|
|
|
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
|