سلام به همه دوستان
من با winavr برنامه ای نوشتم که به صورت زیر هست:
همونطور که میبینید چیز پیچیده ای نیست تو proteus هم جواب میده .ولی وقتی سر breadboardمیبندم خود به خود یه سری اطلاعات رو نشون میده بدون اینکه پورت rx به جایی وصل باشه.لطفا راهنماییم کنید
من با winavr برنامه ای نوشتم که به صورت زیر هست:
کد:
#include "global.h" #include <avr/io.h> #include <avr/io.h> #include <avr/pgmspace.h> #include <util/delay.h> #ifndef F_CPU//define cpu clock speed if not defined #define F_CPU 8000000 #endif #define BAUDRATE 1200 //calculate UBRR value #define UBRRVAL ((F_CPU/(BAUDRATE*16UL))-1) //define receive parameters #define SYNC 0XAA// synchro signal //switch led on command //switch led off command #include <avr/sleep.h> #include <avr/interrupt.h> #include "lcd.h" #include "rprintf.h" #include "aes.h" #define u08 unsigned char #define u16 unsigned int #define u32 unsigned long u08 iv[16] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; u08 aes_key[16] = { '\0', '\0', '\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0'}; u08 text_in[16] = { '\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0' }; void USART_Init(void) { //Set baud rate UBRRL=(uint8_t)UBRRVAL; //low byte UBRRH=(UBRRVAL>>8); //high byte //Set data frame format: asynchronous mode,no parity, 1 stop bit, 8 bit size UCSRC=(1<<URSEL)|(0<<UMSEL)|(0<<UPM1)|(0<<UPM0)| (0<<USBS)|(0<<UCSZ2)|(1<<UCSZ1)|(1<<UCSZ0); //Enable Transmitter and Receiver and Interrupt on receive complete UCSRB=(1<<RXEN)|(1<<RXCIE); //|(1<<TXEN); //enable global interrupts } uint8_t USART_vReceiveByte(void){ // Wait until a byte has been received while((UCSRA&(1<<RXC)) == 0); // Return received data return UDR;} ISR(USART_RXC_vect){ text_in[0]=USART_vReceiveByte(); /* text_in[1]=USART_vReceiveByte(); text_in[2]=USART_vReceiveByte(); text_in[3]=USART_vReceiveByte(); text_in[4]=USART_vReceiveByte(); text_in[5]=USART_vReceiveByte(); text_in[6]=USART_vReceiveByte(); text_in[7]=USART_vReceiveByte(); text_in[8]=USART_vReceiveByte(); text_in[9]=USART_vReceiveByte(); text_in[10]=USART_vReceiveByte(); text_in[11]=USART_vReceiveByte(); text_in[12]=USART_vReceiveByte(); text_in[13]=USART_vReceiveByte(); text_in[14]=USART_vReceiveByte(); text_in[15]=USART_vReceiveByte();*/ lcdInit(); lcdClear(); rprintfInit(lcdDataWrite); _delay_ms(1000); lcdClear(); int i; lcdClear(); lcdDataWrite( text_in[0]); /*for(i=0;i<=15;i++){ lcdDataWrite( text_in[i]); }*/ _delay_ms(10000); //lcdClear(); while(i<=15){ //send command to switch led ON //Send_Packet(0b00000000, 0b00000000); aes_key[i]='\0'; text_in[i]='\0'; i++; } } void Main_Init(void){ //enable global interrupts sei(); } int main(void) { lcdInit(); Main_Init(); USART_Init(); while(1) { } }