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

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 »

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

Programming in Visual C++ 6 to connect with I/O Parallel Port

I have already mentioned the content about C, C++, connecting with PC Port. It’s not too hard. It’s hard at graphics that we write to put together with using, especially program ran on DOS. In this present, programming as Visual is populating because it can be GUI conveniently and not too hard. So, I try to use Microsoft Visual Basic 6 that is in Microsoft Visual Studio 6, for function and step of programming code for connecting port is not much because wizard program of MS VC++6, is created all for us.

In this program, we will use file conio.h that is include file for using function _outp() and _inp()

In this section, I will do as explanation with pictures (Visual Learning), controlling with messages and the arrange of number shown because if you write explanation as the last contexts, you will be hard to understand. 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

Creating DLL file by Borland Delphi, connecting IO Parallel Port

As we know that VB can’t program to connect through Parallel Port directly. In the book, there will be explanation that we create DLL files that can write by using whatever language that has the function connecting to port. This website I have ever presented programming by C++, using Inp function for getting value along port and out is sending value out along port.

So now, we will introduce creating DLL file (Dynamic LInk LIbrary) by Borland Delphi, using Assembly programming to help for connecting through port by using the function of Assembly.

IN AL,DX

Get value at port’s position according to value in DX that is kept at AL

OUT DX,AL

Send value in AL to port’s position according to value in DX

Read the rest of this entry »

April 30th, 2008

Programming in Visual Basic to connect modem by using MSComm6

As I mention about modem, it is modem for internet. Usually, working to connect with modem will have processed program for use, but if experiment for knowledge for one who like programming, it will be useful. It can apply for many.

 

This article will be the fundamental of step of programming and protocol command that is used for Dial-Up Phone, so we begin to know about protocol of modem first.

 

The protocol for connecting with modem

 

For connecting with modem, will have command according to standard of industry that produce modem, is protocol called AT Command in order to send command for controlling or get data from modem. Maybe, there is different command; we can see the form of command from manual of each modem that is bought. For command that is sent to control at modem that we will program, it has AT Command that must be used in the followings, Read the rest of this entry »

April 29th, 2008

Programming in Visual Basic to control through network part 4

We have got to know the contents about sending message through TCP/IP. So, we may understand how to use Winsock to connect via TCP/IP. So now, we program in order to send via data, so, we have to firstly make understanding by dividing data file into 2 types in the following.
•    Sequential File
•    Random File
In this content, we mention how to manage file as Random File that has more advantage than Sequential File. It can be quickly opened by not arranging data as Sequential File and enter to Record.  Read the rest of this entry »

« Previous Entries |
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