پاسخ : ارتباط avr با arm
ممنون
ممنون
#include <mega32a.h> #include <lcd.h> #include <delay.h> #include <stdio.h> #asm .equ __lcd_port= 0x1B //PORTA #endasm #define Lenght_Array 10 unsigned char LCD_Show [ Lenght_Array ] ; void LCD_Initialization ( void ) { lcd_init (16) ; lcd_clear () ; lcd_gotoxy (0 , 0) ; } void Sender_Initialization ( unsigned int baud ) { UBRRH = 0 ; UBRRL = baud ; //UCSRB |= (1 << RXEN ) | (1 << TXEN ); // Turn on the transmission and reception circuitry UCSRB |= (1 << TXEN ); UCSRC |= (1 << URSEL ) | (1 << UCSZ0 ) | (1 << UCSZ1 ); // Use 8- bit character sizes - URSEL bit set to select the UCRSC register } void USART_TOSend ( int ByteToSend ) { while (( UCSRA & (1 << UDRE )) == 0) {}; // Do nothing until UDR is ready for more data to be written to it UDR = ByteToSend ; // Send out the byte value in the variable " ByteToSend " } void main () { DDRC = 0X01 ; LCD_Initialization () ; Sender_Initialization ( 0x33 ) ; PORTC = 0X01 ; delay_ms (50) ; PORTC = 0X00 ; delay_ms (50) ; while (1) { USART_TOSend ( 5 ) ; PORTC = 0X01 ; delay_ms (50) ; PORTC = 0X00 ; delay_ms (50) ; sprintf ( LCD_Show , "%d" , UDR) ; //sprintf ( char array , "String Text ..." , variable ) lcd_puts ( LCD_Show ) ;
#include <AT91SAM7X256.H> #include "delay.h" #include "usart.h" #include "TFTLCD.h" #include "nature.h" #define Lenght_Array 10 char PORTRAIT = 0; char data; char A ; char *q="receive data"; int a; int i = 0; int main (void) { tftlcd_init(); usart0_init(2,9600); while (1) { tftlcd_puts(q,BLUE,GREEN,1); delay_ms(20); A = getkey(); tftlcd_putchar(A,BLUE,GREEN,1); delay_ms(100); }
#include <mega32a.h> #include <lcd.h> #include <delay.h> #include <stdio.h> #asm .equ __lcd_port= 0x1B //PORTA #endasm #define Lenght_Array 10 //unsigned char ReceivedByte ; unsigned char LCD_Show [ Lenght_Array ] ; unsigned char S = 'V'; void LCD_Initialization ( void ) { lcd_init (16) ; lcd_clear () ; lcd_gotoxy (0 , 0) ; } void USART_Init( unsigned int baud ) { /* Set baud rate */ UBRRH = (unsigned char)(baud>>8); UBRRL = (unsigned char)baud; /* Enable receiver and transmitter */ UCSRB = (1<<RXEN)|(1<<TXEN); /* Set frame format: 8data, 2stop bit */ //UCSRC = (1<<URSEL)|(1<<USBS)|(3<<UCSZ0); UCSRC |= 0X26; } void USART_Transmit( unsigned char data ) { /* Wait for empty transmit buffer */ while ( !( UCSRA & (1<<UDRE)) ); /* Put data into buffer, sends the data */ UDR = data; } /* unsigned char USART_Receive( void ) { //Wait for data to be received while ( !(UCSRA & (1<<RXC)) ); //Get and return received data from buffer return UDR; } */ /* void Sender_Initialization ( unsigned int baud ) { UBRRH = 0 ; UBRRL = baud ; UCSRB |= 0X08; // Turn on the transmission and reception circuitry //UCSRB |= (1 << TXEN ); UCSRC |= 0X26; // Use 8- bit character sizes - URSEL bit set to select the UCRSC register //URSEL = 0 LSB //URSEL = 1 MSB } void USART_TOSend ( unsigned char ByteToSend ) { while (( UCSRA & (1 << UDRE )) == 0) {}; // Do nothing until UDR is ready for more data to be written to it UDR = ByteToSend ; // Send out the byte value in the variable " ByteToSend " } void USART_TORecieve ( void ) { while (( UCSRA & (1 << RXC )) == 0) {}; // Do nothing until data have been received and is ready to be read from UDR ReceivedByte = UDR ; // Fetch the received byte value into the variable " ReceivedByte " } */ void main () { DDRC = 0X01 ; LCD_Initialization () ; //Sender_Initialization ( 0x19 ) ; USART_Init ( 0x19 ); PORTC = 0X01 ; delay_ms (50) ; PORTC = 0X00 ; delay_ms (50) ; while (1) { //USART_TORecieve (); //USART_TOSend ( S ) ; //ReceivedByte = USART_Receive (); USART_Transmit (S); PORTC = 0X01 ; delay_ms (50) ; PORTC = 0X00 ; delay_ms (50) ; sprintf ( LCD_Show , "%s" , UDR ) ; //sprintf ( char array , "String Text ..." , variable ) lcd_puts ( LCD_Show ) ; } }
#include <AT91SAM7X256.H> #include "delay.h" #include "usart.h" #include "TFTLCD.h" #include "nature.h" #define Lenght_Array 10 char PORTRAIT = 0; char data; char A ; char *q="receive data"; int a; int i = 0; int main (void) { tftlcd_init(); usart0_init(2,9600); while (1) { tftlcd_puts(q,BLUE,GREEN,1); delay_ms(20); A = getkey(); tftlcd_putchar(A,BLUE,GREEN,1); delay_ms(100); }
#include <mega32a.h> #include <lcd.h> #include <delay.h> #include <stdio.h> #asm .equ __lcd_port= 0x1B //PORTA #endasm #define Lenght_Array 10 #define MainClock 8000000 #define BAUD 19200 #define UBRR (( MainClock ) / ( BAUD * 16 ) - 1 ) //unsigned char ReceivedByte ; //unsigned char ReceivedByte ; unsigned char LCD_Show [ Lenght_Array ] ; //unsigned char S = 0x65; unsigned char S = 'S'; unsigned char l; int i; void LCD_Initialization ( void ) { lcd_init (16) ; lcd_clear () ; lcd_gotoxy (0 , 0) ; } void USART_Init( unsigned int baud ) { /* Set baud rate */ UBRRH = (unsigned char)(baud>>8); UBRRL = (unsigned char)baud; /* Enable receiver and transmitter */ UCSRB = (1<<RXEN)|(1<<TXEN); /* Set frame format: 8data, 2stop bit */ //UCSRC = (1<<URSEL)|(1<<USBS)|(3<<UCSZ0); //UCSRC |= 0X26; UCSRC |= 0XA6; } void USART_Transmit( unsigned char data ) { /* Wait for empty transmit buffer */ while ( !( UCSRA & (1<<UDRE)) ); /* Put data into buffer, sends the data */ UDR = data; } /* unsigned char USART_Receive( void ) { //Wait for data to be received while ( !(UCSRA & (1<<RXC)) ); //Get and return received data from buffer return UDR; } */ /* void Sender_Initialization ( unsigned int baud ) { UBRRH = 0 ; UBRRL = baud ; UCSRB |= 0X08; // Turn on the transmission and reception circuitry //UCSRB |= (1 << TXEN ); UCSRC |= 0X26; // Use 8- bit character sizes - URSEL bit set to select the UCRSC register //URSEL = 0 LSB //URSEL = 1 MSB } void USART_TOSend ( unsigned char ByteToSend ) { while (( UCSRA & (1 << UDRE )) == 0) {}; // Do nothing until UDR is ready for more data to be written to it UDR = ByteToSend ; // Send out the byte value in the variable " ByteToSend " } void USART_TORecieve ( void ) { while (( UCSRA & (1 << RXC )) == 0) {}; // Do nothing until data have been received and is ready to be read from UDR ReceivedByte = UDR ; // Fetch the received byte value into the variable " ReceivedByte " } */ void main () { DDRC = 0X01 ; LCD_Initialization () ; //Sender_Initialization ( 0x19 ) ; USART_Init ( UBRR ); PORTC = 0X01 ; delay_ms (50) ; PORTC = 0X00 ; delay_ms (50) ; lcd_init(16); lcd_gotoxy(0,0); lcd_puts("Robotic"); delay_ms(1000); lcd_clear(); while (1) { //USART_TORecieve (); //USART_TOSend ( S ) ; //ReceivedByte = USART_Receive (); USART_Transmit (S); PORTC = 0X01 ; delay_ms (50) ; PORTC = 0X00 ; delay_ms (50) ; l = 0x65; sprintf ( LCD_Show , "data=%d" , l ) ; //sprintf ( char array , "String Text ..." , variable ) for(i=0;i<16;i++) { lcd_gotoxy(i,0); lcd_putchar ( LCD_Show[i] ) ; } } }
#define MainClock 8000000 #define BAUD 19200 #define UBRR (( MainClock ) / ( BAUD * 16 ) - 1 )
دیدگاه