Here is my code: maybe it is a problem in the code.
I am attempting to code for a universal remote programmed to Sony TV setting.
#include <18F2550.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOLVP //
#FUSES NOPUT
#use delay(clock=4000000) //serial works with #use delay(clock=20000000)
#define RS232_XMIT PIN_C6 //RS232 serial transmit
#define RS232_RCV PIN_C7 //RS232 serial receive
#use rs232(baud=9600,xmit=RS232_XMIT,rcv=RS232_RCV,parity=N,bits=8,stream=COMP)
int counter,i,com,adr;
int16 buffer;
int16 cnt = 0;
#int_ext
void ext_isr(){
output_bit(PIN_C2, 1);
counter=0; //reset counter and buffer
buffer=0;
disable_interrupts(int_ext); //disable interrupts
while(!input(pin_b0)){ //wait for high level
delay_us(15);
++counter; } //time how long has been low
fprintf(COMP,"counter:%u\r\n",counter);
if(counter>=15&&counter<=30){ //if from about 800 to 1000 us
//do routines
delay_us(200);
for(i=0;i<13;i++){ //13 following bits
if(input(pin_b0)){ //if the input high
bit_set(buffer,0); //set the LSB and shift left
buffer<<=1;}
else //otherwise just shift
buffer<<=1;
delay_us(1740); //wait for naxt bit
}
buffer>>=1; //shift 1 right because of last reading
com=buffer&0b00111111; //command is 6-bit long; ignore the rest
buffer>>=6; //shift 6 right
adr=buffer&0b00011111; //address is 5-bit long; ignore the rest
//display on an LCD
fprintf(COMP,"Address:%u Command:%u\r\n",adr,com); //send bytes to the rs232
delay_ms(150);
} //wait
//return(0); //return to main
}
main(){
delay_ms(100);
//output_bit(PIN_C2, 1);
fprintf(COMP,"on... \n\n");
while(1){
delay_ms(100);
ext_int_edge(H_TO_L);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
cnt = cnt + 1;
//fprintf(COMP,"cnt:%lu",cnt);
output_bit(PIN_C2, 0);
delay_ms(50);
}
}
Thanks again...
Also I did change and place a 4MHz clock on it and it works now on serial, only the timing is off and i dont get consistent address and command. Also I have to hold the buttons down for a LONG time and sometimes then it doesnt even work...