Hello guys,
I used to program with bascom language and now i just start using the C language,
I wrote a code to send data using USART,and i tried to simulate it on proteus 8 virtual terminal but it is not working ..
Could you figure out my mistake !
#include <avr/io.h>#include <stdio.h>unsignedchar data;int delay;// function to send datavoid USART_TRANS (unsignedchar data){while(!( UCSRA &(1<<UDRE)));// wait while register is free
UDR = data;// load data in the register}// function to receive dataunsignedchar USART_REC (void){while(!(UCSRA)&(1<<RXC));// wait while data is being receivedreturn UDR;// return 8-bit data}int main(void){
UCSRA=(0<<RXC)|(0<<TXC)|(0<<UDRE)|(0<<FE)|(0<<DOR)|(0<<UPE)|(0<<U2X)|(0<<MPCM);
UCSRB=(0<<RXCIE)|(0<<TXCIE)|(0<<UDRIE)|(1<<RXEN)|(1<<TXEN)|(0<<UCSZ2)|(0<<RXB8)|(0<<TXB8);
UCSRC=(1<<URSEL)|(0<<UMSEL)|(0<<UPM1)|(0<<UPM0)|(0<<USBS)|(1<<UCSZ1)|(1<<UCSZ0)|(0<<UCPOL);
UBRRH=0x00;
UBRRL=0X33;//BAUD 9600 AND CRYSTAL 8.000.000
data="Hello !";while(1){
USART_TRANS(data);for(delay=0;delay=1000;delay++);}}
I adjest the proteus terminal to the same settings,same baud ! :roll:
is there any better program to simulate my program ?!
Thank you so much your code works perfectly !
could you help me to send a variable ? which contains a variable number ?
and also all the letters appear next to each other is there anyway to pass a line ?
Thank you for your fast replay first of all ..
Actually i want to send a variable integer for now ..
I was trying to understand the way the u have used to send the string :
"you used a pointer Ldata ? and you made the Ldata=gdata while calling the function
as a result Ldata is pointing to gdata[0] ??? i hope i am right ?"
Thank you so much !