BACHELOR OF TECHNOLOGY
-+IN
(2011-2015)
1
ACKNOWLEDGEMENT
This project involved the collection and analysis of information from a wide variety of sources
and the efforts of many people beyond me. Thus it would not have been possible to achieve the
results reported in this document without their help, support and encouragement.
I will like to express my gratitude to the following people for their help in the work leading to
this report:
Ms. Medhavi Singh training supervisors: for their useful comments on the subject matter and for
the knowledge I gained by sharing ideas with them.
CERTIFICATE
ABSTRACT
The primary role of the Microchip PIC and other embedded microcontrollers is to provide
inexpensive, programmable logic control and interfacing to external devices. This means they
typically are not required to provide highly complex functionsthey cant replace the Opteron
processor in your ISPs server. They are well suited to monitoring a variety of inputs, including
digital signals, button presses, and analog inputs, and responding to them using the
preprogrammed instructions that are executed by the built-in computer processor. An embedded
microcontroller can respond to these inputs with a wide variety of outputs that are appropriate
for different devices. These capabilities are available to you at a very reasonable cost without a
lot of effort.
List of Figures
Sr
Title
Page No.
No.
Pic MicroController
Pin Diagram
Core Architecture
MickroC Compiler
Program Formation in compiler
5
11
14
17
20
22
LED Interfacing
7-Segment Display
Interfacing & Control Of Stepper Motor
Interfacing Of LCD
Temperature Monitoring
ADCON0 Register
ADCON1 Register
Switching Action Of PIC Pins
Interfacing Of Keyboard Matrix
Serial Comm. b/w PC &MicroController
TXSTA Register
MikroC UART Terminal Work
PCB Desinging& Simulation Tools
OrCad Layout Plus
TINA PRO
24
25
27
28
29
30
31
32
33
35
37
38
40
42
45
CHAPTER - 1
EMBEDDED SYSTEM
uses are endless, and billions of microprocessors are shipper every year for a myriad of
applications.
In embedded systems, the software is permanently set into a read-only memory such as a ROM
or flash memory chip, in contrast to a general-purpose computer that loads its programs into
RAM each time. Sometimes, single board and rack mounted general-purpose computers are
called "embedded computers".
An embedded system is a computer system designed for specific control functions within a
larger system, often with real-time computing constraints. It is embedded as part of a complete
device often including hardware and mechanical parts. By contrast, a general-purpose computer,
such as a personal computer (PC), is designed to be flexible and to meet a wide range of enduser needs. Embedded systems control many devices in common use today.
An Embedded System is a processor based system that is embedded as a subsystem, in a larger
system.Embedded Systems are computing systems with tightly coupled software & hardware
integration that are designed to perform a dedicated task or functions
Specific
Hardware
task
Software
Embedded systems contain processing cores that are typically either microcontrollers or digital
signal processors (DSP) .The key characteristic, however, is being dedicated to handle a
particular task. Since the embedded system is dedicated to specific tasks, design engineers can
optimize it to reduce the size and cost of the product and increase the reliability and
performance. Some embedded systems are mass-produced, benefiting from economies of scale.
7
Physically, embedded systems range from portable devices such as digital watches and MP3
players, to large stationary installations like traffic lights, factory controllers, or the systems
controlling nuclear power plants. Complexity varies from low, with a single microcontroller
chip, to very high with multiple units, peripherals and networks mounted inside a large chassis
or enclosure.
memory
processor
programmable
logic
interfaces
(serial, network,
etc)
EMBEDDED
PERIPHERALS
i. Embedded Systems talk with the outside world via peripherals, such as:
II.
III.
IV.
V.
VI.
VII.
VIII.
IX.
X.
XI.
Debugging: JTAG, ISP, ICSP, BDM Port, BITP, and DP9 ports.
III.
IV.
V.
VI.
VII.
VIII.
II.
III.
IV.
But in controllers there is a fixed amount of memory which makes them ideal for
many applications.
10
V.
VI.
DISADVANTAGES OF MICROPROCESSORSOVER
MICROCONTROLLERS
I.
II.
III.
II.
I.
PIC Microcontroller
PIC is
family
of modified
derived
by General
from
the
Harvard
by Microchip
PIC1650 originally
Instrument's
Microelectronics
II.
III.
IV.
V.
VI.
VII.
VIII.
Up to 10 MIPS operation
IX.
MHz-10
MHz
oscillator/clock
input
with
PLL
active
Peripheral Features
I.
II.
III.
IV.
V.
VI.
VII.
VIII.
IX.
X.
XI.
XII.
3-wire SPI
XIII.
Supports
interrupt-on-address
III.
Power-On Reset
IV.
V.
bit
VI.
VII.
VIII.
IX.
III.
IV.
V.
VI.
VII.
VIII.
IX.
X.
XI.
XII.
XIII.
XIV.
XV.
CMOS Technology:
I.
II.
III.
IV.
V.
VI.
II.
PIN DIAGRAM
16
PIN Description
MCLR (Pin 1):PIC16F7X devices have noise filter in the MCLR reset path. The
I.
filter will detect and ignore small pulses. It should be noted that a WDT Reset does not
drive MCLR pin low. The behavior of the ESD protection on the MCLR pin has been
altered from previous devices of this family. Voltages applied to the pin that exceed its
specification can result in both MCLR Resets and excessive current beyond the device
specification during the ESD event. For this reason, Microchip recommends that the
MCLR pin no longer be tied directly to VDD.
II.
III.
PORT A (pin 2 to 7) & TRISA Register: PORT-A is a 6-bit wide, bidirectional port. The corresponding data direction register is TRISA. Setting a TRISA bit
(= 1) will make the corresponding PORTA pin an input (i.e. put the corresponding
output driver in a Hi-Impedance mode). Clearing a TRISA bit (= 0) will make the
corresponding PORT-A pin an output (i.e. put contents of the output latch on the selected
17
pin). Reading the PORT-A register reads the status of the pins, whereas writing to it will
write to the port latch.
All write operations are read-modify-write operations. Therefore, a write to a port
implies that the port pins are read; the value is modified and then written to the port data
latch.
IV.
V.
VI.
Oscillator Types:
i.
ii.
iii.
iv.
VII.
PORT-C and the TRISC Register (pin 15 18 and 23-26): PORT-C is an 8bit, bi-directional port. The corresponding data direction register is TRISC. Setting a
TRISC bit (= 1) will make the corresponding PORTC pin an input (i.e. put the
corresponding output driver in a Hi-Impedance mode). Clearing a TRISC bit (= 0) will
make the corresponding PORT pin an output (i.e. put the contents of the output latch on
selected pin). PORT-C is multiplexed with several peripheral functions PORT-C pins
have Schmitt Trigger input buffers. When enabling peripheral functions, care should be
taken in defining TRIS bits for each PORT-C pin.
VIII.
VSS (pin 12): Ground reference for logic and I/O pins.
18
IX.
X.
PORT-B and the TRISB Register (pin 33-40): PORT-B is an 8-bit wide, bidirectional port. The corresponding data direction register is TRISB. Setting a TRISB bit
(= 1) will make the corresponding PORTB pin an input (i.e. put the corresponding out
driver in a Hi-Impedance mode). Clearing a TRISB bit (= 0) will make corresponding
PORTB pin an output (i.e. put the contents of the output latch on the selected pin).
Each of the PORT-B pins has a week internal pull-up. A single control bit can turn on the
pull-ups. The weak pull-up is automatically turned off when the port pin is configured as
an output. The pull ups are disabled on Power-on Reset.
III.
PIC MICROCONTROLLER
CORE ARTITECTURE
PIC is a family of modified Harvard architecture microcontrollers made by Microchip
Technology, derived from the PIC1650 originally developed by General Instrument's
Microelectronics Division. The name PIC initially referred to "Peripheral Interface
Controller".
PICs are popular with both industrial developers and hobbyists alike due to their low cost, wide
availability, large user base, extensive collection of application notes, availability of low cost or
free development tools, and serial programming (and re-programming with flash memory)
capability.
Microchip announced on September 2011 the shipment of its ten billionth PIC processor.
19
CORE ARCHITECTUR
20
i.
ii.
iii.
Most instructions are single cycle execution (4 clock cycles), with a single delay cycles upon
branches and skips.
iv.
A single accumulator (W), the use of which (as source operand) is implied (i.e. is not encoded in
the opcode).
v.
All RAM locations functions are registers as both source and/or destination of math and other
functions.
vi.
vii.
A fairly small amount of addressable data space (typically 256 bytes), extended through
banking.
viii.
ix.
The program counter is also mapped into the data space and writable (this is used to implement
indirect jumps).
Unlike most other CPUs there is no distinction between memory space and register space
because the RAM serves the job of both memory and registers, and the RAM is usually just
referred to as the register file or simply as the registers.
Advantages
The PIC architectures have these advantages:
I.
II.
III.
IV.
Easy entry level, in circuit programming plus in circuit debugging pic kit units available
from Microchip.com for less than $50
V.
Inexpensive microcontrollers
VI.
Wide range of interfaces including PC, SPI, USB, USART, a/d, programmable
comparators, PWM, can Small, PSP, and Ethernet.
22
Limitations
The PIC architectures have these limitations:
I.
One accumulator.
II.
III.
Operations and registers are not orthognal; some instructions can address RAM
and/or immediate constants, while others can only use the accumulato
IV.
PROGRAMMING OF PIC
23
MikroC IDE: PIC and C fit together well; PIC is the most popular 8-bit chip in the world,
used in a wide variety of applications and C prized for its efficiency, is the natural choice for
developing embedded systems. MikroC provides a successful match featuring highly advanced
IDE, ANSI compliant compiler, broad set of hardware libraries, comprehensive documentation,
and plenty of ready-to-run examples.
Write your C source code using the built-in Code Editor (Code and Parameter Assistants, Syntax
Highlighting, Auto Correct, Code Templates and more)
ii.
Use the included mikroC libraries to dramatically speed up the development: data acquisition,
memory, displays, conversions, communications practically all P12, P16 and P18 chips are
supported.
iii.
Monitor your program structure, variables and functions in the code explorer.
24
iv.
Generate commented, human-readable assembly, and standard HEX compatible with all
programmers.
v.
vi.
Inspect program flow and debug executable logic with the integrated debugger.
Get detailed reports and graphs: RAM and ROM map, code statistics, assembly listing, calling
tree and more.
vii.
We have provided plenty of examples for you to expand, develop and use as building bricks in
your projects. Copy them entirely if you deem fit thats why we included them with the
compiler.
ii.
Target device
iii.
iv.
Device Clock.
25
New Project:T he easiest way to create project is by means of New Project Wizard, dropdown menu Project > New Project. Just fill the dialog with desired values (project name and
description, location, device, clock, config word) and mikroC will create the appropriate project
file. Also the empty source file named after the project will be created by default. MikroC does
not require you to have source file named same as the project, its just a matter of convenience.
Edit Project: Later, you can change project settings from the drop down menu Project > Edit
Project. You can rename the project; modify its description, change chip, clock, config word,
etc.
Also mikroC has some pre-defined functions:
Commonly used is:
V.
III.
Programs get a formal structure and can be divided into separate functions.
IV.
Programming and program test time is drastically reduced, this increases efficiency.
V.
Keywords and operational functions can be used that come closer to how humans think.
27
VI.
The supplied and supported C libraries contain many standard routines such as numeric
conversions.
VII.
Reusable code: Existing program parts can be more easily included into new programs, because
of the comfortable modular program construction.
VIII.
The C language based on the ANSI standard is very portable. Existing programs can be quickly
adapted to other processors as needed.
28
The interfacing of LEDs shown in the figure above. It is given VCC through resistors of 330E,
also a darlington pair IC is also used i.e. ULN 2803 which shift the DC level of voltage coming
from the port PIC microcontroller.
Now to glow the desired LED, proper hexadecimal code for its binary is programmed in PIC.
E.g.: To glow alternative LEDs, the binary given code will be 10101010 and its corresponding
hexadecimal code will be 0xAA. So 0xAA is fed to controller with coding.
Also PIC has an internal TRIS register which controls the flow of instructions from the
corresponding port i.e. PORT will behave as input (if =1) and as output (if=0).
PORTC = 0x00;
//initialize PORTC
while(1)
{
PORTC = 0xAA;
delay_ms(1000);
}
}
Thus LED blinking practical is done successfully
A Seven segment display consists of seven LEDs arranged in a pattern of digit like 8.
We use BCD to seven segment decoder which saves a pin of microcontroller from seven (one
for each LED) to four. So we have to give BCD code for desired digit to be displayed on it. Now
also we can display more than one seven segment display simultaneously but it will take a
number of pins of controller, so we use two pins from controller to control the display of seven
segment display one by one from port such that it appears to be displaying simultaneously. This
is done by providing a very small delay such that our eyes cant even detect the change over
from one display to another.
{ portc=arr[i];
for(j=0;j<=9;j++)
{
portb=arr[j];
delay_ms(100);
}
}
}
}
Or
void main() {
inti;
unsigned char arr[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
while(1)
{
trisb=0x00;
for(i=0;i<=9;i++)
{
portb=arr[i];
delay_ms(300);
}
}
}
31
Stepper motor is that which rotates in steps like all motors it is also based on electromagnetic
induction i.e. electric field produces a magnetic field whose variation causes a torque which
rotates the motor.
32
A Stepper motor is brushless, synchronous electric motor that can divide a full rotation into
large number of steps. The motors position can be controlled precisely, without any feedback
mechanism. Stepper motors are similar to switched reluctance motors, which are very large
stepping motors with a reduced pole count and generally are closed loop commutated.
Fundamentals of Operation: Stepper motors operate much differently from normal DC motors,
which rotate when voltage is applied to their terminals. Stepper motors, on the other hand,
effectively have multiple toothed electromagnets (a.k.a. phases) arranged around a central
gear-shaped piece of iron. The electromagnets are energized by an external control circuit, such
as microcontroller. To make the motor shaft turn, first 1 electromagnet is given power, which
makes the gears teeth magnetically attracted to the electromagets teeth.
When the gears teeth are thus aligned to the first electromagnet, they are slightly offset from the
next electromagnet. So when the next electromagnet is turned on and the first is turned off, the
gear rotates slightly to align with the next one, and from the process is repeated. Each of those
slight rotations is called a step. In that way, the motor can be turned a precise angle. Now to
run the motor we have to feed the binary code to turn on the current of that winding.
33
MikroC code:
#define sw1 portb.rb3
#define sw2 portb.rb4
#define sw3 portb.rb5
#define sw4 portb.rb6
#define sw5 portb.rb7
void main()
{
while(1)
{
trisb=0xff;
trisc=0x00;
sw1=sw2=sw3=sw4=sw5=0;
if(sw1==1)
{
portc=0x0a;
//move forward
}
34
else if(sw2==1)
{
portc=0x05;
//move backward
}
else if(sw3==1)
{
portc=0x08;
//move left
}
else if (sw4==1)
{
portc=0x02;
//move right
}
else if(sw5==1)
{
portc=0x00;
//stop
}
else
{
portc=0x00;
}
}
}
The above code will rotate the motor first in forward direction and then in reverse direction.
The stepper motor has been studied successfully.
35
command
signals
and
supply
36
Pin
No
1
2
3
Function
Name
Ground (0V)
Supply voltage; 5V (4.7V 5.3V)
Contrast adjustment; through a
Ground
Vcc
VEE
variable resistor
Selects command register when
Register Select
Read/write
Enable
DB0
DB1
DB2
DB3
DB4
DB5
DB6
DB7
Led+
Led-
potentiometer voltage divider network to get the contrast adjusted. But VDD is always at +5V.
RS, R/W and E
These three pins are numbered 4, 5 and 6 as shown above. RS is used to make the selection
between data and command register. For RS=0, command register is selected and for RS=1 data
register is selected.
R/W gives you the choice between writing and reading. If set (R/W=1) reading is enabled.
R/W=0 when writing.
38
Enable pins is used by the LCD to latch information presented to its data pins. When data is
supplied to data pins, a high to low pulse must be applied to this pin in-order for the LCD to
latch in the data present at the data pins. It maybe noted here that the pulse must be of minimum
450ns wide.
D0-D7
The 8-bit data pins, D0-D7, are used to send information to the LCD or read the contents of
LCD's internal register.
The following paragraph is taken and included from "Muhammad Ali Mazidi",
"To display letters and numbers, we send ASCII code for the letters A-Z, a-z and numbers 0-9
while making RS=1. We also use RS=0 to check the busy flag bit to see if the LCD is ready to
receive information. The busy flag is D-7 and can be read when R/W=1 and RS=0, as follows: if
R/W=1, RS=0. When D7=1 (busy flag=1), the LCD is busy taking care of internal operations
and will not accept any new information. When D7=0, the LCD is ready to receive new
information. It is recommended to check the busy flag before writing any data to LCD"
MikroC Code:
void main()
{
TRISB = 0x00;
LCD_Init(&PORTB);
LCD_CMD(LCD_CLEAR);
//Clear Display
39
40
ii.
iii.
41
ADCON0 Register
42
{
e = ADC_READ(1);
ascii(e);
delay_ms(1000);
}
}
voidascii (unsigned int digit)
{
unsigned char temp;
if(digit<100)
{
temp=digit/10;
LCD_CHR(1, 1, table[temp]);
temp = digit temp*10;
LCD_CHR(1, 2, table[temp]);
}
}
PORT(NAME).F(0-7)
Now pin can be put ON or OFF according to user by the above addressing in the program of
PIC. Internally when the pin is high its flip flop is set. When external switch is closed, it forces
no current or voltage to enter to pin and also lowers the pin from 1 to 0. Thus when the switch is
pressed, the pin becomes zero. The switches whose one end is connected to pins of controlled
are shown below:
#define rw porte.re1
#define en porte.re2
#define sw1 portb.rb3
#define sw2 portb.rb4
#define sw3 portb.rb5
#define sw4 portb.rb6
unsigned char arr1[5]={0x06,0x80,0x01,0x38,0x0e};
unsigned char arr2[8]={"forward"};
unsigned char arr3[9]={"backward"};
unsigned char arr4[5]={"left"};
unsigned char arr5[6]={"right"};
unsigned char arr6[5]={"stop"};
void command()
{
rs=rw=0;
en=0;
delay_ms(100);
en=1;
}
void display()
{
rs=1;
rw=0;
en=1;
delay_ms(100);
en=0;
}
void main()
{
inti;
while(1)
{
46
trisb=0xf8;
trisc=trisd=0x00;
trise=0x00;
adcon1=0x07;
sw1=sw2=sw3=sw4=0;
for(i=0;i<=4;i++)
{
portd=arr1[i];
command();
}
if(sw1==1)
{
portc=0x0a;
//move forward
for(i=0;i<=7;i++)
{
portd=arr2[i];
display();
}
}
else if(sw2==1)
{
portc=0x05;
//move backward
for(i=0;i<=8;i++)
{
portd=arr3[i];
display();
}
}
else if(sw3==1)
{
portc=0x08;
//move left
for(i=0;i<=4;i++)
{
portd=arr4[i];
display();
47
}
}
else if (sw4==1)
{
portc=0x02;
//move right
for(i=0;i<=4;i++)
{
portd=arr5[i];
display();
}
}
else
{
portc=0x00;
//stop
for(i=0;i<=10;i++)
{
portd=arr6[i];
display();
}
}
}
}
if(R3==0 && C1==0)
{
PORTC=9;
}
if(R3==0 && C2==0)
{
PORTC=10;
}
if(R3==0 && C3==0)
{
PORTC=11;
}
if(R3==0 && C4==0)
{
PORTC=12;
}
if(R4==0 && C1==0)
{
PORTC=13;
}
if(R4==0 && C2==0)
{
PORTC=14;
}
if(R4==0 && C3==0)
{
PORTC=15;
}
if(R4==0 && C4==0)
{
51
PORTC=16;
}
}
}
Thus, the keyboard matrix practical is performed.
allows full duplex communication. To change settings we have to re configure TXSTA register.
The Universal Synchronous Asynchronous Receiver Transmitter (USART) module is one of the
two serial I/O modules. (USART is also known as a Serial Communications Interface or SCI.)
The USART can be configured. as a full duplex asynchronous system that can communicate
with peripheral devices, such as CRT terminals and personal computers, or it can be configured
as a half-duplex synchronous system that can communicate with peripheral devices, such as A/D
or D/A integrated circuits, serial EEPROMs, etc.
ii.
iii.
53
Bit SPEN (RCSTA<7>) and bits TRISC<7:6> have to be set in order to configure pins
RC6/TX/CK and RC7/RX/DT as the Universal Synchronous Asynchronous Receiver
Transmitter.
Bit7:
Bit6:
1 Transmit enabled
0 - Transmit Disabled
Bit4:
1 Synchronous mode
0 - Asynchronous mode (we use this mode, so D4 = 0)
Bit2:
1 TSR empty
0 TSR full
Bit0:
55
Now coding
I.
To transmitdata from pc
unsigned char arr[]="cetpainfotech"
void main() {
while(1)
{
inti;
spbrg=0x0f;
rcsta.SPEN=1;
txsta.txen=1;
while(pir1.TXIF==0);
for(i=0;i<=26;i++)
{
txreg=arr[i];
}
II.
trisb=0x00;
trisc=0xf0;
for(i=0;i<=4;i++)
{
portb=arr[i];
command();
}
while(1)
{
spbrg=15;
rcsta=0x90;
while(pir1.rcif==0);
portb=rcreg;
display();
}
}
void command()
{
rs=rw=0;
en=1;
delay_ms(100);
en=0;
}
void display()
{
rs=1;
rw=0;
en=1;
delay_ms(100);
57
en=0;
}
Thus serial communication has been studied successfully.
OrCAD Capture CIS:Capture CIS tool in the OrCAD is programmed to design the
schematics of a circuit. i.e. using this tool, we can design the circuit diagram of any circuit and
select various components we want to apply in that circuit. Capture CIS contains all the
components (Active and Passive) that we need to make a circuit. A circuit designed in Capture
CIS is shown below:
58
OrCAD Layout Plus: In Capture CIS, we can only make the circuit diagram of the circuit we
want to create PCB of. Here is the 2 nd major tool of OrCAD which we use to create PCB design.
Layout Plus imports the files from capture CIS and design the circuit accordingly. The file it
imports is a NETLIST file which contains the information of the nets (wires) and components
attached to them. With the help of information contained in the NETLIST file, layout plus
creates the components footprints and hence it forms the PCB design. A PCB designed in layout
plus is shown as below:
59
TINA Pro:
60
TINA Pro is a software which we can use to test the circuit diagram or the circuit we created.
This is a very useful tool in case of industries. We can test the working of circuit, take its DC
analysis, AC analysis, Transient Responses, Step Responses and Transient Single Shot
Responses etc.
TINA pro also offers us the various measure tools i.e. voltmeter, ampere meter, galvanometer,
multi-meter, oscilloscope etc. using these tools, we can view the voltage, current and other
respective values in the circuit. This will save the cost of the industry which may employ when a
circuit is burnt or damaged. We can test the working of the circuit, simulate it and then make
the final PCB of the circuit without any error. Also the reduction of errors are there in TINA pro.
The simple circuit simulated in TINA pro is shown in the fig. below:
61
REFERENCE
Online Sources:
Google
http://encrypted.google.com
Wikipedia
http://www.wikipedia.com
Engineer garage
http://www.engineergarage.com
Offline Sources:
MicroC Manuals
TINA Pro Help
PIC Datasheets
PIC Microcontrollers for Beginners
62
63