johney
Newbie level 4
rf link between 2 pic 16f628 using uart
need help for establishing rf link between two 16f628 using 315 mhz rf tx rx module below is the code i am using but coming across the range issue need help to increase the range of the system to atleast 25-30 meters through the walls Thanks
TX code:
RX code:
CODE IS WORKING PRETTY WELL O HARDWARE BUT RANGE IS THE MAIN ISSUE GETTING RANGE ONLY UPTO 15-20 FEET THROUGH WALLS CROSS THT NOT WORKING KINDLY HELP ME OUT NEED TO COMPLETE IT ASAP.
need help for establishing rf link between two 16f628 using 315 mhz rf tx rx module below is the code i am using but coming across the range issue need help to increase the range of the system to atleast 25-30 meters through the walls Thanks
TX code:
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 char txt[16]; char chk; char dat,character,strt,data,middle,end,invrte; int i=0,ckop=0; unsigned int prcnt=0; void main() { INTCON=0; OPTION_REG = 0X8F; CMCON=7; PORTB=0; PORTA=0; TRISA=0XFF; TRISB = 0XFF; TRISB2_BIT=0; VRCON=0; T1CON=0; T2CON=0; for(i=0;i<16;i++){txt[i]=' ';} UART1_Init(1200); delay_ms(200); // Initialize LCD while(1){ asm sleep asm clrwdt; asm sleep asm clrwdt; TRISB2_BIT=0; TRISA1_BIT=0; RA1_BIT=0; delay_ms(600); strt = 0x0A; middle = 0x0B end =0x0C; prcnt = PORTB; prcnt = (prcnt&0X70); switch(prcnt) { case 0x00: if(RB7_BIT==0) { data = 'A'; } else { data = 'E'; } if (UART1_Tx_Idle() == 1) UART1_Write(0XAA); UART1_Write(0X55); UART1_Write(0XAA); UART1_Write(0X55); UART1_Write(0XAA); UART1_Write(0X55); UART1_Write(0XAA); UART1_Write(0X55); UART1_Write(0XAA); UART1_Write(0X55); UART1_Write(0XAA); UART1_Write(strt); UART1_Write(data); UART1_Write(middle); UART1_Write(end); break; case 0x10: if(RB7_BIT==0) { data = 'B'; } else { data = 'F'; } if (UART1_Tx_Idle() == 1) UART1_Write(0XAA); UART1_Write(0X55); UART1_Write(0XAA); UART1_Write(0X55); UART1_Write(0XAA); UART1_Write(0X55); UART1_Write(0XAA); UART1_Write(0X55); UART1_Write(0XAA); UART1_Write(0X55); UART1_Write(0XAA); UART1_Write(strt); UART1_Write(data); UART1_Write(middle); UART1_Write(end); case 0X30: if(RB7_BIT==0) { sidhad = 'C'; } else { sidhad = 'G'; } if (UART1_Tx_Idle() == 1) UART1_Write(0XAA); UART1_Write(0X55); UART1_Write(0XAA); UART1_Write(0X55); UART1_Write(0XAA); UART1_Write(0X55); UART1_Write(0XAA); UART1_Write(0X55); UART1_Write(0XAA); UART1_Write(0X55); UART1_Write(0XAA); UART1_Write(strt); UART1_Write(data); UART1_Write(middle); UART1_Write(end); break; case 0X70: if(RB7_BIT==0) { sidhad = 'D'; } else { sidhad = 'H'; } if (UART1_Tx_Idle() == 1) UART1_Write(0XAA); UART1_Write(0X55); UART1_Write(0XAA); UART1_Write(0X55); UART1_Write(0XAA); UART1_Write(0X55); UART1_Write(0XAA); UART1_Write(0X55); UART1_Write(0XAA); UART1_Write(0X55); UART1_Write(0XAA); UART1_Write(strt); UART1_Write(data); UART1_Write(middle); UART1_Write(end); break; } asm clrwdt; SPEN_BIT =0; RA1_BIT=0; TRISA=0XFF; TRISB=0XFF; } }
RX code:
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 char txt[16]; char chk,ID; int i=0,ckop=0; unsigned long sig; char data_byte1=0,data_byte2=0,checksum_byte=0,start_byte=0; char started, count; char buffer; void interrupt(){ if (PIR1.RCIF) { buffer = RCREG; //read from rcreg register if(started){ count++; if(count == 1) txt[count] = buffer; if(count == 2) txt[count] = buffer; if(count == 3) txt[count] = buffer; if(count == 4) { txt[4]= buffer; started = 0; //reset started flag if(txt[4]==0X0C){ // simple error checking RA0_BIT=1; delay_ms(10); RA0_BIT=0; sig=0; if(txt[2]=='A') { RB4_BIT=0; RB5_BIT=0; RB6_BIT=0; RB7_BIT=1; } else { if(txt[2]=='E') { RB4_BIT=0; RB5_BIT=0; RB6_BIT=0; RB7_BIT=0; } } if(txt[2]=='B') { RB4_BIT=1; RB5_BIT=0; RB6_BIT=0; RB7_BIT=1; } else{ if(txt[2]=='F') { RB4_BIT=1; RB5_BIT=0; RB6_BIT=0; RB7_BIT=0; } } if(txt[2]=='C') { RB4_BIT=1; RB5_BIT=1; RB6_BIT=0; RB7_BIT=1; } else { if(txt[2]=='G') { RB4_BIT=1; RB5_BIT=1; RB6_BIT=0; RB7_BIT=0; } } if(txt[2]=='D') { RB4_BIT=1; RB5_BIT=1; RB6_BIT=1; RB7_BIT=1; } else { if(txt[2]=='H') { RB4_BIT=1; RB5_BIT=1; RB6_BIT=1; RB7_BIT=0; } } for(i=0;i<6;i++){txt[i]=' ';} buffer=' '; asm clrwdt; } } }else{ if(buffer == 0x0A) { started = 1; //set started flag count = 0; } } } } void main() { INTCON=0; OPTION_REG=0X8F; PORTB=0; PORTA=0; TRISB=0; TRISA=0X00; CMCON=7; VRCON =0; TRISB1_bit=1; T1CON=0; T2CON=0; UART1_Init(1200); delay_ms(200); asm clrwdt; INTCON.RCIF=0; INTCON.PEIE=1; PIE1.RCIE=1; INTCON.GIE=1; asm clrwdt; while(1){ asm clrwdt; RA1_BIT=0; } }
CODE IS WORKING PRETTY WELL O HARDWARE BUT RANGE IS THE MAIN ISSUE GETTING RANGE ONLY UPTO 15-20 FEET THROUGH WALLS CROSS THT NOT WORKING KINDLY HELP ME OUT NEED TO COMPLETE IT ASAP.
Last edited by a moderator: