There are fellow programmers that has developed program of Microcontroller inquire about this. It is about the next part of programming for connecting through
Anywhere, I do the experimental board by using circuit of the basic Microcontroller in order to carry out this content. Generally, in the side of programming with Microcontroller, I will mention the part of programming to connect
TCON (Time Control Register) and TMOD (Time Mode Register)
We take the both to do for controlling Timer’s working in order to use as looping to measure time taken of Baud Rate, is to set value in TMOD such as TMOD=00100000B. Here, we use getting and sending data 11 bit, will have 8 data bit, Start bit, Stop bit, Custom data bit. All we will set Timer to occur interrupt that we will set at IE (Interrupt Enable Register), setting to be zero every bit, for Baud rate of getting and sending data, will use the rate of Timer Overflow together with the value of SMOD(Serial Mode Register). For the value that will set for Timer in order to create the rate of getting and sending of Serial Port in Microcontroller can use the below table.
The table of setting value for Timer in order to use for Baud Rate
|
Frequency(MHz) |
Baud Rate of |
The value of Timer that will be set |
|
11.059 |
1200 |
E8H |
|
11.059 |
2400 |
F4H |
|
11.059 |
4800 |
FAH |
|
11.059 |
9600 |
FDH |
Programming for setting value of working of Timer
We may conclude programming for setting of Timer such as Baud Rate of Serial port=9600 bit/sec
MOV TMOD,#00100000B ; setting value in TMOD Register to begin the new value automatically.
MOV IE,#00000000B ; setting value not Timer Interrupt
MOV TL1,#FDH ;setting Baud Rate 9600 bit/sec
MOV TH1,#FDH
SETB TR1 ; command Timer 1 to work
Programming to connect with Serial Port
Serial Port Control Register named SCON
Doing as controller of process of getting and sending of
The table of showing the component of SCON
|
The positions of Bit |
Names |
Functions |
|
0 |
RI |
Interrupt in sending data |
|
1 |
TI |
Interrupt in getting data |
|
2 |
TR8 |
Getting data if use Mode 2,3 will be Bit No. 9 |
|
3 |
TB8 |
Sending data if use Mode 2,3 will be Bit No. 9 |
|
4 |
REN |
Setting to get data or not |
|
5 |
SM2 |
If use connect two more Microcontroller |
|
6 |
SM1 |
Choose Mode of parallel port |
|
7 |
SM0 |
Choose Mode of parallel port |
It is keeper of data for getting or sending data through
Such as MOV A, SBUF, etc.
If we will send data out to
Such as MOV SBUF,A or MOV SBUF,#31H, etc.
Programming to get data
MOV A,SBUF ; keep value from Buffer to keep in Register A
Programming to send data
MOV SBUF,#43H ; get ค่าแอสกี้=43H to keep at Buffer in sending data through
JNB TI,$ ; compare condition as real when Buffer Send alreay
CLR TI ; clear value of TI(Transmit Interrupt) bit in SCON Register
From the content I mention above, I think we may understand and can use to program to connect Serial Port of Microcontroller by yourself. For more understanding, I have the project about this content.
Microcontroller connecting with PC as RS-232 through Serial Port
The learning outcome of this article
1) To be the fundamental in programming for controlling the
2) To know Register for controlling Timer and
3) Can apply program Microcontroller connecting with program on PC through