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 4th, 2008

Programming in Visual C++ to connect through IO Serial Port Part#2

From programming in visual c++ to connect through i/o serial port #1 for send and receive data with serial port , In this section ,We will learn controllering program communication with serial port by programming in vc++ 6 to create simple program using basic in the part 1 .

1. New project Microsoft VC++ 6 Read the rest of this entry »

May 4th, 2008

Programming in Visual C++ to connect through IO Serial Port1

The context is the fundamental of programming principle by MS Visual C++ 6 connecting through Serial Port of the computer in sending and getting alphabet. For the form of how to programming that will not have ready-made control that will be used like Visual Basic. In this section, you have to use programming principle as reading and writing data file. Anyhow, the data that will be got and sent out to port is like reading and writing data on file. I prepare the step for understanding in programming like this,

4 steps for connecting Serial Port

1. Set variable for keeping file names, data read (Buffer),file handles, value of getting and sending data.

HANDLE hComm; // handle for COM port
DCB dcb;
// data structure that keep value for connecting serial port
char * chCommPort = “COM1″; // we use com port 1
int valReturn; // keep returning value back in some function.
char chBuffer; // keep alphabet in getting and sending data.
unsigned long nReadPort; //keep returning value back in function, ReadFile
unsigned long nWrittenPort; // keep returning value back in function, WriteFile Read the rest of this entry »

May 3rd, 2008

C++ communicate Parallel Port and Serial Port

C language is the one of good complier for interface program via Serial Port,Parallel Port,Card I/O 8255 with output devices.

Programming Microsoft Visual C++ 6 communicating Parallel Port

Outp(port,bytedata)

Send value out port as byte

Outpw(port,worddata)

Send value out port as word

Such as Outp(0×378,0xF1)

Outpd(port,worddata)

Send value out port as byte double words.

inp(port)

Read value as byte from port

inpw(port)

Read value as word from port.

Such as inpw(0×378)

inpd(port)

Read value as double words from port.

You can notice that the structure of function is like programming by VB because Dll File that is used in VB that is written from C. I will not mention the fundamental of communicating port. Read the rest of this entry »

May 2nd, 2008

C++ communicate Serial Port as polling

I present you about programming by C, version that runs on DOS because there is easier explanation than program as visual that runs on Window that you can notice the article about MS VC++ 6 communicating with Parallel Port and also you can write and try to do by yourself. You can use TurboC because just 1 Mb compiler.

From the part 1, I mentioned about communication as interrupt. In this part, I will present you about communication as polling. The working like this, the flow of data will not be smooth. CPU cannot anticipate that when the new data arrive. It will verify the time with getting and sending data by speed rate that is higher than speed rate that send through keyboard. Read the rest of this entry »

May 2nd, 2008

C++ communicate Serial Port as interrupt

It’s C/C++ in programming to communicate with Serial Port or comport (RS-232). The program I recommend here can communicate between two computers that can send message to each other as interrupt.

For here, we will use Borland C as complier, but you will see me use // that I make for programming explanation. There will be code for reference inter like the following,

Intervector –> use setvect()function for setting the value of IRQ

Intervector –> use getvect()function for the value of IRQ

Intervector –> use for setting of Programmable Interrrupt Controller

Intervector –> use for setting in order to cancel using intervector

Comm Setting –> will use the value in setting rate of Baud rate, the number of bit in transferring data, stop bit, control register FIFO, open DTR-RTS-OUT2. Read the rest of this entry »

May 1st, 2008

Programming in Visual Basic to connect I2C Bus through Serial Port

After studying about communication with data or controlling output devices through Serial Port. In this part, We will learn about programming by Visual Basic through Serial Port for using programming to communicate with Bus system I2C (Inter Integrated Circuit ). You can find more information here http://www.esacademy.com/faq/i2c/.

Why do you have to use this system? Because there will be communication between IC and Module that can order or communicate in many and a long distance that have receiver and sender, the main module or Master to control all working in the system. For another module that is Slave will be controlled. The working of couple modules in this system, will be controlled by 2 signal lines, they have data line and signal line clock in order to use in setting rhythm of working. For taking devices or modules to connect in this system, it can be done by taking module to parallel, will use pressure level of electrical resource in each module will not be equal. 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