I have 2 schematics. First is pic16f877 with pushbutton and rf transmitter, and other shematic is pic16f877 with LED and rf receiver.
my code for transmitter:
Code:
void main()
{
TRISB.F0 = 0xFF;
PORTB.F0 = 0;
UART1_Init(2400); // Initialize UART module at 9600bps
Delay_ms(100); // Wait for UART module to stabilize
while (1)
{ // Endless loop
UART1_Write(PORTB); // and send data via UART
Delay_ms(500);
}
}
code for receiver:
Code:
void main()
{
TRISB = 0;
PORTB = 0;
UART1_Init(2400); // Initialize UART module at 9600bps
Delay_ms(100); // Wait for UART module to stabilize
while (1)
{ // Endless loop
if (UART1_Data_Ready())
{ // If data is received,
PORTB = UART1_Read(); // read the received data,
}
}
}
I have those two circuits connected in reality, but this code didn't work. It should transmit signal when I press button which connected to portB pin 0 and LED on receiver portB pin 0 should be on.
maybe I should encode manchester code when I receive a signal?
- - - Updated - - -
can anyone rewrite my code with manchester encoding/decoding http://www.mikroe.com/esupport/index.php?_m=knowledgebase&_a=viewarticle&kbarticleid=138 ? I need to see how it looks, because Im having hard time to figure it out by myself...
Encoder will be built into the Transmitter and Decoder will be built into the Receiver. So, you don't have to worry about encoding/decoding the data. Your RF module works at 4800 bps. What is the baudrate you have selected for your MCUs (both transmitter MCU and Receiver MCU)?