Introduction: 16F84 SERIAL COMMUNICATIONS

Picture of 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 .

Note:

This is an old project I've made long time ago and wanted to share with you on instructables.. This is about an old Microcontroller chip 16F84A. But I still use this chip on my projects.

Let's begin.

Wish you the best. And have fun ,Live free And Read Books on Amazon

Step 1: Theoretical Background

Picture of Theoretical Background

In old Microcontrollers like 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.

Step 2: Connection and Circuit

Picture of Connection and Circuit

The web page clearly explains this method . The PIC 16f84A 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?

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 on the simulator first before building it.

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 circuit 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 is done by the PWM DC motor control signals.

Components:

PIC 16F84A Amazon US , Amazon CA , Amazon UK , Amazon DE , Amazon FR , Amazon ES , Amazon IT , Banggood , Aliexpress , eBay

9 PIN Connector Amazon US , Amazon CA , Amazon UK , Amazon DE , Amazon FR , Amazon ES , Amazon IT , Banggood , Aliexpress , eBay

4MHz Crystal Oscillator Amazon US , Amazon CA , Amazon UK , Amazon DE , Amazon FR , Amazon ES , Amazon IT , Banggood , Aliexpress , eBay

2N2222 Transistor Amazon US , Amazon CA , Amazon UK , Amazon DE , Amazon FR , Amazon ES , Amazon IT , Banggood , Aliexpress , eBay

DC Motor Amazon US , Amazon CA , Amazon UK , Amazon DE , Amazon FR , Amazon ES , Amazon IT ,Banggood , Aliexpress , eBay

9 V Battery Amazon US , Amazon CA , Amazon UK , Amazon DE , Amazon FR , Amazon ES , Amazon IT , Banggood , Aliexpress , eBay

9 V Battery Connector Amazon US , Amazon CA , Amazon UK , Amazon DE , Amazon FR , Amazon ES , Amazon IT , Banggood , Aliexpress , eBay

1K Ohm Resistor Amazon US , Amazon CA , Amazon UK , Amazon DE , Amazon FR , Amazon ES , Amazon IT , Banggood , Aliexpress , eBay

10K Ohm Resistor Amazon US , Amazon CA , Amazon UK , Amazon DE , Amazon FR , Amazon ES , Amazon IT , Banggood , Aliexpress , eBay

Step 3: Connection to the PC Side

Picture of Connection to the PC Side

You can write a simple software for the PC that reads from the PC's serial port ( Com 1 or Com 2 ) . Or you can simply open the famous program Hyper terminal that comes with all Microsoft windows versions under the menu

Programs --> Accessories --> Communications --> Hyper Terminal. 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.

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 .

Step 4: Embedded Software

Picture of Embedded Software

You can find the full code in the attached file with the simulation and schematics files.

Here is a little piece of code.

#include

#include "rs232.c"

__CONFIG(WDTDIS & XT & UNPROTECT);

# define Motor_PIN RB1

void PWM_STOP(); void PWM_LOW(); void PWM_MID(); void PWM_HIGH();

unsigned char c ;

int Duty = 0 , t = 0 , period = 2000 ;

main(void) { TRISA = 0b00000001; TRISB = 0b00000001; PORTA = 0; PORTB = 0;

rs232_initialize();

rs232_send_string(" Hello Abohmeed");

rs232_send_char(NL); // NEW LINE

rs232_send_char(CR); // CARRIGE RETURN

rs232_send_char(NL); // NEW LINE

rs232_send_char(CR); // CARRIGE RETURN

rs232_send_string(" Please enter Motor Speed : 0 STOP , 1 LOW , 2 MID , 3 HIGH ");

Step 5: Run Your Circuit

Picture of Run Your Circuit

Now you can run your simulator and run the real circuit.

Connect to the PC and Run Hyper Terminal.

Follow the instructions that appears on the Terminal window.

Have Fun....

Thank you for reading my instructable..

You can read this article on my blog:

http://embedded-egypt.blogspot.com.eg/2010/07/16f8...

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

You can read this post in Arabic Language

http://arabic-embedded-egypt.blogspot.com.eg/2010....

Wish you the best. And have fun ,Live free And Read Books on Amazon

Comments

About This Instructable

428views

12favorites

License:

Bio: For me, instructables is more than a website. It is a lifestyle. It gave me the chance to live my dream. Share what I do ... More »
More by ahmedebeed555:I Made the Flying Battery - Simplest Bi-rotor PlaneSimple Solar Car in 5 MinutesAncien PC ventilateur ------> éolienne en 10 minutes
Add instructable to: