hobby_85
Junior Member level 2
16f688.h
I bought a RF kit, transmitter and receiver, and the website of a similar product is below. Now, im trying to write code for it, just to make sure it is working.
https://www.sparkfun.com/commerce/product_info.php?products_id=8950
Im using a PIC 16f688 and if the LED lights up to a correct pattern, i know the code is working. However, it is not.
Here is the TX code:
#include <16F688.h>
//-------------------------------------------------------------------------------
#define WireTX PIN_C4 //
#define WireRX PIN_C5
//-------------------------------------------------------------------------------
#fuses XT, NOWDT, NOPROTECT,NOBROWNOUT, PUT
#use delay (clock = 4000000)
#use rs232(baud=2400,xmit=WireTX , rcv=WireRX , STREAM=COM_A )
void main(){
for(;
{
if(input(PIN_C2)==0) //if button pressed
{
output_high(PIN_A1); //output high Led
delay_ms(20); //delay 20ms
fputc('T',COM_A); //send data
delay_ms(20);
delay_ms(1000); //delay some ms
output_low(PIN_A1); // output low led
}
output_high(PIN_A1); // if button not pressed then just on off led on pin D1
delay_ms(50);
output_low(PIN_A1);
delay_ms(50);
}
}
So if the button is pressed, the letter T is meant to be sent across, and the LED should come on, then off then on a longer time.
Here is the corresponding Receiver code:
#include <16F688.h>
#fuses XT, NOWDT, NOPROTECT,BROWNOUT, PUT
#use delay (clock = 4000000)
//------------------------------
#define WireTX PIN_C4
#define WireRX PIN_C5
//------------------------------
#use rs232(baud=2400, xmit=WireTX, rcv=WireRX, STREAM=COM_A)
unsigned int8 data;
int1 flag=0;
#int_rda
void rd_isr(void){
disable_interrupts(INT_RDA); // Disable Serial Recieve Interrupt
disable_interrupts(GLOBAL); // Disable Global Interrupts
data= fgetc(COM_A);
if(data=='T'){
flag=1;
}
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);
}
void main(){
enable_interrupts(global);
enable_interrupts(int_rda);
for(;
{
if(flag==1){
output_high(PIN_A1);
delay_ms(1000);
output_low(PIN_A1);
flag=0;
}
output_high(PIN_A1);
delay_ms(50);
output_low(PIN_A1);
delay_ms(50);
}
}
So if the message is received, the LED should come on/off in 1 sec intervals. If not, it should just flash on and off.
I have an oscilloscope, so i can look at the signals being transmitted. Here are the problems:
1) The switch - When i checked the RF signal being sent when the button was pushed, i saw a step on the oscilloscope. The message would be sent forever and the led would light as coded.
So i know something was sent across. However, after a couple of seconds, even when the switch was off, the message was sent automatically.
I connected 220k resister from the output of the MC to the LED, and then to GND.
2) The receiver - The led turns on/off, as though it didnt receive anything. However, when i connected the osc to the receiver/RX of the MC, i can see a jump in the signal, matching the signal sent by the tx. So why isnt the led lighting as expected?
Any ideas?
Thanks
I bought a RF kit, transmitter and receiver, and the website of a similar product is below. Now, im trying to write code for it, just to make sure it is working.
https://www.sparkfun.com/commerce/product_info.php?products_id=8950
Im using a PIC 16f688 and if the LED lights up to a correct pattern, i know the code is working. However, it is not.
Here is the TX code:
#include <16F688.h>
//-------------------------------------------------------------------------------
#define WireTX PIN_C4 //
#define WireRX PIN_C5
//-------------------------------------------------------------------------------
#fuses XT, NOWDT, NOPROTECT,NOBROWNOUT, PUT
#use delay (clock = 4000000)
#use rs232(baud=2400,xmit=WireTX , rcv=WireRX , STREAM=COM_A )
void main(){
for(;
if(input(PIN_C2)==0) //if button pressed
{
output_high(PIN_A1); //output high Led
delay_ms(20); //delay 20ms
fputc('T',COM_A); //send data
delay_ms(20);
delay_ms(1000); //delay some ms
output_low(PIN_A1); // output low led
}
output_high(PIN_A1); // if button not pressed then just on off led on pin D1
delay_ms(50);
output_low(PIN_A1);
delay_ms(50);
}
}
So if the button is pressed, the letter T is meant to be sent across, and the LED should come on, then off then on a longer time.
Here is the corresponding Receiver code:
#include <16F688.h>
#fuses XT, NOWDT, NOPROTECT,BROWNOUT, PUT
#use delay (clock = 4000000)
//------------------------------
#define WireTX PIN_C4
#define WireRX PIN_C5
//------------------------------
#use rs232(baud=2400, xmit=WireTX, rcv=WireRX, STREAM=COM_A)
unsigned int8 data;
int1 flag=0;
#int_rda
void rd_isr(void){
disable_interrupts(INT_RDA); // Disable Serial Recieve Interrupt
disable_interrupts(GLOBAL); // Disable Global Interrupts
data= fgetc(COM_A);
if(data=='T'){
flag=1;
}
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);
}
void main(){
enable_interrupts(global);
enable_interrupts(int_rda);
for(;
if(flag==1){
output_high(PIN_A1);
delay_ms(1000);
output_low(PIN_A1);
flag=0;
}
output_high(PIN_A1);
delay_ms(50);
output_low(PIN_A1);
delay_ms(50);
}
}
So if the message is received, the LED should come on/off in 1 sec intervals. If not, it should just flash on and off.
I have an oscilloscope, so i can look at the signals being transmitted. Here are the problems:
1) The switch - When i checked the RF signal being sent when the button was pushed, i saw a step on the oscilloscope. The message would be sent forever and the led would light as coded.
So i know something was sent across. However, after a couple of seconds, even when the switch was off, the message was sent automatically.
I connected 220k resister from the output of the MC to the LED, and then to GND.
2) The receiver - The led turns on/off, as though it didnt receive anything. However, when i connected the osc to the receiver/RX of the MC, i can see a jump in the signal, matching the signal sent by the tx. So why isnt the led lighting as expected?
Any ideas?
Thanks