Discussion in "8051 Discussion Forum" started by    carlos_10111    Nov 6, 2009.
Fri Nov 06 2009, 10:43 AM
#1
Hi every one, i'm trying to use proteus virtual terminal for serial communication.
But i'm getting funny characters on the display. i tried using the code from the tutorial, it shows nothing, but the one i coded is showing but not what i'm expecting.
the code is just suppose to show a character on the vTerminal. here is the code and the circuit.
#include <REGX51.H>


void delay(int);
void SerTx(unsigned char x);
void serial_send(unsigned char dat);
void serial_init();
unsigned char serial_read();
void main()
{
 
while(1)
{  
     serial_init();
     SerTx('c'); // this is my function
     serial_send('C'); //tutorial function
              
	
}

}

void SerTx(unsigned char x)
{
  	SBUF =x;
	while (TI==0);
	TI = 0;

} 

void serial_init()
{	
	TMOD =0x20;
             SCON =0x50;
	TH1= 0xFD;
	TL1= 0XFD;
 	TR1 = 1;

}

void delay(int cnt)
{
   int x,y;
   for(x = 0; x < cnt;x++);
   	for (y=0;y<100;y++);
   			
 }  
void serial_send(unsigned char dat)
{
	while(!TI);
	TI = 0;
	SBUF = dat;
}

unsigned char serial_read()
{

	while(!RI);
	RI = 0;
	return SBUF;
}





As you can see from the terminal window, instead of showing 'c' it showing a quarter (1/4).
I tried changing the font type, still get the same error.

Please help out!
Fri Nov 06 2009, 11:30 AM
#2
comment this serial_send('C'); from while loop.

and take serial_init function out of while loop as its required only once.
Mon Nov 09 2009, 11:25 AM
#3
Thanx Ajay, but i'm still getting the same errror!
How do you use the serial_send function? is the structure of my code fine?
I have a feeling the problem is not with the function, because it sending the information, it's only that the characters are displayed in a format that i don't understand. if i transmit A, i get a funy character!

Mon Nov 09 2009, 11:52 AM
#4
probably you did not set the correct baud rate.

open virtual terminal properties and see what baud is set there. try not to use max232 in simulation, coz its of no use in virtual circuit debugging.
Wed Nov 11 2009, 08:08 AM
#5
Hi Ajay, yes i tried removing the max232, but still getting the same problem.
the baud rate i'm using is 9600, which is the same i did setup in the program.
Let me try to use a lower baud rate and see what happens
Thanx again,
Wed Nov 11 2009, 08:25 AM
#6
Nop, still getting the same problem. here are the changes i have made to the circuit as well as the program. Here is how my codes looks like:


#include <AT89X51.H>


void delay(unsigned int ) ;
void SerTx(unsigned char );
void serial_send(unsigned char );
void serial_init();
unsigned char serial_read();

void main(void)
{
serial_init(); 
while(1)
{  


	
	serial_send('B');

	serial_send('C');

	serial_send('D');


	
}

}

void SerTx(unsigned char x)
{
  	SBUF =x;
	while (TI != 1);
	TI = 0;

} 

void serial_init()
{	
	TMOD =0x20;
    SCON =0x50;
	TH1= -6;
	TR1 = 1;

}

  
void serial_send(unsigned char dat)
{  
	SBUF = dat;
	while(TI == 0);
	TI = 0;
	
}

unsigned char serial_read()
{

	while(RI == 0);
	RI = 0;
	return SBUF;
} 
void delay(unsigned int cnt)
{	int x;
	for (x=0; x < cnt; x++)
	{
	TMOD = 0x10;
	TH1 = 0xC5;
	TL1 = 0x68;
	TR1 = 1;
	while(TF1 != 1 );
	TR1 = 0;
	TF1 = 0;
	}
} 







This picture is showing what im getting after i transmit B,C and D




Thanx for your help once again!
Wed Nov 11 2009, 12:22 PM
#7
hi carlos_10111,

Looks to me that you are messing up with timer 1!

void SerTx(unsigned char x)
{
        SBUF =x;
        while (TI != 1);
        TI = 0;
}

void serial_init()
{      
        TMOD = 0x20;
        ------------
        ......
}
void delay(unsigned int cnt)
{       int x;
        for (x=0; x < cnt; x++)
        {
        TMOD = 0x10;
        TH1 = 0xC5;
        TL1 = 0x68;
        TR1 = 1;
        while(TF1 != 1 );
        TR1 = 0;
        TF1 = 0;
        }
}



Your serial_init() configures T1 in auto reload mode and delay() in mode 1!
If you want to use UART. you must not modify Timer 1 as it is hardwired to clock the UART. Besides you are overwriting the baud rate (-6) values in delay().
I guess if you use timer 0 in delay, your program would work fine.

BTW I would prefer using assembly for delay kind of operations.
One more suggestion is for your delay function. You can rewrite it as :
void delay(unsigned int cnt)
{       int x;
        
        TMOD = 0x10;
        TH1 = 0xC5;
        TL1 = 0x68;
        TR1 = 1;
                     
        for (x=0; x < cnt; x++)
        {
             while(TF1 != 1 );
             TH1 = 0xC5;
             TL1 = 0x68;
             TF1 = 0;
        }
}


Cheers
Sarma
Wed Nov 11 2009, 01:28 PM
#8
Thanx for your help sarma, but it looks the problem is not with the delay. here is the modified code. i commented out the delay, but still get the same problem!

#include <AT89X51.H>


//void delay(unsigned int ) ;
void SerTx(unsigned char );
void serial_init();
unsigned char serial_read();

void main(void)
{
serial_init(); 
while(1)
{  


	
	SerTx('B');

	SerTx('C');

	SerTx('D');


	
}

}

void SerTx(unsigned char x)
{
  	SBUF =x;
	while (TI != 1);
	TI = 0;

} 

void serial_init()
{	
	TMOD =0x20;
    SCON =0x50;
	TH1= -6;
	TR1 = 1;

}

 

unsigned char serial_read()
{

	while(RI == 0);
	RI = 0;
	return SBUF;
} 


/*void delay(unsigned int cnt)
{	int x;
	TMOD = 0x01;
	TH0 = 0xC5;
	TL0 = 0x68;
	TR0 = 1;
	for (x=0; x < cnt; x++)
	{

	while(TF0 != 1 );
	TH0 = 0xC5;
	TL0 = 0x68;
	TF0 = 0;
	}
}  */


Here is some setup for the virtual terminal, may be i'm not configuring it properly.



Can someone look at this? i can't be stuck on this please!
Wed Nov 11 2009, 09:17 PM
#9
you have kept Send XON/XOFF as yes. make it no. coz we are not using any flow control in transmission.
Thu Nov 12 2009, 05:03 AM
#10
Here are some debug tips:

1. check the baud rate! Did you set TH1 for 4800 baud rate, some times we miscalculate the number loaded to TH1.

2. Are you sure that the characters are received and transmitted, i.e. is the communication between PC and your controller is established? Are there any debug LEDs connected to Tx and Rx lines which blink when you Transmit/receive any character, or some thing of that kind to be sure that the transmission and reception is happening properly.

3. check your clock speed and crystal frequency when initiating the timer. I assume that the value(-6) you used here for a 12 clock mode micro-controller with standard 11.XXX MHz crystal.

If you are sure about 1 and 2 then try setting your Vterminal's baud rate to other numbers. This is a random process! This may or may not work.
 carlos_10111 like this.

Get Social

Information

Powered by e107 Forum System

Conversation

Mon Oct 21 2019, 08:46 AM
charmdatemru
cooking
Sun Oct 13 2019, 02:02 AM
Aline Hutchinson
Hey there,
ExperimenterUK
Sat Oct 12 2019, 10:23 PM
Log in.. then post your code in the 8051 forum
Sat Oct 12 2019, 10:18 AM
Bhadra Sajikumar
i am doing a countdown timer with 8051 for my project, unfortunately our professor had to take a leave of absence before he could teach us most of it.. can someone explain the .asm code of it for me?
Mon Sep 23 2019, 07:37 AM
Nathaniel
I am doing a project for my schools wireless security system with cameras,sensors and spot lights using 8051 micro controller, could you help me out with the design and its source code.
Wed Sep 18 2019, 08:48 PM
Caryn Kover
Thank you for your time,
ExperimenterUK
Mon Aug 05 2019, 07:09 PM
@Ismail ..post in forum, give details
Mon Aug 05 2019, 04:33 PM
Ismail balghmi
Hello. Please I won't download
ExperimenterUK
Wed Jul 24 2019, 12:47 AM
@BUSTER123 Please post in the forum
Tue Jul 23 2019, 06:13 PM
BUSTER123
hello! newbie here. i am kind of a guy who hates using ready - made existing libraries, so this helped a lot as i was trying to control and write to a character lcd display. however, i can't figure out how to set the cursor position. for example, i want to set it to the 5th column in the first row, so position 5. so according to the table, i am sending 10000101 on the 8 data lines of the lcd (register select pulled low). the cursor does not move there however. and i cant move the cursor left or right too. is it something wrong that i am doing? thank you.

Downloads

Comments

ilylily07
Tue Oct 15 2019, 04:32 PM
hientran123
Tue Oct 15 2019, 02:27 AM
Sat Oct 05 2019, 02:38 PM
zexalo
Thu Oct 03 2019, 09:53 AM
thanhle12345
Thu Oct 03 2019, 07:37 AM
ramon_vsc
Fri Sep 20 2019, 04:53 PM
youssoufba
Thu Sep 19 2019, 11:57 AM
Taiphan000
Tue Sep 17 2019, 04:21 AM

Online

Guests: 48, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 38097
Newest member: ilylily07
Forum Activity
wimac Avatar
Posted By wimac
Mon Oct 21 2019, 09:18 AM
I’ve been following this thread and looking at the...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sun Oct 20 2019, 03:09 PM
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sun Oct 20 2019, 03:02 PM
sir, when i on display ,sometime 3rd display is no...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sun Oct 20 2019, 02:53 PM
sir, when i on display ,sometime 3rd display is no...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sun Oct 20 2019, 12:21 AM
Your code seems okay on my simulationTry my code o...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sun Oct 20 2019, 12:21 AM
Your code seems okay on my simulationTry my code o...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sat Oct 19 2019, 07:13 PM
please find video attachment. 3rd & 4th displa...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sat Oct 19 2019, 07:05 PM
sir, 3rd and 4th dot matrix display flickering, ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Oct 18 2019, 09:18 PM
Hopefully you understand some of the program.Which...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Thu Oct 17 2019, 09:38 PM