![]() |
|
Tài trợ cho PIC Vietnam |
Thực hành Bắt đầu làm một robot như thế nào? Mẹo vặt? Kỹ thuật? Công nghệ?... Hãy bắt tay vào việc... |
|
Ðiều Chỉnh | Xếp Bài |
![]() |
#1 |
Nhập môn đệ tử
Tham gia ngày: Jun 2009
Bài gửi: 4
: |
cặp thu phát FS1000A_PCR1A 315mhz
bác nào co kinh nghiệm về 2 con này thì giúp em với.em truyền nhận tín hiệu giữa 2 con này băng pic 16f887.nhưng mạch chỉ chạy đúng khi em cấp điện vào còn sau đó thì chỉ nhân dc toàn tín hiệu nhiễu.em nghĩ code đúng vì nó nhận đúng khi cấp điện.nhưng ko hiểu sao chỉ đúng trong lần phát đầu tiên.ko biết 2 con này nên xài anten như thế nào.em chỉ gắn sợi dây điện làm anten cho nó
đây là code viết trong mikroc Trans: // Manchester module connections sbit MANRXPIN at RC0_bit; sbit MANRXPIN_Direction at TRISC0_bit; sbit MANTXPIN at RC1_bit; sbit MANTXPIN_Direction at TRISC1_bit; // End Manchester module connections char index, character; char s1[] = "This is"; char noise = 0; void main() { ANSEL = 0; // Configure AN pins as digital I/O ANSELH = 0; C1ON_bit = 0; // Disable comparators C2ON_bit = 0; Man_Send_Init(); // Initialize transmitter while (1) { // Endless loop Man_Send(0x0B); // Send "start" byte Delay_ms(500); // Wait for a while character = s1[0]; // Take first char from string index = 0; // Initialize index variable while (character) { // String ends with zero Man_Send(character); Delay_ms(90); // Wait for a while index++; // Increment index variable character = s1[index]; // Take next char from string } Man_Send(0x0E); // Send "end" byte Delay_ms(2000); } } code Receiver: // Manchester module connections Start sbit MANRXPIN at RC0_bit; sbit MANRXPIN_Direction at TRISC0_bit; sbit MANTXPIN at RC1_bit; sbit MANTXPIN_Direction at TRISC1_bit; // End Manchester module connections End unsigned char error = 0, ErrorCount = 0, temp = 0; void main() { ANSEL = 0; // Configure AN pins as digital I/O ANSELH = 0; C1ON_bit = 0; // Disable comparators C2ON_bit = 0; UART1_Init(9600); Man_Receive_Init(); // Initialize Receiver do{ // Rx Routine forever loop GET_BYTE: temp = Man_Receive(&error); // Attempt byte receive if (error) goto ERROR_BYTE; // if comm's error goto error handler goto START_BYTE; // if good byte Received goto start handler ERROR_BYTE: UART1_Write_Text("ErrorByte count = "); // Write error and count to UART ErrorCount++; // Update error counter UART1_Write(ErrorCount+48); UART1_Write_Text("\n\r"); if(ErrorCount > 5) goto RE_SYNC; goto GET_BYTE; START_BYTE: if (temp == 0x0B){ // "Start" byte value expected is 0xC3 goto DISPLAY_BYTE; // goto the Display routine } goto NOISE_BYTE; // Valid data byte found is not a start byte // go to noise reporting loop DISPLAY_BYTE: if(temp == 0x0E) goto STOP_BYTE; // Valid Stop Byte found Exit UART1_Write_Text("Valid Data Found\n\r"); // Send Activity to UART while (1){ // loop to collect all valid data temp = Man_Receive(&error); // Attempt byte receive if (error) goto ERROR_BYTE; // if comm's error goto error handler if (temp == 0x0E)break; // Stop condition found Exit while loop UART1_Write(temp); // write received byte on UART } UART1_Write_Text("\n\r"); // new line + Carriage Return goto STOP_BYTE; // Exit UART write loop NOISE_BYTE: UART1_Write_Text("Synchronized But Data Found is Noise = "); // Send Activity to UART UART1_Write(temp); UART1_Write_Text("\n\r"); goto GET_BYTE; // Exit noise detect loop RE_SYNC: UART1_Write_Text("Synchronizing\n\r"); // Display Activity on 2nd Row delay_ms(50); temp = Man_Synchro(); // Try to synchronize again ErrorCount = 0; // Reset error counter if (temp == 0xFF) goto RE_SYNC; // Sync failed try again goto GET_BYTE; // Sync complete start over again STOP_BYTE: if (temp == 0x0E){ // If "End" byte was received UART1_Write_Text("Valid Stop Found\n\r"); // Send Activity to UART delay_ms(100); } goto GET_BYTE; // start over again }while(1); // Rx Routine } // main |
![]() |
![]() |
|
|