{"id":598,"date":"2022-01-25T13:13:52","date_gmt":"2022-01-25T10:13:52","guid":{"rendered":"https:\/\/ugur-ozgur.gen.tr\/blog\/?p=598"},"modified":"2022-01-25T21:38:01","modified_gmt":"2022-01-25T18:38:01","slug":"8051-serial-repeater","status":"publish","type":"post","link":"https:\/\/ugur-ozgur.gen.tr\/blog\/index.php\/2022\/01\/25\/8051-serial-repeater\/","title":{"rendered":"8051 Serial Repeater"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"2560\" height=\"1440\" src=\"https:\/\/ugur-ozgur.gen.tr\/blog\/wp-content\/uploads\/2022\/01\/IMG_20220125_121148_1-edited-1-scaled.jpg\" alt=\"AT89S51 Serial Test\" class=\"wp-image-604\" srcset=\"https:\/\/ugur-ozgur.gen.tr\/blog\/wp-content\/uploads\/2022\/01\/IMG_20220125_121148_1-edited-1-scaled.jpg 2560w, https:\/\/ugur-ozgur.gen.tr\/blog\/wp-content\/uploads\/2022\/01\/IMG_20220125_121148_1-edited-1-632x356.jpg 632w, https:\/\/ugur-ozgur.gen.tr\/blog\/wp-content\/uploads\/2022\/01\/IMG_20220125_121148_1-edited-1-1020x574.jpg 1020w, https:\/\/ugur-ozgur.gen.tr\/blog\/wp-content\/uploads\/2022\/01\/IMG_20220125_121148_1-edited-1-768x432.jpg 768w, https:\/\/ugur-ozgur.gen.tr\/blog\/wp-content\/uploads\/2022\/01\/IMG_20220125_121148_1-edited-1-1536x864.jpg 1536w, https:\/\/ugur-ozgur.gen.tr\/blog\/wp-content\/uploads\/2022\/01\/IMG_20220125_121148_1-edited-1-2048x1152.jpg 2048w\" sizes=\"(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><figcaption>AT89S51 on breadboard with an empty Arduino UNO board as a USB UART bridge.<\/figcaption><\/figure>\n\n\n\n<p>These two programs send all received data when either there is no space available in the buffer or you press the enter button in the UART terminal.  There is one LED to indicate data transmission.<\/p>\n\n\n\n<!--more-->\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1020\" height=\"574\" src=\"https:\/\/ugur-ozgur.gen.tr\/blog\/wp-content\/uploads\/2022\/01\/8051_serial_repeater_edsim51-1020x574.gif\" alt=\"8051 Serial Repeater EdSim51 Simulation Software\" class=\"wp-image-610\" srcset=\"https:\/\/ugur-ozgur.gen.tr\/blog\/wp-content\/uploads\/2022\/01\/8051_serial_repeater_edsim51-1020x574.gif 1020w, https:\/\/ugur-ozgur.gen.tr\/blog\/wp-content\/uploads\/2022\/01\/8051_serial_repeater_edsim51-632x356.gif 632w, https:\/\/ugur-ozgur.gen.tr\/blog\/wp-content\/uploads\/2022\/01\/8051_serial_repeater_edsim51-768x432.gif 768w, https:\/\/ugur-ozgur.gen.tr\/blog\/wp-content\/uploads\/2022\/01\/8051_serial_repeater_edsim51-1536x864.gif 1536w\" sizes=\"(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><figcaption>EdSim51 Simulation Software<\/figcaption><\/figure>\n\n\n\n<p>There are one Assembly and one C codes available, which are completely identical. In the Keil compiler, C code costs 290 Bytes while Assembly code costs 120 Bytes.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">;8051 ASSEMBLY CODE\n;UART DATA REPEATER\n\nORG 00H\n\tSJMP START\nORG 23H\n\tJBC TI, INTERRUPT_OUTGOING\n\tSJMP INTERRUPT_INCOMING\nORG 30H\nSTART:\n\tACALL SETUP_INCOMING\n\tMOV TMOD, #20H\n\tMOV TH1, #0FDH\t; 9600 BAUD RATE\n\tMOV SCON, #50H\n\tMOV IE, #90H\n\tSETB TR1\nWAIT:\n\tSJMP WAIT\nINTERRUPT_INCOMING:\n\tJNB 20H, INTERRUPT_CANCELED_INCOMING\n\tMOV @R0, SBUF\n\tCLR RI\n\tCJNE @R0, #0DH, CONTINUE_INCOMING\n\tMOV @R0, #0AH\n\tACALL SETUP_OUTGOING\nINTERRUPT_OUTGOING:\n\tJB 20H, INTERRUPT_CANCELED_OUTGOING\n\tMOV SBUF, @R0\n\tCJNE @R0, #0AH, CONTINUE_OUTGOING\n\tACALL SETUP_INCOMING\n\tRETI\nCONTINUE_INCOMING:\n\tCJNE R0, #7EH, CONTINUE_OUTGOING\n\tMOV 7FH, #0AH\n\tACALL SETUP_OUTGOING\n\tSJMP INTERRUPT_OUTGOING\nCONTINUE_OUTGOING:\n\tINC R0\n\tRETI\nINTERRUPT_CANCELED_INCOMING:\n\tCLR RI\nINTERRUPT_CANCELED_OUTGOING:\n\tRETI\nSETUP_INCOMING:\n\tCLR P2.0\n\tSETB 20H\n\tMOV R0, #30H\n\tRET\nSETUP_OUTGOING:\n\tSETB P2.0\n\tCLR 20H\n\tMOV R0, #30H\n\tRET\nEND<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/8051 C CODE\n\/\/UART DATA REPEATER\n\n#include &lt;reg51.h&gt;\n\nsbit LED = P2^0;\nbit state = 1;\nunsigned char pointer = 0;\nunsigned char text[80];\n\nvoid setup_incoming(){\n\tLED = 0;\n\tstate = 1;\n\tpointer = 0;\n}\nvoid setup_outgoing(){\n\tLED = 1;\n\tstate = 0;\n\tpointer = 0;\n}\nvoid interrupt_outgoing(){\n\tSBUF = text[pointer];\n\tif(text[pointer]==0x0A){\n\t\tsetup_incoming();\n\t}\n\telse{\n\t\tpointer++;\n\t}\n}\nvoid interrupt_incoming(){\n\ttext[pointer] = SBUF;\n\tRI = 0;\n\tif(text[pointer]==0x0D){\n\t\ttext[pointer] = 0x0A;\n\t\tsetup_outgoing();\n\t\tinterrupt_outgoing();\n\t}\n\telse{\n\t\tif(pointer==78){\n\t\t\ttext[79] = 0x0A;\n\t\t\tsetup_outgoing();\n\t\t\tinterrupt_outgoing();\n\t\t}\n\t\telse{\n\t\t\tpointer++;\n\t\t}\n\t}\n}\nvoid serial_interrupt() interrupt 4 {\n\tif(TI==1){\n\t\tTI = 0;\n\t\tif(!state){\n\t\t\tinterrupt_outgoing();\n\t\t}\n\t}\n\telse{\n\t\tif(state){\n\t\t\tinterrupt_incoming();\n\t\t}\n\t\telse{\n\t\t\tRI = 0;\n\t\t}\n\t}\n}\n\nvoid main(){\n\tsetup_incoming();\n\tTMOD = 0x20;\n\tTH1 = 0xFD;\n\tSCON = 0x50;\n\tIE = 0x90;\n\tTR1 = 1;\n\twhile(1){}\n}<\/pre>\n\n\n\n<p>I&#8217;ve tested both codes on AT89S51 and verified their functionalities but, these codes comes with ABSOLUTELY NO WARRANTY. It is your own risk to use these codes in your applications.<\/p>\n\n\n\n<p>You must use a 11.0592 MHz crystal on your own circuit to get a proper UART baud rate. Don&#8217;t forget to adjust the value of the TH1 register to get the intended UART baud rate on your own application.<\/p>\n\n\n\n<p>I&#8217;ve used one Arduino UNO board -without Atmega328 IC- as a USB UART bridge and connected to it through PuTTY terminal software. If you don&#8217;t want to set up a physical circuit, you can try these codes on EdSim51 simulation software.<\/p>\n\n\n\n<p>Note: Feel free to ask anything via email or comments which you don&#8217;t understand.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>These two programs send all received data when either there is no space available in the buffer or you press the enter button in the UART terminal. There is one LED to indicate data transmission.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,1,39],"tags":[98,99,4,5,63,17,13,14,102,100,101],"_links":{"self":[{"href":"https:\/\/ugur-ozgur.gen.tr\/blog\/index.php\/wp-json\/wp\/v2\/posts\/598"}],"collection":[{"href":"https:\/\/ugur-ozgur.gen.tr\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ugur-ozgur.gen.tr\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ugur-ozgur.gen.tr\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ugur-ozgur.gen.tr\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=598"}],"version-history":[{"count":11,"href":"https:\/\/ugur-ozgur.gen.tr\/blog\/index.php\/wp-json\/wp\/v2\/posts\/598\/revisions"}],"predecessor-version":[{"id":614,"href":"https:\/\/ugur-ozgur.gen.tr\/blog\/index.php\/wp-json\/wp\/v2\/posts\/598\/revisions\/614"}],"wp:attachment":[{"href":"https:\/\/ugur-ozgur.gen.tr\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ugur-ozgur.gen.tr\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=598"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ugur-ozgur.gen.tr\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}