We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
You know this should be really easy to find but for some reason I am having no luck. First off, I'm a C programmer and I am really bad at reading Assembler code. I know there is a way to write a software UART for the 8051. I am using a Phillips P89C668 right now and I will be changing it to another soon. If someone could point me to some sample code how to setup a half-duplex UART I would really appreciate it. I have two pins and I am going to use one as tx and the other as rx. I don't think I need to do a full duplex but if there is something out there that does it I'll take it at this point! Thanks. -stv
"Everything is in assembler" Don't you think there might be a reason for that...? ;-) Think about it: handling individual bits is essential to the operation of a UART; standard 'C' has no support for handling individual bits. Yes, C51 provides extensions for accessing bit-addressable data, but this certainly sounds like a job best suited to assembler, IMO.
Think about it: handling individual bits is essential to the operation of a UART; standard 'C' has no support for handling individual bits. Andy, I think you are missing the point, I am sure the code could be done in C, but the timing would screw up for sure. Erik
yeah yeah.;. I know .. There is a way to do bit twiddling in C. It's not that hard. And I can convert alot of the code, but it would be nice not to have to rewrite something that is already written.
but it would be nice not to have to rewrite something that is already written. and why on earth would you rewrite? Erik
My company used S/W UART before. THe problem was: each time we changed the clock frequency, we had to re-calibrate the baudrate again .. and it was not an easy task!!! . Because of that, now we have switched to H/W UART on all designs. JIMMY
"There is a way to do bit twiddling in C. It's not that hard." As Erik says, it's not hard for the programmer to write the 'C' code, but bit twiddling in 'C' involves shifting & masking whole bytes. You don't really want to do that in a timing-sensitive application like a UART! "it would be nice not to have to rewrite something that is already written." Again, as Erik says, why would you re-write it? uVision has absolutely no difficulty whatsoever in mixing 'C' and assembler in the same project!
I agree.. It was easy to do it and i did actually write it in C. However, like stated very early by Erik, there were a few (not too many) timing issues that I didn't want to keep coding around so I just mixed in assembler in my C. Ok.. So this is now figured out. Be a good thread for some C coder to read someday! :) Thanks to all.
Sounds like you finished it already.....but as a review you may want to check out the software UART App Note at Silicon Laboratories (formerally Cygnal) at http://www.silabs.com/products/pdf/an115rev1_1.pdf . Its in C !! Michael Karas