Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[AVR] Atmega16 with Proteus 8 virtual terminal !

Status
Not open for further replies.

mzannerni

Newbie level 3
Newbie level 3
Joined
Mar 19, 2014
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
29
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 ! :cry:

i will post my code here :


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <avr/io.h>
#include <stdio.h>
 
unsigned char data;
int delay;
 
// function to send data
void USART_TRANS (unsigned char data)
{
    while (!( UCSRA & (1<<UDRE)));   // wait while register is free
    UDR = data;   
                                       // load data in the register
}
// function to receive data
unsigned char USART_REC (void)
{
    while(!(UCSRA) & (1<<RXC));                   // wait while data is being received
    return 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 ?!
 
Last edited by a moderator:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <avr/io.h>
#include <stdio.h>
 
unsigned char gdata[] = "Hello";
unsigned long delay;
 
// function to send data
void USART_TRANS (unsigned char ldata)
{
    while (!( UCSRA & (1 << UDRE)));   // wait while register is free
    UDR = ldata;   
                                       // load data in the register
}
 
// function to receive data
unsigned char USART_REC (void)
{
    while(!(UCSRA) & (1 << RXC));                   // wait while data is being received
    return UDR;                                   // return 8-bit data
}
 
// function to send data
void USART_TRANS_STRING (unsigned char *ldata)
{
        while(*ldata){
        USART_TRANS(*ldata++);
    }
}
 
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
 
    
        while(1)
        {
  
            USART_TRANS_STRING(gdata);
 
            for (delay = 0; delay = 1000000; delay++);
    
        }
}

 


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <avr/io.h>
#include <stdio.h>
 
unsigned char gdata[] = "Hello";
unsigned long delay;
 
// function to send data
void USART_TRANS (unsigned char ldata)
{
    while (!( UCSRA & (1 << UDRE)));   // wait while register is free
    UDR = ldata;   
                                       // load data in the register
}
 
// function to receive data
unsigned char USART_REC (void)
{
    while(!(UCSRA) & (1 << RXC));                   // wait while data is being received
    return UDR;                                   // return 8-bit data
}
 
// function to send data
void USART_TRANS_STRING (unsigned char *ldata)
{
        while(*ldata){
        USART_TRANS(*ldata++);
    }
}
 
int main(void)
{
    
     
    UCSRA = (0 << RXC)   | (0 << TXC)   | (0 << UDRE)   | (0 << FE)   | (0 << DOR)  | (0 << PE)   | (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
 
    
        while(1)
        {
  
            USART_TRANS_STRING(gdata);
 
            for (delay = 0; delay < 1000000; delay++);
    
        }
}


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 ?
 

could you help me to send a variable ? which contains a variable number ?

Integer or float value?

You have to convert each digit of the number to char by adding 0x30 and then form a string.

and also all the letters appear next to each other is there anyway to pass a line ?


Code C - [expand]
1
2
3
unsigned char gdata[] = "Hello\r\n";
 
USART_TRANS_STRING(gdata);



or


Code C - [expand]
1
2
3
4
5
unsigned char gdata[] = "Hello";
 
USART_TRANS_STRING(gdata);
USART_TRANS(0x13);
USART_TRANS(0x10);

 

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 !
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top