Thaiio.com

Thaiio is the best of PC interfacing Electronic Hardware and Devices resource.

Today , 2007
May 5th, 2008

Programming in Microcontroller to control 8051 through Serial Port

There are fellow programmers that has developed program of Microcontroller inquire about this. It is about the next part of programming for connecting through Serial Port. Either of Visual Basic or C, there are many people inquired about how to control with Microcontroller 8051 that is the family of Microcontroller that has been populating.

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 Serial Port, but there will be programming to control Timer also. Why use Timer? Because we will create Baud Rate, after that we will go to programming to get and send data through Serial Port of Microcontroller

Managing to Timer’s working

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 Serial Port(bit/sec)

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 Serial Port in Microcontroller that will be what mode for getting data and sending data. This SCON, will manage, but we have to set the function to SCON before like the details in the following,

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

 

Serial Port Buffer Register named SBUF 

It is keeper of data for getting or sending data through Serial Port in Microcontroller. If we will write program to get data, we have to move data in Buffer to use.

Such as MOV A, SBUF, etc.

If we will send data out to Serial Port in Microcontroller, we have to move data to Buffer the same. 

Such as MOV SBUF,A or MOV SBUF,#31H, etc.

 Programming to get data

 JNB RI,$            ; compare condition until be real when Buffer Receive already.

CLR RI               ; clear value of RI(Receive Interrupt) bit in SCON Register 

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 Serial Port

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 Microcontroller Serial Port’s working.

2) To know Register for controlling Timer and Serial Port.

3) Can apply program Microcontroller connecting with program on PC through Serial Port

May 5th, 2008

Programming in Assembly to control IO Printer Port Part 2

    In the part 2, we will learn about controlling program Printer Port and Card 8255 I/O Port by Assembly that can be changed to be language of computer by using Assembler program like SXA-51, Cross-16, Cross-32 that can program by Editor, and then keep in file name .ASM. When comply have finished, will get file .Hex. If we use micro controller like 8051, 8052, 8055, etc. We can take file .Hex to put at CPU by EMULATOR PROGRAM CPU, but I will recommend to use Debug in your PC by typing Debug at C:\> on Dos in order to be learning to use mnemonic code that consist of the main 3 parts like the followings,

1.      Operation Code consists of 2-4 alphabets such as MOV, SJMP, etc.

2.      Operand is operated; it will be the set of alphabets that notify operation that will be one set or 2 sets. If there will be 2, it will have comma (,) like A, #20H, etc.

3.      Comment is explanation the meaning of codes that will be preceded by semicolon (;).

The group of commands of mnemonic code, are divided into 4 main groups,

1.      Logic, such as AND,OR,XOR,NOT

2.      Mathematic  such as INC,DEC,ADD,SUBB,MUL,DIV

3.      Control to manage working

4.      Processing as Boolean

 

The table of writing command doing with data

How to do with data

Examples

1. Directly do at memory position
2. Indirectly do at register position
3. Directly give value with memory
4. According to value of Register
5. According to arrangement
6. Do according condition

MOV A,8CH
MOV A,@R1
MOV A,#7FH
MOV A,R7
MOVC A,@A+PC
INC DPTR

 

The table of the basic command of Assembly

Commands

Examples

Meanings

MOV

MOV A,R1
MOV A,14H
MOV A,#7FH
MOV P1,A

Using for transferring data from start to terminal.
there will be P1 is using to send value out at
Output leg of microcontroller such as 8051,Z80

ADD

ADD A,R1
ADD
A,14H
ADD P1,A

Using for adding data that will have A on the left, if Add R1, A <—- X wrong.  

ANL

ANL A,R1

Is to And value, then keep at the terminal.
<– This is doing And value in A with R1, then keeps value in A as usual.

CJNE

CJNE A,#02H,OUT
MOV P1,#01H
END

Is to do comparison, if the value isn’t be equal, it will skip working <– such as value A isn’t be equal with 02, it will skip at the line named OUT, if to be equal, will take value at P1.

OUT

OUT DX,AL

For sending to PC Port

CLR

CLR A

For clearing data as zero
<– A=0

INC

INC R1

Increasing value> R1=R1+1

DEC

DEC R1

Decreasing value > R1=R1-1

JNZ

ADD P1,A

Skipping to other Label, if A(Accumulator) isn’t be zero

ROR

ROR AL,1

Moving data bit to the right, 1 bit 1 time 1=0001—>1000

ROL

ROL AL,1

Moving data bit to the left, 1 bit 1 time 1=0001—>0010

LOOP

LOOP 0123

For looping working at Address 0123

INT20

INT 20

Show output on screen.

INT21

INT 21

Getting value from keyboard.


Programming to control Card I/O 8255 port in Debug

1. Type the word, Debug at C:\ then will get on the below line.
      2. then, type a, that will get data.
      3. Type
Code like this,

   

4. Press Enter 1 time, then type P or R, you will get for running program that continuously Enter, it will have result like this,

 

     

      From the method I mentioned is experiment to easily program, but writing for real using, you have to write Editor so that you can keep and edit in the next time.

May 5th, 2008

Programming in Assembly to control IO Printer Port

From the article of Assembly, I introduced controlling port of Card I/O 8255 that is card that extends parallel port. Many people might not try to do because there is no card. This article is another method that uses controlling I/O through Printer port getting and sending signal.

The command used to control I/O Printer Data Port
send signal out Printer Port, we use the form of command like this,

OUT Address data port, Value
Address data port of
printer=0378
Value that will send to
printer data port, the number that control 8 bit is 00-FF.

OUT DX,AL

Read the rest of this entry »

|
cheapest online diazepam 24 hour delivery cheap levitra rx pills buy lorazepam cheap cialis buy cheapest generic valium purchase new report female zyban order oxazepam prescription cheapest generic xanax viagra order herbal klipal for woman levitra buy drugs online buy herbal tramadol cialis soft tabs levitra cialis best herbal viagra soft tabs uk cialis buy viagra on line viagra levitra women buy cialis online without prescription natural levitra substitutes cheapest generic viagra cyber pharmacy propecia viagra soft tabs studies women
Close
E-mail It