سلام دوستان :smile: توی یه تاپیکی من سوالمو مطرح کردم کسی پاسخ نداد واسه همین تاپیک جدید زدم... بیشتریا هم با بسکام کار میکردن...
من یه hmt و hmr 915mhz دارم که میخوام راه اندازیش کنم . یه ال سیدی به پورت b اتمگا 8 زدم و کاراکتر 1 رو مدام میفرستم .ولی چیزای عجیب غریبی روی ال سیدی نشون میده....


میشه کمکم کنین؟
اگه پایه های rx tx میکرو رو به هم وصل کنم کاراکتر ok رو بدون وقفه نشون میده که نشون دهنده این هس که ارسال و دریافت داره به درستی انجام میشه... ولی وقتی به ماژول هام وصل میکنم ممکنه گاهی 3 ،4 تا ok روی ال سیدی نشون بده بقیش معلوم نیس چیه از شکلک وعدد گرفته تا حروف چینی میاد 
میشه بگین چیکار کنم؟
از دوستانی که راهنمایی کنن پیشاپیش متشکرم
من یه hmt و hmr 915mhz دارم که میخوام راه اندازیش کنم . یه ال سیدی به پورت b اتمگا 8 زدم و کاراکتر 1 رو مدام میفرستم .ولی چیزای عجیب غریبی روی ال سیدی نشون میده....


میشه کمکم کنین؟
کد:
#include <mega8.h> #include <delay.h> #asm .equ __lcd_port = 0x18; PORTB 0x12 D #endasm #include <lcd.h> #include <stdlib.h> #include <stdio.h> #define FRAMING_ERROR (1<<FE) #define PARITY_ERROR (1<<PE) #define DATA_OVERRUN (1<<DOR) #define DATA_REGISTER_EMPTY (1<<UDRE) #define RX_COMPLETE (1<<RXC) // USART Receiver buffer #define RX_BUFFER_SIZE 64 char rx_buffer[RX_BUFFER_SIZE]; #if RX_BUFFER_SIZE<256 unsigned char rx_wr_index,rx_rd_index,rx_counter; #else unsigned int rx_wr_index,rx_rd_index,rx_counter; #endif // This flag is set on USART Receiver buffer overflow bit rx_buffer_overflow; //void USART_Transmit(unsigned char); //void USART_Receive(); // USART Receiver interrupt service routine interrupt [USART_RXC] void usart_rx_isr(void) { char status,data; status=UCSRA; data=UDR; if ((status & (FRAMING_ERROR | PARITY_ERROR |DATA_OVERRUN))==0) { rx_buffer[rx_wr_index]=data; if (++rx_wr_index == RX_BUFFER_SIZE) rx_wr_index=0; if (++rx_counter == RX_BUFFER_SIZE) { rx_counter=0; rx_buffer_overflow=1; }; }; } #ifndef _DEBUG_TERMINAL_IO_ // Get a character from the USART Receiver buffer #define _ALTERNATE_GETCHAR_ #pragma used+ char getchar(void) { char data; while (rx_counter==0); data=rx_buffer[rx_rd_index]; if (++rx_rd_index == RX_BUFFER_SIZE) rx_rd_index=0; #asm("cli") --rx_counter; #asm("sei") return data; } #pragma used- #endif // USART Transmitter buffer #define TX_BUFFER_SIZE 32//64 char tx_buffer[TX_BUFFER_SIZE]; #if TX_BUFFER_SIZE<256 unsigned char tx_wr_index,tx_rd_index,tx_counter; #else unsigned int tx_wr_index,tx_rd_index,tx_counter; #endif // USART Transmitter interrupt service routine interrupt [USART_TXC] void usart_tx_isr(void) { if (tx_counter) { --tx_counter; UDR=tx_buffer[tx_rd_index]; if (++tx_rd_index == TX_BUFFER_SIZE) tx_rd_index=0; }; } #ifndef _DEBUG_TERMINAL_IO_ // Write a character to the USART Transmitter buffer #define _ALTERNATE_PUTCHAR_ #pragma used+ void putchar(char c) { while (tx_counter == TX_BUFFER_SIZE); #asm("cli") if (tx_counter || ((UCSRA & DATA_REGISTER_EMPTY)==0)) { tx_buffer[tx_wr_index]=c; if (++tx_wr_index == TX_BUFFER_SIZE) tx_wr_index=0; ++tx_counter; } else { UDR=c; } #asm("sei") } #pragma used- #endif /***************************************/ void main() { char str; UCSRA=0x00; UCSRB=0xD8; UCSRC=0x86; UBRRH=0x00; UBRRL=0x67; #asm("sei") lcd_init(16); lcd_gotoxy(0,0); lcd_putsf("start.."); delay_ms(1000); lcd_clear(); while(1) { printf("1"); while(rx_counter>0) { str=getchar(); if(str=='1') lcd_putsf(" ok "); else lcd_putchar(str); delay_ms(100); } } }

میشه بگین چیکار کنم؟
از دوستانی که راهنمایی کنن پیشاپیش متشکرم

دیدگاه