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.

[SOLVED] how to check the uart transmission in proteus?

Status
Not open for further replies.

PRABAKARDEVA

Full Member level 2
Full Member level 2
Joined
Sep 16, 2013
Messages
127
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Location
Chennai
Visit site
Activity points
2,168
i know that how to initialize the uart for transmitting the data and also know to write the data into the register.....but when i checked the uart in proteus.....it showing stack overflow error...what is that error?is that error because of program?
 

i didn't use more functions....calling the functions by two times....can u pls post any code for transmitting the data using uart?
 

i didn't use more functions....calling the functions by two times....can u pls post any code for transmitting the data using uart?

Not only using much functions, calling a function inside a function and recursive functions can make stake overflow

Code C - [expand]
1
2
3
4
main()
{
main();
}


(most of the embedded compilers not offering recursive functions)
or

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
main()
{
add();
}
add()
{
multiply();
}
multiply()
{
add();
}


or simply a ISR could make a stake overflow in higher interrupt rate...
 

Code:
#include<pic.h>
#include<htc.h>
__CONFIG(FOSC_HS & WDTE_OFF & BOREN_OFF & LVP_OFF & DEBUG_OFF);

#define _XTAL_FREQ   20000000

void main()
{
	TRISC6=1;
	    TRISC7=1;
	unsigned char x;
	unsigned int rate=9600;
	x=((_XTAL_FREQ-(16*rate))/(16*rate));    
		TXREG='0';
		BRGH=1;
		SPBRG=x;
		SYNC=0;
		SPEN=1;
		TXEN=1;
		CREN=1;
		GIE=1;
		PEIE=1;
		TXIE=1;
		RCIE=1;
		
	while(!TXIF)
			 continue;		
			TXREG="HELLO";
	
}

- - - Updated - - -

the coding actually shows something in proteus.....but again stack overflow message is displayed....

- - - Updated - - -

PROTEUS FILE HAS BEEN ATTACHED HERE...
 

Attachments

  • CAP.jpg
    CAP.jpg
    196.9 KB · Views: 128

Try this. There is a bug in Proteus related to baudrate. Change baudrate to 1200 bps or 2400 bps in Proteus Virtual Terminal. It will display properly. Keep baudrate as 9600 bps in code.


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
50
51
52
53
#include<htc.h>
 
__CONFIG(FOSC_HS & WDTE_OFF & BOREN_OFF & LVP_OFF & DEBUG_OFF);
 
#define _XTAL_FREQ 20000000
 
void UART_Write(unsigned char uartData);
void UART_Write_Text(unsigned char *uartData);
 
void UART_Write(unsigned char uartData){
 
    TXREG = uartData;
    while(!TXIF);
}
 
void UART_Write_Text(unsigned char *uartData){
 
    while(*uartData)
        UART_Write(*uartData++);
}
 
void main(){
 
    unsigned char x;
    unsigned int rate=9600;
 
    TRISC6=1;
    TRISC7=1;
 
    x = (_XTAL_FREQ - (16 * rate) / (16 * rate); 
    
       
    BRGH = 1;
    SPBRG = x;
    SYNC = 0;
    SPEN = 1;
    TXEN = 1;
    CREN = 1;
    GIE = 1;
    PEIE = 1;
    TXIE = 1;
    RCIE = 1;
 
    INTCON = 0xC0;
 
    while(1){
 
        UART_Write_Text("Hello");
        //Add delay of 500 ms here
 
    }
    
}

 

yeah...its displayed jayanth......why the error occured?what was happened by the 9600 baud rate in virtual terminal?



thank u..



but the stack overflow problem continues...
 


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
50
51
52
53
#include<htc.h>
 
__CONFIG(FOSC_HS & WDTE_OFF & BOREN_OFF & LVP_OFF & DEBUG_OFF);
 
#define _XTAL_FREQ 20000000
 
void UART_Write(unsigned char uartData);
void UART_Write_Text(unsigned char *uartData);
 
void UART_Write(unsigned char uartData){
 
    TXREG = uartData;
    while(!TXIF);
}
 
void UART_Write_Text(unsigned char *uartData){
 
    while(*uartData)
        UART_Write(*uartData++);
}
 
void main(){
 
    unsigned char x;
    unsigned int rate=9600;
 
    TRISC6=1;
    TRISC7=1;
 
    x = (_XTAL_FREQ - (16 * rate) / (16 * rate); 
    
       
    BRGH = 1;
    SPBRG = x;
    SYNC = 0;
    SPEN = 1;
    TXEN = 1;
    CREN = 1;
    GIE = 1;
 //   PEIE = 1;
    TXIE = 1;
    RCIE = 1;
 
 //   INTCON = 0xC0;
 
    while(1){
 
        UART_Write_Text("Hello");
        //Add delay of 500 ms here
 
    }
    
}


Hi try this code....

- - - Updated - - -

you have not written ISR but enabled peripheral interrupts...

- - - Updated - - -

and also setting 129 instead of x you can see with 9600 baud...
 

hi venkadesh....why did u comment those interrupts?can u explain it?

- - - Updated - - -

hi jayanth..i used your code and my code also....again it was not transmitting the data...
 

stack overflow is not occuring after comment those interrupts.....but it was not transmitting the data....

- - - Updated - - -

why do i wanna write the isr?
 

but works fine to me....untitled.JPG

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
#include<htc.h>
 
__CONFIG(FOSC_HS & WDTE_OFF & BOREN_OFF & LVP_OFF & DEBUG_OFF);
 
void UART_Write(unsigned char uartData);
void UART_Write_Text(const char *uartData);
 
void UART_Write(unsigned char uartData){
 
    TXREG = uartData;
    while(!TXIF);
}
 
void UART_Write_Text(const char *uartData){
 
    while(*uartData)
        UART_Write(*uartData++);
}
 
void main(){
 
 
 
    TRISC6=1;
    TRISC7=1;
 
   
    BRGH = 1;
    SPBRG = 129;
    SYNC = 0;
    SPEN = 1;
    TXEN = 1;
    CREN = 1;
 
    while(1){
 
        UART_Write_Text("Hello");
        //Add delay of 500 ms here
    }



- - - Updated - - -

You don wanto write ISR and enabling also dont want enable the peripheral ISR...
 
yeah..its working venkadesh.thank u........after comment those peripheral interrupts...


if i want to write a code for whatever i entering in the keyboard....just want to be displayed in virtual terminal..what should i do?
 

if any key activated (not pressed(if you do so it will transmit continuously when pressing)) put the key value in "void UART_Write(unsigned char uartData)" with addition of '0' (0x30).. that will be shown in the VT..
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top