Saturday, July 24, 2010

16F84 SERIAL COMMUNICATIONS



In many projects exists the need to exchange information with outside world. This case can be the need to store information from your project to a database on a standard PC or a need to communicate with another device. RS232 is widely used serial communications protocol. Modern Microcontroller chips contain hardware modules for such communications protocol. In those chips all you have to do is configuring the RS232 module and to choose the right crystal to produce the desired baud rate .



But in Microcontroller as 16F84A there is no such hardware communications modules. Serial communication can be established by software or Bit-Bang method. The standard RS232 protocol uses +12v to represent logic 0 and -12v to represent logic 1 . While TTL uses +5v to represent logic 1 and 0 V to represent logic 0.

An external IC is used as an interface between the Microcontroller and an RS232 enabled device ( PC for example ) .This IC MAX232 or HIN232 performs this level shifting function between the RS232 and TTL protocols.


Recently , I found a website implementing RS232 protocol in software using C language. The new method represented in this website is using the inverted logic ( 0v for logic 1 and +5v for logic 0 ) .

This method enables connection of the Microcontroller directly to the PC. The web page clearly explains this method . The PIC 16f8A can withstand +12v and -12v when receiving data from PC . And for data transmission to PC 0v to +5v can be distinct by the PC as two different levels.


I really wanted to try this code in real world and built the simple circuit as shown in the web page. The designer recommends connecting a resistor for PIC protection .


Of course , you can find that it is a very simple circuit that provides another new usage for the PIC 16F84A.


So how can you use the serial data form the Microcontroller ?

You can write a simple software for the PC that reads from the PC's serial port ( com1 or com2 ) . Or you can simply open the famous program Hyper terminal that comes with all Microsoft windows versions under the menu Programs --> Accessories --> Communications --> HyperTerminal. Then you need to configure the right Com port , Baud rate and Flow control . As shown here








I used a serial connector from an old mouse to connect the circuit board to the PC .




Here is the pinout of the 9 pin serial connector




This is the Hyper terminal program showing "Hello World" message from the Microcontroller .


This is the schematic drawing of the circuit




Here is the real circuit board I built and the serial connector connected to it .


Here, we 'll use the serial communication protocol RS232 to adjust the Microcontroller which in turn controls a DC motor by the PWM signals.

By choosing the motor speeds and sending them to the Microcontroller, we are able to choose PWM signals duty cycles and sending them to the Microcontroller via RS232 protocol.

The ciruit between the Microcontroller and the PC is very simple. All you have to connect is the PIC16F84A ,the crystal oscillator and the RS232 9 pin female connector.

The Microcontroller is supplied by the 12V DC from RS232 pin 7 RTS. Do not be afraid of losing the PIC chip, it can withstand it without damage.

The PIC16F84A Tx pin 1 is connected directly to RS232 pin 2 Rx.

The PIC16F84A Rx pin 17 is connected to RS232 pin 3 Tx through 10k ohm resistor to adjust the input voltage to the PIC.

The motor driving part of the circuit has already been explained in the PWM DC motor control post. So I 'll use the same driving circuit.

The PWM signal comes from the PIC16F84A to the NPN 2N2222 transistor base. This transistor acts as an electronic switch.

The DC motor is driven by an external DC 9v battery.



This image shows the Proteus 7 Model of the project


As usual , you may want to try the code and the circuit om the simulator first before building it . So , you 'll find the Proteus 7 model and code in this link . But to properly send and receive data form PIC 16F84A to the virtual terminal model in Proteus 7 environment it must be configured to use inverted data . You 'll find that I configured this for the model . But if you want to see it for yourself , right click on the virtual terminal model and choose inverted .


يمكنك قراءة هذه المقالة باللغة العربية

You can read this post in Arabic Language





If you like this blog you can support us by many ways:
   
   1. Leave comments stating your point of view about this article.

   2. Buy our book on Amazon Learn By Making.

   3. Click on links of our sponsors without adding any extra cost on you if you make purchase from them. Actually, many of these offers are totally free.
This means that you can enjoy something for free and still support our blog to keep posting useful stuff.


Amazon.com - Read eBooks using the FREE Kindle Reading App on Most Devices


This is the well-know Amazon Kindle platform. If you sign up for the free reader from Amazon to read any book, we get commission. 
There are many useful book for free on Amazon Kindle. Even you can find best sellers offered for free on Kindle format.
The best part is you can have the application on any platform. You can even read any book without installing any application by using Amazon Cloud-Reader on your browser.


Join Amazon Kindle Unlimited 30-Day Free Trial

You can join Amazon Kindle for 30 days free to have access to many paid book for free. You can cancel you subscription anytime.


Try Amazon Prime 30-Day Free Trial


The Amazon Prime is a special paid service from Amazon that offers good promotions and one-day free shipment for Amazon Shoppers. You can try this service for 30 days. You can cancel you subscription anytime.

Shop Amazon - Give the Gift of Amazon Prime


Try Audible and Get Two Free Audiobooks


Audible is the audio books website from Amazon. Many Kindle books are sold on Audible. You can try this service for free and get 2 free book. You can cancel you subscription anytime.


Shop Amazon - Create an Amazon Baby Registry

If you have a new baby borne or expecting one, you can create your free baby registry to easily save products and get offers and promotions on baby requirements.

  4. Visit our new website outatime.tech.

Thank you for visiting our blog.

No comments: