Code for sending data in ASCII from PC to 89c51 and displaying it on 7 segment

Status
Not open for further replies.

sunish

hai all
i like to read and display the hyper terminal out put of a computer which will send 10 digit charectors to my 89c51 based system using 10 seven segment displays.i think the charactors will be send by the pc in ascii format.ie +1000.09gm.how is it possible for me to display the ascii charectors in seven segment displays?what are the values i should load in the timer/scon/smod registers for a boadrate of 9600?
source code and ckt diagram also welcome

thanking you

sunish

Code Warrior

Full Member level 4
implement odd parity in 89c51

For this you have read any 8051 book.

KST

Full Member level 2
pcon in 89c51

I think that there is no problem. Could you check PC software is OK ? Capble is OK ? 89C51 is OK ? My way is using the samples program and after that I do my product.
there is the one times I loss 2 weeks for cable.
Good luck for you !

IanP

seven segmen 89c51

First of all, how to setup 8051 for selected baudrate ..
All what you need to do is to load A with a number from 0 to 9 and CALL this subroutine:
Code:
; ====================================================
; Initialize Serial communications  A=Baud Rate
; With cristal oscillator of 11,059,200 value for auto-reloded Timer1 is calculated using the
; following formula: 256-57600/BaudRate=TH1
; Full formula: 256-[2pwrSMOD/32]*[SC/(12*BaudRate)]

Ser_Setup:
MOV   	PCON, #80h	; Set SMOD=1
MOV   	SCON, #52h
MOV   	TMOD, #20h
MOV   	DPTR, #BAUDRATE
MOVC  	A, @A+DPTR
MOV   	TH1, A
SETB  	TR1
RET

BAUDRATE:
DB   0FFh        ; 57600    0
DB   0FEh        ; 28800    1
DB   0FDh        ; 19200    2
DB   0FCh        ; 14400    3
DB   0FAh        ; 9600     4
DB   0F4h        ; 4800     5
DB   0E8h        ; 2400     6
DB   0D0h        ; 1200     7
DB   0A0h        ; 600      8
DB   040h        ; 300      9

; ==================================================
Also visit: http://www.atmel.com/dyn/resources/prod_documents/doc4346.pdf

For hardware example of the sequential 7-segment LED display goto:
Chapter 4.8. Frequency Counter
To control transistors you can select pins from PORT2 (P2.0, P2.1 ..). This will free P3.0 (RxD) and P3.1 (TxD) which will be required in serial communication with PC.
Picture below shows you how to connect these pins to CMOS/RS-232 level converter ..

Regards,
IanP

sunish

89c51 converter

hai

thank you all for your replys .still i didnot understand that how can i convert an ascii charactor to display that on seven segment display?in lcd we can directly send the charector.how it is possible in 7 segment displays?suppose i am using port 1 for sending the data and port 2 and port 3 (leaving rxd and txd) for transitor switching.i am having 10 displays and the data will be like +100.0987gm or -159.111gm
thanking you

sunish

silvio

89c51 program memory tutorial

Suppose you have the port P1 connections to 7 segment display as follows:

P1.0 -> a
P1.1 -> b
P1.2 -> c
P1.3 -> d
P1.4 -> e
P1.5 -> f
P1.6 -> g

If you choose display with common anode then the value writen to port P1 should be :

display data - value P1 (hex)

0 - x1000000 or C0
1 - x1111001 or F9
2 - x0100100 or A4
3 - x0110000 or B0
4 - x0011001 or 99
5 - x0010010 or 92
6 - x0000010 or 82
7 - x1111000 or F8
8 - x0000000 or 80
9 - x0010000 or 90

x = don't care but you can set logic "1"

Now what you don't understand is how you assign the ASCII hex value to the one required to P1.
You can do this with what is called a lookup table stored in the code memory program.

Hope you are familiar with this declaration;

ORG FFF0h
DIGIT_CODES: DB C0h, F9h, A4h, B0h, 99h, 92h, 82h, F8h, 80h, 90h

As you can see the values are placed in memory program starting with FFF0h, but you can choose the insertion point according with your memory size.

FFF0 - C0
FFF1 - F9
FFF2 - A4
FFF3 - B0
FFF4 - 99
FFF5 - 92
FFF6 - 82
FFF7 - F8
FFF8 - 80
FFF9 - 90

What you have to do next is to initialize the DPTR register with the first entry in the lookup table.

MOV DPTR, #DIGIT_CODE and now the DPTR holds FFF0h

Suppose now that you have the received character in SBUF. I will not check if is in the range 30h - 39h.

MOV A, SBUF

If you subtract now 30h from A,

CLR C
SUBB A, #30h

the accumulator holds now a value in range 0 - 9 decimal. Suppose SBUF = 37h (for ASCII 7), now A = 07h after subtraction.

After MOVC A, @A+DPTR
A holds the value F8h, the value which is stored in memory program FFF7h
Just because A+DPTR = 07h (the initial value of A) + FFF0h (the value of DPTR)

Now you can write the value of A to port P1 and drive the appropiate transistor for common anode display on port P2 as you demand.

sunish

Re: pc to 89c51

hai
i will try this
one more simple doubt.i am going to use the 'h' of the 7 segment display.to display the '.' value. iif i am displaying 107.65,the . comes between 7 and 6 will be displayed on the next 7 seg display.i want to display the '.' on the 7 seg of digit 7 itself.what step i should add to achive the same?

sunish

IanP

Re: pc to 89c51

One option is to connect bit 7 of Port1 (or whichever port is used for that) to segment 'h' ..
(you can do this operation directly to the memory cell where you keep this digit's value)

If you want to turn it ON set it to H:
ORL P1, #10000000b

and if you need to turn it OFF clear it to L:
ANL P1, #01111111b

or the opposite way around ..

Regards,
IanP

silvio

Re: pc to 89c51

I believe your received characters are stored in a small buffer in internal or external RAM.
When you retrieve data from this buffer and send it to display, every time you send a character look ahead for the next one in the buffer.
If it's "." then before sending the character (exemple 7) clear the most significant bit of register that will be send to P1.
Thus if you send accumulator contents to P1, where acc holds value F8h (according to ASCII 37h as explained above), before sending perform an AND A, #7Fh
You probably notice that P1.7 has not being used yet. Thus it can be tied to decimal point of the display digits.

Because you use P1 for sending data to all display it's wise to use what is called interdigit blanking.
Before sending data to the next digit, send FFh to P1 for a small amount of time (usual 1 / n where n is the number of digits) in order to blank all the displays.
Doing this P1.7 will be blank too. And your previous decimal point will not appear lit on the next one.

Sorry, IanP I saw your post after posting mine.

sunish

Re: pc to 89c51

hai
i tried this but it didn't work
when i've checked the hyper terminal properties.(the pc exicutes a program and send the results to the hyper terminal),it shows the following

baud rate =1200
data bits=7
stop bit=1
parity =odd
hand shaking=hardware

to receive the data from the hyper terminal,what necessary changes i must use in the registers of my 89c51?
i am using a 11.0592 mhz crystal.pls give me the regiaster values.

sunish

silvio

Re: pc to 89c51

Hi Sunish,

You can use the IanP's code. It's suitable for your 11.0592 MHz crystal
Just insert into your code the sequence:

Code:
;
MOV A, #0              ; for 57600
;   or     MOV A, #1  ; for 28800
;   or     MOV A, #2  ; for 19200
; or 3 or 4 or 5 .... look at the BAUDRATE values inside IanP's code
; and choose one according to your hyperterminal baudrate settings
LCALL Ser_Setup
;

But you must change your settings in hyperterminal, too :

baud rate =1200 or whatever
data bits=8
stop bit=1
parity =none

wek

Full Member level 4
Re: pc to 89c51

sunish said:
i tried this but it didn't work
when i've checked the hyper terminal properties.(the pc exicutes a program and send the results to the hyper terminal),it shows the following

baud rate =1200
data bits=7
stop bit=1
parity =odd
hand shaking=hardware
Unless you have implemented hardware handshaking (CTS and DSR connected to proper levels), which I doubt you have (I believe you connected only Rx and Tx from PC to the '51 via a level convertor such as MAX232), you should set handshaking to none; otherwise the PC won't send out anything.

IanP said:
If you want to turn it ON set it to H:
ORL P1, #10000000b

and if you need to turn it OFF clear it to L:
ANL P1, #01111111b

Just to remind, you can change P1 bits also using the bit operations; in this case setb p1.7 and clr p1.7 . Of course, everything said by IanP and silvio holds.

You might also want to check out the following tutorial:

wek

sunish

Re: pc to 89c51

hai all
the problem is i cannot change the hyperterminal settings because the same is used for some other purpose also.can we not program the 89c51 to receive the data with a baud rate of 1200/2400,data 7 bits,one stop bit,odd parity and hardware hand shaking?

sunish

silvio

Re: pc to 89c51

Hi Sunish,

You can program 89C51 to receive data at 1200 bps, with 1 stop bit, odd parity and hardware handshaking.
As you probably notice is something missing. You can't program 89C51 to receive or send 7 bits through hardware USART..

However, I don't see any reason for which you can't change Hyperterminal settings.
If you open hyperterminal program you're prompted to type a name for a specific connection, say COM 1.
Then you have to choose baudrate, data bits, parity and handshaking.
When you close your session, you're prompted if you want to save it. Choose YES and that's all.
The settings could be different according to your applications needs. Don't click on a shortcut for the other application. Open hyperterminal from path Start -> Programs -> Accessories -> Communications -> Hyper Terminal
Try it.

IanP

Re: pc to 89c51

I guess you would like to simulate situation at 1200bps and 7bits, odd, 1Stop ..

In this case, load registers as mentioned before:
TMOD --> 20h
SCON --> 52h
PCON --> 80h
TH1 -->0D0h
and SETB TR1
To operate 7-bits, odd, 1Stop copy Putchar and Getchar from the attached page ..

Also, implement "null modem with loop back handshaking" ( https://www.lammertbies.nl/comm/info/RS-232_null_modem.html )

Regards,
IanP

silvio

Re: pc to 89c51

YES, nice trick with ACC.7 replaced by P for send/receive 7 bits.
I never used 7bits for serial communication before, but thank you for suggestion.

besthabit

Junior Member level 3
Re: pc to 89c51

i have the same problem can u plz chk out this code

#include <AT89X51.H>

char getCharacter (void)
{
char chr; /* variable to hold the new character */
while (RI != 1) {;}
chr = SBUF;
RI = 0;
return(chr);
}

void main (void)
{
//int i;
char chr; /* variable to hold characters in */
SCON = 0x50; /* mode 1, 8-bit uart, enable receiver */
TMOD = 0x20; /* timer 1, mode 2, 8-bit reload */
TH1 = 0XFD; /* 9600 */
TR1 = 1;
TI = 1;
while (1)
{
chr = getCharacter ();
//for(i=0;i<3300;i++)
//{};
P1=chr;

}
}

Status
Not open for further replies.