http://www.8051projects.net/mediawiki/index.php?title=8051_Software_UART_Tutorial&feed=atom&action=history
8051 Software UART Tutorial - Revision history
2024-03-28T21:11:24Z
Revision history for this page on the wiki
MediaWiki 1.28.0
http://www.8051projects.net/mediawiki/index.php?title=8051_Software_UART_Tutorial&diff=156&oldid=prev
Ajay Bhargav: /* Help & Queries */
2015-03-03T14:18:21Z
<p><span dir="auto"><span class="autocomment">Help & Queries</span></span></p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr style='vertical-align: top;' lang='en'>
<td colspan='2' style="background-color: white; color:black; text-align: center;">← Older revision</td>
<td colspan='2' style="background-color: white; color:black; text-align: center;">Revision as of 14:18, 3 March 2015</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l119" >Line 119:</td>
<td colspan="2" class="diff-lineno">Line 119:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>If you have any queries, doubts or feedback on this tutorial please share in our [http://www.8051projects.net/forum.html discussion forum].</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>If you have any queries, doubts or feedback on this tutorial please share in our [http://www.8051projects.net/forum.html discussion forum].</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Tutorials]]</div></td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>[[Category:<ins class="diffchange diffchange-inline">8051 </ins>Tutorials]]</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Serial Port Peripherals]]</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Serial Port Peripherals]]</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
</table>
Ajay Bhargav
http://www.8051projects.net/mediawiki/index.php?title=8051_Software_UART_Tutorial&diff=134&oldid=prev
Ajay Bhargav: Initial commit 8051 Soft uart
2015-02-25T11:57:16Z
<p>Initial commit 8051 Soft uart</p>
<p><b>New page</b></p><div>To implement software UART successfully one must understand the basics of UART first and understand its protocol. As mentioned in our UART Basics tutorial. For 8bit, no parity and 1 stop bit UART Transmission, 10 bits are transmitted (startbit, 8-data bits and stop bit). There is a formula to calculate the delay time for 1 bit which is needed between bits to get correct baudrate.<br />
<br />
<code>1 bit time = (((crystal/baud)/12) - 5) / 2</code><br />
<br />
Where crystal is the frequency of crystal in Hz<br />
baud is the required baudrate<br />
we are doing divide by 12 as 8051 architecture single machine cycle is crystal freq/12<br />
<br />
Below is a software implemented UART, which can be used in C as well as Assembly programs. It is written for Keil software. But with a little modification you can use it in your programs.<br />
<br />
<source lang="asm">?SU?PUTC SEGMENT CODE<br />
?SU?GETC SEGMENT CODE<br />
<br />
PUBLIC _putc<br />
PUBLIC getc<br />
<br />
txd_pin EQU P3.1 ;Transmit on this pin<br />
rxd_pin EQU P3.0 ;Receive on this pin<br />
<br />
;Formula to calculate the bit time delay constant<br />
;This constant is calculated as: (((crystal/baud)/12) - 5) / 2<br />
;crystal is the frequency of crystal in Hz<br />
;baud is required baudrate<br />
;Please try to keep baudrate below 9600<br />
;to get best results :)<br />
<br />
BITTIM EQU 45; (((11059200/9600)/12) - 5) / 2<br />
<br />
;--------------------------------------------<br />
;To send data serially<br />
;For C programs<br />
;Protype definition:<br />
; void putc(unsigned char);<br />
;Usage:<br />
; putc(data);<br />
;Return:<br />
; This function returns nothing<br />
;<br />
;For Assembly Programs:<br />
;<br />
;Usage:<br />
; data to be send has to be moved to R7<br />
; for example:<br />
; mov R7,#'a'<br />
; lcall _putc<br />
;--------------------------------------------<br />
RSEG ?SU?PUTC<br />
_putc:<br />
push ACC<br />
Push PSW<br />
mov a,r7<br />
CLR txd_pin ;Drop line for start bit<br />
MOV R0,#BITTIM ;Wait full bit-time<br />
DJNZ R0,$ ;For START bit<br />
MOV R1,#8 ;Send 8 bits<br />
putc1:<br />
RRC A ;Move next bit into carry<br />
MOV txd_pin,C ;Write next bit<br />
MOV R0,#BITTIM ;Wait full bit-time<br />
DJNZ R0,$ ;For DATA bit<br />
DJNZ R1,putc1 ;write 8 bits<br />
SETB txd_pin ;Set line high<br />
RRC A ;Restore ACC contents<br />
MOV R0,#BITTIM ;Wait full bit-time<br />
DJNZ R0,$ ;For STOP bit<br />
POP PSW<br />
pop ACC<br />
RET<br />
<br />
;--------------------------------------------<br />
;To receive data Serially<br />
;If you want to use this routine in your<br />
;C program then define function prototype<br />
; as:<br />
; unsigned char getc(void);<br />
;<br />
; Usage:<br />
; data = getc();<br />
; Return value:<br />
; Returns data received<br />
;<br />
;<br />
;If you are using it in assembly program<br />
; Usage:<br />
; lcall getc<br />
; Return:<br />
; data received is stored in R7<br />
;--------------------------------------------<br />
<br />
RSEG ?SU?GETC<br />
getc: <br />
Push ACC<br />
Push PSW<br />
JB rxd_pin,$ ;Wait for start bit<br />
MOV R0,#BITTIM/2 ;Wait 1/2 bit-time<br />
DJNZ R0,$ ;To sample in middle<br />
JB rxd_pin,getc ;Insure valid<br />
MOV R1,#8 ;Read 8 bits<br />
getc1:<br />
MOV R0,#BITTIM ;Wait full bit-time<br />
DJNZ R0,$ ;For DATA bit<br />
MOV C,rxd_pin ;Read bit<br />
RRC A ;Shift it into ACC<br />
DJNZ R1,getc1 ;read 8 bits<br />
mov r7,a<br />
POP PSW<br />
pop ACC<br />
RET ;go home<br />
</source><br />
Now you can have two serial ports or even 3 :) on a normal 8051. Have a happy programming.<br />
== See Also ==<br />
* [[UART Communication Tutorial]] - Basics of UART<br />
* [[8051 UART/Serial Communication Tutorial]]<br />
* [[AVR UART/Serial Communication Tutorial]]<br />
* [[GPS Receiver Interfacing over UART Tutorial]]<br />
* [[GSM Modem Interfacing over UART Tutorial]]<br />
<br />
== Help & Queries ==<br />
If you have any queries, doubts or feedback on this tutorial please share in our [http://www.8051projects.net/forum.html discussion forum].<br />
<br />
[[Category:Tutorials]]<br />
[[Category:Serial Port Peripherals]]<br />
<br />
{{#seo:<br />
|title=8051 Software UART Tutorial<br />
|keywords=soft uart code, 8051 software uart, 8051 software serial port, keil c software uart, 8051 keil c software uart code, bit-bang uart 8051, keil big bang uart<br />
|description=Learn to implement software uart on 8051 microcontroller in keil assembly. Download sample code for 8051 software serial port.<br />
}}</div>
Ajay Bhargav