You are on page 1of 32

1

THE UNIVERSITY OF ÇUKUROVA


ENGINEERING & ARCHITECTURE FACULTY
ELECTRICAL & ELECTRONICS ENGINEERING DEPARTMENT

GRADUATION THESIS
MICROCONTROLLER BASED AUTOMOBILE

PREPARED BY
EREN ERDAL AKSOY
2000514011

SUPERVISED BY
Assistant Prof. Dr. MUSTAFA GÖK

JUNE 2005
ADANA
2

To my parent
3

ABSTRACT

The Microcontrollers are very popular in electronics and computer controlled


systems overall in the world. Remote control of a system by using computers is applied
to lots of processes. It is very important about reducing the time loss and also cost of
employees.
This thesis presents the controlling of a microcontroller based system using
computer. First of all microcontrollers are introduced. The main differences between
microcontrollers and microprocessors are discussed with reasons. Also, the reasons of
why PICs (Peripheral Interface Controller) are the most popular type of the
microcontrollers are explained. The hardware and software parts of microcontroller
based automobile are clarified comprehensively. The motor drivers, battery control
units, sensor circuits for following a line and displaying units are achieved by using PIC
16F877. One of the most important parts of this thesis is the communication between
PIC microcontroller and computer, so communication protocol is described in depth.
PIC C is used for programming PIC microcontroller and Visual Basic is used for
programming the computer. The thesis concludes with explanations of these programs.
4

CONTENTS

1. INTRODUCTION................................................................................................................ 1
1.1 Microcontrollers......................................................................................................... 1
1.2 Microcontrollers Versus Microprocessors............................................................... 1
1.3 Types of Microcontrollers.......................................................................................... 2
1.4 Programming PIC Microcontrollers......................................................................... 2

2. HARDWARE....................................................................................................................... 3
2.1 Minimum Circuitry for 16F877................................................................................. 3
2.2 Power Supply.............................................................................................................. 4
2.3 Motor Control............................................................................................................. 5
2.4 LCD.............................................................................................................................. 7
2.5 Sensors......................................................................................................................... 8
2.6 Battery Control........................................................................................................... 10
2.7 Serial Communication................................................................................................ 11

3. SOFTWARE......................................................................................................................... 14
3.1 PIC C for Microcontroller........................................................................................ 14
3.2 User Interface............................................................................................................. 21

4. CONCLUSION..................................................................................................................... 26

5.REFERENCES ...................................................................................................................... 27
5

1. INTRODUCTION
Preparation of classical control circuit is very difficult with using transistor, diode,
resistors, capacitors, coil, op-amp and other integrated circuits. To use of these
components in the circuits can increase the cost and occupies places and may decrease
the efficiency. In addition, while setting up these components on the circuit, they can be
affected by temperature and mechanical pressure. Instead of these elements
microcontrollers are preferred. The microcontrollers are so widespread in modern
electronic systems. They are used in a wide number of electronic systems such as:

• Engine management systems in automobiles.


• Electronic measurement instruments (such as multimeters and oscilloscopes)
• Televisions, radios, CD players, tape recording equipment.
• Robotics technology, etc…

In this study PIC 16F877 microcontroller has been used for controlling DC motors,
battery, LCD, etc… Flexibility which is the most important advantage of the
microcontrollers aided about rewriting and improving the programs.

1.1 MICROCONTROLLERS
Microcontroller is a computer on a chip that is programmed to perform almost any
control, sequencing, monitoring and display function. Because of its relatively low cost,
it is a natural choice for design. It performs many of the functions traditionally done by
simple logic circuitry, sequential control circuits, timers or a small microcomputer.

1.2 MICROCONTROLLERS VERSUS MICROPROCESSORS


Microcontroller differs from a microprocessor in many ways. First and the most
important is its functionality. In order for a microprocessor to be used, other
components such as memory, or components for receiving and sending data must be
added to it. In short that means that microprocessor is the very heart of the computer.
On the other hand, microcontroller is designed to be all of that in one. No other external
components are needed for its application because all necessary peripherals are already
built into it. Thus, we save the time and space needed to construct devices.
6

1.3 TYPES OF MICROCONTROLLERS


There are lots of different types of microcontrollers. For example, Intel microcontrollers
(8051), Motorola microcontrollers (68HC11), etc... PIC (Peripheral Interface Controller)
microcontrollers from Microchip are very popular microcontrollers. PICs are easily
programmable cheap microcontrollers. PIC is the name for the Microchip
microcontroller (MCU) family, consisting of a microprocessor, I/O ports, timer(s) and
other internal, integrated hardware. The main advantages are low external part count, a
wide range of chip sizes (from 8-pin up), great availability of compilers and source code
and easy programming. Flash-type devices are reprogrammable in-circuit, while OTP
versions are very cheap to use at the final stage. A wide range of simple programmer
hardware and software is downloadable from the net. With a PIC microcontroller you
can do things that would be difficult to do with discrete logic. Besides its power, you can
easily "change your mind" with a microcontroller. The PIC isn't for every project. It
won't replace a PC, or even a larger processor. But for many jobs it is just the right size,
inexpensive, and doesn't require much in the way of support hardware.

1.4 PROGRAMMING PIC MICROCONTROLLERS


There are nowadays many tools for making programs for PICs. Microchip provides
MPLAB, a free assembler programming environment. Even when you do not want to
use assembler you should get MPLAB, if only for the build-in simulator. Various
companies sell C compilers for PICs. High-Tech C provides PICC-Lite, a free demo
version of their compiler. PICC-Lite targets an number of 16F chips, some with
limitations. There are also compilers for other languages (for example JAL). In this
thesis CCS PIC C is used for programming PIC microcontroller. After writing and
compiling the codes, a different program is used to download the compiled file (.hex file)
into the PIC microcontroller.
7

2. HARDWARE
2.1 MINIMUM CIRCUITRY FOR 16F877
In this thesis PIC 16F877 microcontroller is used. Because it has 8K Flash Program
Memory, 368 bytes RAM, Timers, 10 bits Analog to Digital Converters, 33 I/O ports.
The minimum circuitry for 16F877 is indicated below. 4MHz Crystal and 22pF
capacitors are used for Oscillator. Port 1 is the Master Clear input to reset the PIC.
8

2.2 POWER SUPPLY


The voltage range is form 3V to 5V for 16F877. High sink and source currents are
25mA. So a voltage regulator is used for supplying constant 5V to microcontroller. The
regulator circuit is indicated below. C1 is 330 µF, C2 is 10 µF and C3 is 0.1 µF. A diode
is used to prevent the reverse current. The input voltage range of 7805 is 7~9V, but
output voltage is constant 5V. NiMH Batteries are used because their currents can be
increased up to 2100 mA. Hence we can get enough power for drive motors,
microcontroller, LCD at the same time.
9

2.3 MOTOR CONTROL


The movable part of the automobile consists of two dc motors. These motors must be
driven through any direction. A very popular circuit for driving DC motors is called an
H-bridge. It's called that because it looks like the capital letter 'H' on classic schematics.
The great ability of an H-bridge circuit is that the motor can be driven forward or
backward at any speed, optionally using a completely independent power source. To
power the motor, two switches that are diagonally opposed must be turned on.

In the picture to the right,


think that the high side left
and low side right switches
are turned on. The current
flow is shown in red. The
current flows and the motor
begins to turn in a "positive"
direction.

If the high side right and low


side left transistors are turned
on, then the current flow is on
the other direction which is
drown in green. So the motor
turns in the opposite direction
according to the previous one.
10

Base points of all transistors are connected to the PIC microcontroller. According to the
H-bridge theory, two of transistor bases are ON and others are OFF for each motor.
Also two of the transistors are PNP (BD140) and others are NPN (BD139). BD140 and
BD139 are power transistors that mean they have higher beta β according to the normal
transistors. All resistances are 430 Ω, in this circuit. The motor and transistor
connections to the PIC 16F877 are indicated below.
11

2.4 LCD
LCD (Liquid Crystal Display) is used for informing the user. There is information about
the movements of the automobile, on LCD. 2x8 LCD which has 14 pins is used in this
thesis. With descriptions, 14 pins of LCD are shown in the table, below. 5V is supplied to
the 2nd pin. The 1st Pin is connected to the ground. Also the 3rd pin is used to adjust the
contrast of the LCD. So 2KΩ can be connected to the 3rd pin.

1 Vss, Gnd, 0V 8 Data 1


According to the program,
2 Vcc, +5V 9 Data 2
PIC16F877 sends 4 bit data to
3 Contrast 10 Data 3
the LCD. Because of the type of
4 Register Select 11 Data 4
LCD, we used 4 bit data.
5 Read/Write 12 Data 5
The maximum data length can
6 Enable 13 Data 6
be 8 bit.
7 Data 0, LSB 14 Data 7, MSB

The connection of LCD to PIC 16F877 is indicated below.


12

2.5 SENSORS
The automobile designed in this thesis can detect a black line on white surface. For this
process Reflective Optical Sensor (CNY70) is used. CNY70 has a compact construction
where the emitting light source and the detector are arranged in the same direction to
sense the presence of an object by using the reflective IR beam from the object. The
operating wavelength is 950 nm. The detector consists of a phototransistor and diode
which are indicated below.

The infrared-emitting diode radiates. If there is any object in front of the sensor, then
the phototransistor detects it because of the reflected wave. White color absorbs the light
but black color does not. According to this phenomenon, there will be a current flow
while the sensor detects a black line on the white surface. Then this current will be used
in a comparator circuit to get a high output voltage. This output voltage acts as a pulse
for microcontroller to operate the motors. So according to the color the motors will be
ON or OFF. This method can be used for different aims. For example our automobile
can follow a black line on white surface or it can move in a bounded area.
The sensor circuit is indicated below.
13

There will be always a current flow on the infrared-emitting diode. When the
phototransistor detects an object, the current flow will be on the collector also. This
current is increased by connecting a transistor as a Darlington. In this circuit op-amp
(LM741) acts as a comparator. It has constant 4.4V on the 3rd pin which is reference
voltage. When phototransistor is off, the voltage on the 2nd pin is zero and the output of
the comparator will be zero. So the red led will be turn on. When phototransistor is on
the voltage will increase over 4.4 V and the output of the comparator will be 5V. So the
red led will be turn off and also this output will trigger the microcontroller for changing
the directions of the motors. In this thesis three sensor circuits are used. Each sensor’s
outputs are connected to the microcontrollers as a three different inputs. The sensor
circuit is connected to the microcontroller by a flex cable as an external device.

The connection of the sensor circuit to the PIC 16F877 is indicated below.
14

2.6 BATTERY CONTROL


The automobile has 8 NiMH batteries as a power supply. It is needed to control the
batteries and warn the user when they are low. PIC 16F877 has 8 different 10 bit Analog
to Digital Converters (ADC). The analog input charges a sample and hold capacitor.
The output of the sample and hold capacitor is the input into the converter. The
converter then generates a digital result of this analog level via successive
approximation. The A/D conversion of the analog input signal results in a corresponding
10-bit digital number. In this thesis only one input (RA0) of the microcontroller is used
for analog to digital conversion. Two 10K Ω resistors are connected to the PIC 16F877
as shown below. So, as shown below the analog input is 2,5V. Also the 5V can be
connected to the microcontroller directly. But the current could be high and then
damage the microcontroller.
15

2.7 SERIAL COMMUNICATION


The electrical specifications of the serial port are contained in the EIA (Electronics
Industry Association) RS232C standard. It states many parameters such as,

• A "Space" (logic 0) will be between +3 and +25 Volts.


• A "Mark" (Logic 1) will be between -3 and -25 Volts.
• The region between +3 and -3 volts is undefined.
• An open circuit voltage should never exceed 25 volts. (In Reference to GND)
• A short circuit current should not exceed 500mA. The driver should be able to
handle this without damage.

There are two sizes of Serial Ports. They are the D-Type
25 pin connector and the D-Type 9 pin connector both of
which are male on the back of the PC, thus we will
require a female connector on our device. Below is a
table of pin connections for the 9 pin D-Type connectors.

Pin No. Abbreviation Full Name Function

Pin 3 TD Transmit Data Serial Data Output (TXD)


Pin 2 RD Receive Data Serial Data Input (RXD)
Pin 7 RTS Request To Send This line informs the Modem that
UART is ready to exchange data.
Pin 8 CTS Clear To Send This line indicates that the
Modem is ready to exchange data.
Pin 6 DSR Data Set Ready This tells UART that the modem
is ready to establish a link.
Pin 5 SG Signal Ground Ground
Pin 1 CD Carrier Detect When the modem detects a
"Carrier" from the modem at the
other end of the phone line, this
line becomes active.
Pin 4 DTR Data Terminal This is the opposite of DSR. This
Ready tells the Modem that the UART is
ready to link.
Pin 9 RI Ring Indicator Goes active when modem detects
a ringing signal from the PSTN.
16

RS-232 communication is asynchronous. That is a clock signal is not sent with the data.
Each word is synchronized using it's start bit, and an internal clock on each side, keeps
tabs on the timing.

The diagram above shows the expected waveform from the UART when using the
common 8N1 format. 8N1 signifies 8 Data bits, No Parity and 1 Stop Bit. A transmission
starts with a start bit which is (Logic 0). Then each bit is sent down the line, one at a
time. The LSB (Least Significant Bit) is sent first. A Stop Bit (Logic 1) is then appended
to the signal to make up the transmission. The above diagram is only relevant for the
signal immediately at the UART. RS-232 logic levels uses +3 to +25 volts to signify a
"Space" (Logic 0) and -3 to -25 volts for a "Mark" (logic 1). Any voltage in between
these regions (i.e. between +3 and -3 Volts) is undefined. Therefore this signal is put
through a "RS-232 Level Converter". This is the signal present on the RS-232 Port of
any computer, shown below.

PIC microcontrollers which we


use require either TTL or
CMOS logic levels. Therefore
the first step to connecting the
microcontroller to the RS-232
port is to transform the RS-232
levels back into 0 and 5 Volts.
This is achieved by RS-232
Level Converters. The common
level converter is the MAX-
232. The connection of the
Max232 to the computer is
indicated on the right. RX/TX
Pins of the Max232 is
connected to RX/TX pins of the
microcontroller in order.
Max232 includes a Charge
Pump, which generates +10V
and -10V from a single 5v
supply.
17

Max232 also includes two receivers and two transmitters in the same package. This is
handy in many cases when we only want to use the Transmit and Receive data Lines.
We don't need to use two chips, one for the receive line and one for the transmit line.

The pin connections of PIC16F877 microcontroller, max232 and computer are indicated
above. All the capacitances used in this circuit are equal to 1 µF. Also a serial cable is
used to connect this circuit to the computer. This serial cable is approximately 3 meters
and has 2 female connectors. Hence we must use a male connector for this circuit.
18

3. SOFTWARE
3.1 PIC C FOR MICROCONTROLLER
For programming PIC16F877 microcontroller CCS PIC C is used. PIC C is a kind of C
program developed for PIC microcontrollers. So microcontroller is programmed
according to C logic and rules. The pre-processors and functions used in this program
are explained below.

Pre-Processors
#include < filename > filename is a valid PC filename. It maybe type of PIC or
LCD. Text from the specified file is used at this point of the
compilation.

#use delay( clock=speed ) speed is a constant 1-100000000 (1 Hz to 100 MHz). This


function tells the compiler the speed of the processor and
enables the use of the delay function: delay_ms ( ).

#fuses options This directive defines what fuses should be set in the part
when it is programmed. This directive does not affect the
compilation.

#use rs232 ( ) This directive tells the compiler the baud rate and pins used
for serial I/O. Also it takes effect until another RS232
directive is encountered. This directive enables use of built-in
functions such as GETC, PUTC, and PRINTF.

Discrete I/O Functions


input ( pin ) This function reads the pin. Pins are defined in the devices .h
file. This function returns the state of the indicated pin. If the
pin is low, then the function returns 0, otherwise 1.

output_x ( value ) value is a 8 bit int. This function outputs an entire byte to a
port. PIC 16F877 has 5 ports (port A, B, C, D, E). x is the
port name.
19

set_tris_x ( value ) value is an 8 bit integer with each bit representing a bit of the
I/O port. Each bit in the value represents one pin. 1 indicates
the pin is input and 0 indicates it is output. x is the port
name.

Delay Functions
Delay_ms ( time ) time varies between 0-255. This function will create code to
perform a delay of the specified length. Time is specified in
milliseconds.

A/D Conversion Functions


setup_adc_ports ( value ) value is a constant defined in the devices .h file. It can be a
pin of any port. This function sets up the ADC pins to be
analog, digital or a combination.

setup_adc ( mode ) mode is Analog to digital mode. The valid options vary
depending on the device.

set_adc_channel ( chan ) chan is the channel number to select. Channel numbers start
at 0 and are labeled in the data sheet AN0, AN1.This function
specifies the channel to use for the next READ_ADC call.

read_adc ( ) This function will read the digital value from the analog to
digital converter. setup_adc(), setup_adc_ports() and
set_adc_channel() should be made sometime before this
function is called. The range of the return value depends on
the type of the microcontroller.

RS232 I/O Functions


getc ( ) This function waits for a character to come in over the RS232
RCV pin and returns the character.
20

Printf ( string ) string is a constant string or an array of characters null


terminated. This function outputs a string of characters to
the standard RS-232 pins.

kbhit ( ) If the RS232 is under software control this function returns


TRUE if the start bit of a character is being sent on the
RS232 RCV pin. If the RS232 is hardware this function
returns TRUE is a character has been received and is waiting
in the hardware buffer for getc() to read.

LCD Functions
lcd_init ( ) This function initializes LCD.

lcd_putc ( char ) This function will display char on LCD.

Lcd_goto_xy ( x, y ) Set write position on LCD


21

This is the PIC 16F877 source code of automobile. After compiling these codes, we get
.hex file which will be downloaded to PIC 16F877.
//__________________________________________________________________________
//_________________PIC16F877 Microcontroller Based Automobile_________________
//__________________________________________________________________________
//_________________________Pre-Processors____________________________________
//__________________________________________________________________________

#include <16F877.h> //type of microcontroller…


#include<lcd.c> //needed for using LCD
#fuses XT, NOWDT, NOPROTECT, NOLVP //type of oscillator, etc…
#use delay(clock=4000000) //4MHz crystal is used in oscillator…
#use rs232(baud=9600,parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=8)
//Baud rate, parity bits, number of receiving, transmitting pins, and length of data…

//__________________________________________________________________________
//___________________________Battery Control_________________________________
//__________________________________________________________________________
void battery (void)
{
float battery_value;
setup_port_a( AN0 ); //to define the 1st bit of portA as analog and other as digital input.
setup_adc( ADC_CLOCK_INTERNAL ); //4MHz crystal is used as a clock…
set_adc_channel( 0 ); //means which bit is used as input for reading analog value…

delay_ms(100); //delay 100ms for reading analog data…


battery_value=((2,5*read_adc())/256); //This is the real battery value. Because of having
//10 bit AD Converter and 4MHz crystal, the accuracy is (210-1)/4=256. Also the reference
//voltage is 2.5V.

if(battery_value<=2.1) //Sends data to the PC according to the value of battery…


printf("L"); // “L” means Low…
else if(battery_value>=2.3)
22

printf("H"); // ”H” means High…


else
printf("N"); // “N” means normal...
}

void open_lcd (void) // displaying slide writings…


{
int x;
lcd_putc("\f"); //clears display…
for(x=8;x>0;x--)
{ lcd_gotoxy(x,1);
lcd_putc("CUKUROVA"); //puts character on LCD…
lcd_gotoxy(x,2);
lcd_putc(" UNI. ");
delay_ms(500);
}}
void forward (void)
{
output_b(0x33); //causes motors turn clockwise direction…
lcd_putc("\f MOVING ");
lcd_putc("\nFORWARD ");
}

void back (void)


{
output_b(0xCC); //causes motors turn counterclockwise direction…
lcd_putc("\f MOVING ");
lcd_putc("\n BACK ");
}

void right (void)


{
output_b(0x3C); //causes the motors turns opposite directions according to each other.
lcd_putc("\fTURNING ");
23

lcd_putc("\n RIGHT ");


}

void left (void)


{
output_b(0xC3); //causes the motors turns opposite directions according to each other.
lcd_putc("\fTURNING ");
lcd_putc("\n LEFT ");
}

void stop (void)


{ output_b(0x00); //stops all motors…
lcd_putc("\f STOP ");
delay_ms(2000);
lcd_putc("\fCUKUROVA");
lcd_putc("\n UNI. "); }
void manual (void) //to control the automobile on computer…
{
battery(); //send the battery value to the PC…
lcd_putc("\f MANUAL ");
lcd_putc("\nCONTROL ");
}

void exit (void)


{
output_b(0x00); //stops all motors…
open_lcd();
}

void line_follow (void) //receives the sensors outputs as inputs and control the
//motors according to these inputs…
{
lcd_putc("\f LINE ");
lcd_putc("\n FOLLOW ");
24

battery();
output_b(0x00); //firstly, stops all motors…

while(TRUE)
{
if(input(pin_e0)) //controls the first sensor output…
output_b(0x33); //drives motors forward…
else if(input(pin_e1)) //controls the second sensor output…
output_b(0x3C); //changes motor directions to turn right…
else if(input(pin_e2)) //controls the third sensor output…
output_b(0xCC); //changes motor directions to turn left…
else
output_b(0x00); //if all sensor outputs are low, then motor stops…
if(kbhit() && (getc()=='S' )) break; //waits until receiving char ‘S’ from PC…
}
}
void main()
{
unsigned char selection;
lcd_init(); //for initializing LCD…
battery(); //controls the battery value and sends it to the PC…

set_tris_b(0x00); //sets port B as an output for motors…


output_b(0x00); //causes all bits of port B being low…
open_lcd();

while(TRUE)
{
while(!kbhit()); //waits until receiving data from PC…
selection=getc(); //receiving data from PC…

switch(selection)
{
case 'F': forward(); break; //forward movement…
25

case 'B': back(); break; //backward movement…


case 'R': right(); break; //turning right…
case 'L': left(); break; //turning left…
case 'S': stop(); break; //stops the automobile…
case 'M': manual(); break; //controlling the motors on PC…
case 'X': line_follow(); break; //following a line…
case 'E': exit(); break; //exit…
}
}
}
26

3.2 USER INTERFACE


Programming computer for serial communication is as important as programming PIC
microcontroller. In this thesis serial programming of computer is achieved by using
MSComm component of Visual Basic. MSComm is used for any type of adjustments
about serial ports. The basic functions of MSComm and Visual Basic used in this
program are clarified below.

Components of MSComm
CommPort Defines number of serial communication port. COM1,
COM2, COM3, etc…

PortOpen Activates serial port.

RThreshold Defines the number of input character which causes


program jumping OnComm subprogram.

Settings Defines features of serial port. Adjusts of Baud rate, length


of data, number of stop bits, etc…

Input Reads data from input buffer.

InBufferSize Adjusts the input buffer length.

comEvReceive Returns 1 while receiving data from serial port.

Output Sends data from computer by serial port.

Other Functions
Timer Writes the date and hour on the user form.

Text Receives data from the user.

MsgBox Gives a message to the user.


27

According to these functions and components, the user interface is programmed and
designed. The program is indicated blow.
‘__________________________________________________________________________
‘________________________The User Interface__________________________________
‘__________________________________________________________________________
Private Sub Form_Load()
MSComm1.Settings = "9600, N, 8, 1" ‘Baud rate is 9600, no parity bit is used,
‘only one stop bit is used, data length is 8 bits…
MSComm1.CommPort = 2 ‘COM2 is selected…
MSComm1.InBufferSize = 1 ‘for receiving only one bit data…
MSComm1.RThreshold = 1 ‘jumps to subprogram after receiving one bit data...
MSComm1.PortOpen = True ‘opens the port…
Timer1.Interval = 1 ‘timing interval is 1 ms…
Timer1.Enabled = True ‘timer is enabled…
Text1 = "select a control method, please..."
End Sub

Private Sub MSComm1_OnComm()


Dim newdata As String
If MSComm1.CommEvent = comEvReceive Then ‘receives battery value from PIC.
newdata = MSComm1.Input
If newdata = "L" Then ‘If the PIC sends char “L”,
Text3 = "Low" ‘then the user is informed that battery is Low…
Text4 = ""
Text5 = ""
ElseIf newdata = "H" Then ‘If the PIC sends char “H”,
Text3 = "" ‘then the user is informed that battery is High…
Text4 = ""
Text5 = "High"
Else
Text3 = ""
Text4 = "Normal" ‘otherwise the user is informed that battery is Normal…
Text5 = ""
End If
28

End If
End Sub

Private Sub manual_Click()


If MSComm1.PortOpen = False Then ‘If port is close,
MSComm1.PortOpen = True ‘then, opens the port…
End If
MSComm1.Output = "M" ‘sends char “M” to the PIC for manual control…
Text1 = "use manual control buttons, please..."
End Sub

Private Sub linefollow_Click()


If MSComm1.PortOpen = False Then ‘If port is close,
MSComm1.PortOpen = True ‘then, opens the port…
End If
MSComm1.Output = "X" ‘sends char “X” to the PIC for following a line…
Text1 = "press stop button to exit..."
End Sub

Private Sub exit_Click()


If MSComm1.PortOpen Then ‘If port is open,
MSComm1.Output = "E" ‘sends char “E” to the PIC to exit…
MSComm1.PortOpen = False ‘then, closes the port…
End If
End
End Sub

Private Sub forward_Click()


If MSComm1.PortOpen Then ‘If port is open,
MSComm1.Output = "F" ‘sends char “F” for forward moving…
Text1 = "moving forward..."
Else ‘otherwise warns the user…
MsgBox ("press manual control, please...")
End If
29

End Sub

Private Sub right_Click()


If MSComm1.PortOpen Then ‘If port is open,
MSComm1.Output = "R" ‘sends char “R” for turning right…
Text1 = "turning right..."
Else ‘otherwise warns the user…
MsgBox ("press manual control, please...")
End If
End Sub

Private Sub left_Click()


If MSComm1.PortOpen Then ‘If port is open,
MSComm1.Output = "L" ‘sends char “L” for turning left…
Text1 = "turning left..."
Else ‘otherwise warns the user…
MsgBox ("press manual control, please...")
End If
End Sub

Private Sub back_Click()


If MSComm1.PortOpen Then ‘If port is open,
MSComm1.Output = "B" ‘sends char “B” for moving backward…
Text1 = "moving backward..."
Else ‘otherwise warns the user…
MsgBox ("press manual control, please...")
End If
End Sub

Private Sub stop_Click()


If MSComm1.PortOpen Then ‘If port is open,
MSComm1.Output = "S" ‘sends char “S” to stop…
Text1 = "stop..."
Else ‘otherwise warns the user…
30

MsgBox ("press manual control, please...")


End If
End Sub

Private Sub Timer1_Timer ()


Text2 = Now ‘timer is on…
End Sub

‘__________________________________________________________________________
‘__________________________________________________________________________

The compiled form of the user interface is indicated below.


31

CONCLUSION

In this paper, PIC16F877 microcontroller based automobile was designed and


programmed. This automobile has lots of functionalities. It can be controlled using serial
port. For implementing this property, a user interface was designed with Visual Basic.
This automobile can control its battery and warns the user. LCD is used for informing
the user about all movements of the automobile. Another property is following a black
line on a white surface. Because of the flexibility of PIC microcontroller, some properties
can be improved by modifying the program. For example this automobile can move in a
bounded area after changing some codes. Also, this thesis can be used for different
applications in industry. After adding a robot arm on this automobile, a dangerous
process can be done in safety.
32

REFERENCES

[1] PIC 16F877 Data Sheet, Microchip Technology Inc., 2001. www.microchip.com

[2] “Interfacing the Serial/RS232 Port v5.0”, http://www.senet.com.au/~cpeacock

[3] Prof. Dr. Doğan İbrahim, “PIC ve PC iletişim Projeleri”, 2004, Bileşim yayınevi.

[4] www.antrak.org.tr

[5]www.endtas.com

[6] www.robot.metu.edu.tr

You might also like