[SOLVED] Using serial port, How to read a character into RAM location ??

Status
Not open for further replies.

Pavithra89

Member level 2
Joined
Mar 18, 2013
Messages
53
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
1,695
I'm using 8051 MC. I want to know how to move a first character which is read using serial port to a particular register say R1, then next character to R2 so on or maybe only two characters.. Please let me know as soon as possible
 

I don't understand your question, could you be more specific? You need to write some software. When the software sees the first character, it reads it and stores in R1, then when it sees the next character...
 

    V

    Points: 2
    Helpful Answer Positive Rating
Hi

What I wanted to do is read a character and store it to r1 then next character has to go to R2, both has to occupy separate locations so that they can be manipulated in future
Say I want to use only last 4 bits of the character stored in R1 , I can logic 'and' with with 0x0f....

Regards

- - - Updated - - -

Hi
Thank you!!
i thought I could use some push pop instructions but dint knew simple instruction would do the job
Regards
 

Are you reading only 2 characters from USART? The registers are 8 bits. If if store ASCII characters like 'A', 'Z', etc... in the register then why do you want to modify it? By doing that your data will be changed. PUSH and POP are used for stack based operations. For you other problem regarding freq gen there is a solution. You can change the priority of Serial input.

Edit: If the above code in my last post does not work then you to to do something like this.


Code ASM - [expand]
1
2
3
4
mov A, SBUF
mov R1, A
mov A, SBUF
mov R2, A

 
Last edited:


Hi
Sorry because of heavy rainfall at my location , there was no network from long time. So couldn't reply
:roll:
I used your code wherein after i enter second character both r1 and r2 s holding 2nd character entered.
BTW I'm not entering only two characters, but using pair of entered characters at a time.
Say I enter 'A' Then 'W'
What i want is 'A' gets into R1, Then 'W' into 'R2', ..
now at present I'm concentrating on entering 2 characters ;-)
 

The code I gave is for 2 characters. You can't store as many characters you like in registers as there are only a few registers. You need to store data in some variables.
 

Hi again
Hmmm what your code is doing, is even R1 and R2 holds the recent character( or second character)
Say I entered 'A' Then 'R'
R1='R'
R2='R' .
But I need
R1='R' and R2='A'
I think I have to use pointers. Am i Right??
Please help :}

P.S. About interrupt problem, I resolved long back using IP Thanks

Regards.
 

That is not the actual code. I just showed you how to move the data in SBUF to some register. You have to use that method in your serial interrupt code. Use a counter in interrupt routine and check for the value of counter. If it is 0 (initial value) then move value of SBUF to R1 and then increment the counter. Next time when another byte is received Serially you will check the counter and if counter is 1 then move SBUF to R2, like that. You can use pointers or arrays.
 

Thanks a lot :] I'm gonna try this :}
I've got a new doubt.
Is there any way to store serial port data into some memory and then retrieve them later?? Its just a doubt which clicked into my mind :}
Regards
 

Create an array and load the address of array's first element to DPTR and then every time you receive data through interrupt write data to the array element and increment DPTR so that it points to next element.
Your array should be of sufficient size to hold the data and it depends upon RAM of your MCU.
 

    V

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…