max_1974
Newbie level 5
- Joined
- Feb 20, 2009
- Messages
- 10
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,411
hello
help pls with manchester code
I tried to make R F remote control
using p16f84a
the code working fine on Proteus
but when I built the circuit it doesn't
RX Code
TX Code
source code
help pls with manchester code
I tried to make R F remote control
using p16f84a
the code working fine on Proteus
but when I built the circuit it doesn't
RX Code
Code:
// Manchester module connections
sbit MANRXPIN at RB5_bit;
sbit MANRXPIN_Direction at TRISB5_bit;
// End Manchester module connections
// define all leds
sbit led1 at RA0_bit;
sbit led2 at RA1_bit;
sbit led3 at RA2_bit;
sbit led4 at RA3_bit;
sbit led5 at RB0_bit;
sbit led6 at RB1_bit;
sbit led7 at RB2_bit;
sbit led8 at RB3_bit;
sbit led_ok at RB4_bit;
sbit led_ok_dir at trisB4_bit;
#define on 1
#define off 0
const char divce_address=10;
char error, ErrorCount, temp , kk[2], cont=0 , data_recived=0;
void main()
{
trisb=0x32;
led_ok_dir=0;
trisa=0;
porta=0;
portb=0;
ErrorCount = 0;
Man_Receive_Init(); // Initialize Receiver
while (1) { // Wait for the "start" byte
temp = Man_Receive(&error); // Attempt byte receive
if (temp == 0) // "Start" byte, see Transmitter example
break; // We got the starting sequence
if (error) // Exit so we do not loop forever
break;
}
while (1) { // Endless loop
temp = Man_Receive(&error); // Attempt byte receive
if (error) { // If error occured
ErrorCount++; // Update error counter
if (ErrorCount > 20) { // In case of multiple errors
temp = Man_Synchro(); // Try to synchronize again
ErrorCount = 0; // Reset error counter
}
}
if(temp==0)led_ok=1;
if(data_recived==0)
{
switch(cont) {
case 0:if(temp==divce_address)cont=1;
else cont=0;
break;
case 1:if(temp== ~divce_address)cont=2;
else cont=0;
break;
case 2:kk[0]=temp;
cont=3;
break;
case 3:kk[1]=temp;
if(kk[0]== ~kk[1]) data_recived=1;
cont=0;
break;
}
}
if(data_recived==1)
{
data_recived=0;
switch(kk[0])
{
case 1:led1=on;break;
case 11:led1=off;break;
case 2:led2=on;break;
case 21:led2=off;break;
case 3:led3=on;break;
case 31:led3=off;break;
case 4:led4=on;break;
case 41:led4=off;break;
case 5:led5=on;break;
case 51:led5=off;break;
case 6:led6=on;break;
case 61:led6=off;break;
case 7:led7=on;break;
case 71:led7=off;break;
case 8:led8=on;break;
case 81:led8=off;break;
}
kk[0]=0;
}
}
}
TX Code
Code:
// Initialize Transmitter:
sbit MANTXPIN at RB5_bit;
sbit MANTXPIN_Direction at TRISB5_bit;
// Initialize switches
sbit sw1 at RA0_bit;
sbit sw2 at RA1_bit;
sbit sw3 at RA2_bit;
sbit sw4 at RA3_bit;
sbit sw5 at RA4_bit;
sbit sw6 at RB0_bit;
sbit sw7 at RB1_bit;
sbit sw8 at RB2_bit;
sbit sw9 at RB3_bit;
sbit sw10 at RB4_bit;
// End Manchester module connections
char x;
const char device_address=10;
char led_on[10] , code_data[]={device_address, ~device_address,0,0};
void send_data(char data1);
void main()
{
trisB=0xDF;
trisa=255;
for(x=0;x<10;x++)led_on[x]=0;
Man_Send_Init(); // Initialize transmitter
for(x=0;x<100;x++)Man_Send(0);
while (1) {
/////////////// led1 ///////////////////
if(sw1==0 && led_on[0]==0) //led1=on
{
send_data(1);
led_on[0]=1;
delay_ms(250);
}
else if(sw1==0 && led_on[0]==1) //led1=off
{
send_data(11);
led_on[0]=0;
delay_ms(250);
}
/////////////// led2 ///////////////////
if(sw2==0 && led_on[1]==0) //led2=on
{
send_data(2);
led_on[1]=1;
delay_ms(250);
}
else if(sw2==0 && led_on[1]==1) //led2=off
{
send_data(21);
led_on[1]=0;
delay_ms(250);
}
/////////////// led3 ///////////////////
if(sw3==0 && led_on[2]==0) //led1=on
{
send_data(3);
led_on[2]=1;
delay_ms(250);
}
else if(sw3==0 && led_on[2]==1) //led1=off
{
send_data(31);
led_on[2]=0;
delay_ms(250);
}
/////////////// led4 ///////////////////
if(sw4==0 && led_on[3]==0) //led2=on
{
send_data(4);
led_on[3]=1;
delay_ms(250);
}
else if(sw4==0 && led_on[3]==1) //led2=off
{
send_data(41);
led_on[3]=0;
delay_ms(250);
}
/////////////// led5 ///////////////////
if(sw5==0 && led_on[4]==0) //led1=on
{
send_data(5);
led_on[4]=1;
delay_ms(250);
}
else if(sw5==0 && led_on[4]==1) //led1=off
{
send_data(51);
led_on[4]=0;
delay_ms(250);
}
/////////////// led6 ///////////////////
if(sw6==0 && led_on[5]==0) //led2=on
{
send_data(6);
led_on[5]=1;
delay_ms(250);
}
else if(sw6==0 && led_on[5]==1) //led2=off
{
send_data(61);
led_on[5]=0;
delay_ms(250);
}
/////////////// led7 ///////////////////
if(sw7==0 && led_on[6]==0) //led1=on
{
send_data(7);
led_on[6]=1;
delay_ms(250);
}
else if(sw7==0 && led_on[6]==1) //led1=off
{
send_data(71);
led_on[6]=0;
delay_ms(250);
}
/////////////// led8 ///////////////////
if(sw8==0 && led_on[7]==0) //led2=on
{
send_data(8);
led_on[7]=1;
delay_ms(250);
}
else if(sw8==0 && led_on[7]==1) //led2=off
{
send_data(81);
led_on[7]=0;
delay_ms(250);
}
}
}
//********************************************//
void send_data(char data1)
{
code_data[2]=data1;
code_data[3]=~data1;
for(x=0;x<4;x++)
{
Man_Send(code_data[x]);
delay_ms(10);
}
}
source code