pophip897
Newbie level 2
- Joined
- Apr 25, 2013
- Messages
- 2
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,295
Need Help with RF remote coding -/\- pls
Hello!
I have some trouble with my transmitter & receiver code via UART.
I want to check start byte first then receive the data for my real function.
I'm using PIC16F628A for Both transmitter & receiver(4 MHz clock).
Transmitter Module : TWS-BS3 (433.92 MHz)
Receiver Module : RWS-374 (433.92 MHz)
(Coding with Mikroc)
Thanks
Thanapat.
Origin: 27/5/2013
Updated 1: 28/5/2013:
Change baud rate from 300.5 to 1202
Transmitter Code:
Receiver Code:
Hello!
I have some trouble with my transmitter & receiver code via UART.
I want to check start byte first then receive the data for my real function.
I'm using PIC16F628A for Both transmitter & receiver(4 MHz clock).
Transmitter Module : TWS-BS3 (433.92 MHz)
Receiver Module : RWS-374 (433.92 MHz)
(Coding with Mikroc)
Thanks
Thanapat.
Origin: 27/5/2013
Updated 1: 28/5/2013:
Change baud rate from 300.5 to 1202
Transmitter Code:
Code:
void main() {
TRISA = 0x03;
TRISB = 0xF9;
SPBRG = 51;
TXSTA.TXEN = 1;
RCSTA.SPEN = 1;
Delay_ms(500); // Wait for setting
USART_Write (172) ; // Send data for receiver to check [start byte]
Delay_ms(15); [B][COLOR="#FF0000"]// *** Not sure that I need to have this one ?[/COLOR][/B]
USART_Write(0); // Send command [Clear port]
while (1)
{
int tx1 = 0;
int tx2 = 0;
int tx3 = 0;
int tx4 = 0;
int trans = 0;
while ((PORTB.F6==1)&&(PORTB.F7==0)) // Choose Function (my remote have 3 function)
{
if(PORTB.F0==1)
{
USART_Write (172) ; // sent start byte
Delay_ms(15); [B][COLOR="#FF0000"]***[/COLOR][/B]
USART_Write(65) ; // send command
Delay_ms(200);
}
if(PORTB.F3==1)
{
USART_Write (172) ; // sent start byte
Delay_ms(15); [B][COLOR="#FF0000"]***[/COLOR][/B]
USART_Write(72) ; // send command
Delay_ms(200);
}
if(PORTB.F4==1)
{
USART_Write (172) ; // sent start byte
Delay_ms(15); [B][COLOR="#FF0000"]***[/COLOR][/B]
USART_Write(80) ; // send command
Delay_ms(200);
}
if(PORTB.F5==1)
{
USART_Write (172) ; // sent start byte
Delay_ms(15); [B][COLOR="#FF0000"]***[/COLOR][/B]
USART_Write(96) ; // send command
Delay_ms(200);
}
if(PORTA.F0==1)
{
USART_Write (172) ; // sent start byte
Delay_ms(15); [B][COLOR="#FF0000"]***[/COLOR][/B]
USART_Write(0) ; // send command [Clear port]
Delay_ms(200);
}
}
while ((PORTB.F6==0)&&(PORTB.F7==1)) // Choose Function
{
if(PORTB.F0==1)
{
USART_Write (172) ; // sent start byte
Delay_ms(15); [B][COLOR="#FF0000"]***[/COLOR][/B]
USART_Write(129) ; // send command
Delay_ms(200);
}
if(PORTB.F3==1)
{
USART_Write (172) ; // sent start byte
Delay_ms(15); [B][COLOR="#FF0000"]***[/COLOR][/B]
USART_Write(136) ; // send command
Delay_ms(200);
}
if(PORTB.F4==1)
{
USART_Write (172) ; // sent start byte
Delay_ms(15); [B][COLOR="#FF0000"]***[/COLOR][/B]
USART_Write(144) ; // send command
Delay_ms(200);
}
if(PORTB.F5==1)
{
USART_Write (172) ; // sent start byte
Delay_ms(15); [B][COLOR="#FF0000"]***[/COLOR][/B]
USART_Write(160) ; // send command
Delay_ms(200);
}
if(PORTA.F0==1)
{
USART_Write (172) ; // sent start byte
Delay_ms(15); [B][COLOR="#FF0000"]***[/COLOR][/B]
USART_Write(0) ; // send command [Clear port]
Delay_ms(200);
}
}
while ((PORTB.F6==1)&&(PORTB.F7==1)) // Choose Function
{
if(PORTB.F0==1)
{
tx1 = 1;
Delay_ms(50);
}
if(PORTB.F3==1)
{
tx2 = 8;
Delay_ms(50);
}
if(PORTB.F4==1)
{
tx3 = 16;
Delay_ms(50);
}
if(PORTB.F5==1)
{
tx4 = 32;
Delay_ms(50);
}
if(PORTA.F1==1)
{
trans = tx1+tx2+tx3+tx4;
USART_Write (172) ; // sent start byte
Delay_ms(15); [B][COLOR="#FF0000"]***[/COLOR][/B]
USART_Write(trans); // send command
Delay_ms(200);
}
if(PORTA.F0==1)
{
tx1 = 0;
tx2 = 0;
tx3 = 0;
tx4 = 0;
trans = 0;
USART_Write (172) ; // sent start byte
Delay_ms(15); [B][COLOR="#FF0000"]***[/COLOR][/B]
USART_Write(0); // send command [Clear port]
Delay_ms(200);
}
}
}
}
Receiver Code:
Code:
void main()
{
int receive = 0;
TRISB = 0xC6;
SPBRG = 51;
RCSTA.SPEN = 1;
RCSTA.CREN = 1;
Delay_ms(500);
PORTB = 0;
while (1)
{
if (Usart_Data_Ready() == 1)
{
receive = Usart_Read();
if (receive==172) // Check start byte
{
Delay_ms(15); [B][COLOR="#FF0000"]*** I don't know why but it need to match the intput delay[/COLOR][/B]
if (Usart_Data_Ready() == 1) {
receive = Usart_Read(); // receive command
if (receive<128)
{
PORTB = receive; // main function
Delay_ms(200);
}
if (receive==129)
{
PORTB.F0=~PORTB.F0; // main function
Delay_ms(200);
}
if (receive==136)
{
PORTB.F3=~PORTB.F3; // main function
Delay_ms(200);
}
if (receive==144)
{
PORTB.F4=~PORTB.F4; // main function
Delay_ms(200);
}
if (receive==160)
{
PORTB.F5=~PORTB.F5; // main function
Delay_ms(200);
}
}
}
}
}
}
Last edited: