Mình vừa làm xong layout cho thí nghiệm USB-RF>>Air>>RF-LCD+LEDs: dùng 18F4550 để mã hóa và giải mã. Post lên để các bác cùng tham gia thảo luận và phát triển. Sau đây là phần phát:
![](http://i387.photobucket.com/albums/oo318/bravesoldier/USB-RF-2-1.jpg)
![](http://i387.photobucket.com/albums/oo318/bravesoldier/USB-RF-2-1.jpg)
![](http://i387.photobucket.com/albums/oo318/bravesoldier/simul-1.jpg)
#include <18f4550.h> #fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,PLL2,CPUDIV1,VREGEN #device ADC=8 #use delay(clock=48000000) void main() { while(true) { output_high(pin_b0); delay_ms(90); output_low(pin_b0); delay_ms(90); } }
#include <18f4550.h> #fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,PLL2,CPUDIV4,VREGEN #use delay(clock=16000000) #define RX pin_b0 #use fast_io(d) #byte LEDx8=0xf8c // latch D void main() { set_tris_d(0x00); while(true) { if (input(RX)==1) LEDx8=0xFF; else LEDx8=0x00; } }
GPIO=0x00; TRIS=0B00001000; OPTION=0x03;
GPIO=0x00; TRIS=0B00001000; OPTION=0x03;
int1 get_data(int8 *buff) { int8 i,j,T0,count; i=16; count=0; setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_8_BIT); // pre scaler = 256 for clock tick = 64us; T_delay=16384us while(--i) // wait preamble { #asm NOP NOP NOP #endasm while(input(RX)); set_timer0(0); #asm NOP NOP NOP #endasm while(!input(RX)); T0=get_timer0(); if (T0==0xFF) return 1; // error if ((T0>=73) && (T0<=83)) // { count++; if ((count>=5) || (i==0)) break; } } if (i==0) return 1; // error setup_timer_0(RTCC_INTERNAL|RTCC_DIV_4); // prescaler = 4 but mode16BIT for clock tick = 256us; T_delay=65536us T0=0; while (!((T0>73) && (T0<83))) // { #asm NOP NOP NOP #endasm while(input(RX)); // wait syn set_timer0(0); #asm NOP NOP NOP #endasm while(!input(RX)); T0=get_timer0(); } while(input(RX)); //wait start bit go low Delay_Us(7355); // for (j=0;j<3;j++) { i=8; buff[j]=0; while(i--) { buff[j]=buff[j]<<1; rx_bit=input(RX); // sampling buff[j]=buff[j] | rx_bit; if (rx_bit==0) while(!input(RX)); else while(input(RX)); Delay_Us(7355); } } if (rx_bit==0) {if (!input(RX)) return 1;} // error (no stop bit found) else {if (!input(RX)) return 1;} // error (no stop bit found) return 0; }
Comment