0% found this document useful (0 votes)
21 views17 pages

Embedded Systems

Uploaded by

yonasamare126
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views17 pages

Embedded Systems

Uploaded by

yonasamare126
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Embedded Systems

Introduction: An embedded system is a device that has one or more computers embedded
within it, which exercise primarily a control function.
• The embedded computer is usually a microcontroller: a microprocessor adapted for embedded
control applications.
• Microcontrollers are designed according to accepted electronic and computer principles, and
are fundamentally made up of microprocessor core, memory and peripherals; it is important to be
able to recognize their principal features.
Microcontrollers
A microcontroller, is a single IC containing specialized circuits and functions that are applicable
to mechatronic system design. It contains a microprocessor, memory, I/O capabilities, and other
on-chip resources. It is basically a microcomputer on a single IC. Examples of microcontrollers
are Microchip’s PIC, Motorola’s 68HC11, and Intel’s 8096. Factors that have driven
development of the microcontroller are low cost, versatility, ease of programming, and small
size. Microcontrollers are attractive in mechatronic system design since their small size and
broad functionality allow them to be physically embedded in a system to perform all of the
necessary control functions.
Microcontrollers are used in a wide array of applications including home appliances,
entertainment equipment, telecommunication equipment, automobiles, trucks, airplanes, toys,
and office equipment. All these products involve devices that require some sort of intelligent
control based on various inputs. For example, the microcontroller in a microwave oven monitors
the control panel for user input, updates the graphical displays when necessary, and controls the
timing and cooking functions. In an automobile, there are many microcontrollers to control
various sub-systems, including cruise control, antilock braking, ignition control, keyless entry,
environmental control, and air and fuel flow. An office fax machine controls actuators to feed
paper, uses photo sensors to scan a page, sends or receives data on a phone line, and provides a
user interface complete with menu-driven controls. A toy robot dog has various sensors to detect
inputs from its environment (e.g., bumping into obstacles, being patted on the head, light and
dark, voice commands), and an onboard microcontroller actuates motors to mimic actual dog
behavior (e.g., bark, sit, and walk) based on this input. All of these powerful and interesting
devices are controlled by microcontrollers and the software running on them.
The figure below shows a block diagram for a typical full-featured microcontroller. Also
included in the figure are lists of typical external devices that might interface to the
microcontroller. The components of a microcontroller include the CPU, RAM, ROM, digital I/O
ports, a serial communication interface, timers, A/D converters, and D/A converters. The CPU
executes the software stored in ROM and controls all the microcontroller components. The RAM
is used to store settings and values used by an executing program. The ROM is used to store the
program and any permanent data. A designer can have a program and data permanently stored in
ROM by the chip manufacturer, or the ROM can be in the form of EPROM or EEPROM, which
can be reprogrammed by the user. Microcontroller manufacturers offer programming devices
that can download a compiled machine code file from a PC directly to the EEPROM of the
microcontroller, usually via the PC serial port and special-purpose pins on the microcontroller.
These pins can usually be used for other purposes once the device is programmed. Additional
EEPROM may also be available and used by the program to store settings and parameters
generated or modified during execution. The data in EEPROM is nonvolatile, which means the
program can access the data when the microcontroller power is turned off and back on again.

Figure: Component of a typical full-featured microcontroller


The digital I/O ports allow binary data to be transferred to and from the microcontroller using
external pins on the IC. These pins can be used to read the state of switches and on-off sensors,
to interface to external analog-to-digital and digital-to-analog converters, to control digital
displays, and to control on-off actuators. The I/O ports can also be used to transmit signals to and
from other microcontrollers to coordinate various functions. The microcontroller can also use a
serial port to transmit data to and from external devices, provided these devices support the same
serial communication protocol.
The A/D converter allows the microcontroller to convert an external analog voltage (e.g., from a
sensor) to a digital value that can be processed or stored by the CPU. The D/A converter allows
the microcontroller to output an analog voltage to a non-digital device (e.g., a motor amplifier).
Onboard timers are usually provided to help create delays or ensure events occur at precise time
intervals (e.g., reading the value of a sensor).

Programmable Interface Controller (PIC)

A programmable Interface Controller (PIC) microcontroller is a single chip computer. Micro


suggests that the device is small, and controller suggests that it is used in control applications.
Another term for microcontroller is embedded controller, since most of the microcontrollers are
built into (or embedded in) the devices they control. A microprocessor differs from a
microcontroller in a number of ways. The main distinction is that a microprocessor requires
several other components for its operation, such as program memory and data memory, input-
output devices, and an external clock circuit. A microcontroller, on the other hand, has all the
support chips incorporated inside its single chip. All microcontrollers operate on a set of
instructions (or the user program) stored in their memory. A programmable interface controller
is also a solid state control system that continuously monitors the status of devices connected as
in puts. Based upon a user written program, stored in memory, it controls the status of devices
connected as out puts. 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.

Advantages of PIC

The PIC architectures have these advantages:

 Small instruction set to learn


 RISC architecture
 Built in oscillator with selectable speeds for PIC18F families.
 Inexpensive microcontrollers
 Wide range of interfaces including, SPI, USB, USART, A/D, programmable
comparators, PWM, LIN, CAN, PSP, and Ethernet
 Availability of processors in DIL package makes them easy to handle for hobby use.

Historical background of PIC

The original PIC was built to be used with General Instrument's new 16-bit CPU, the CP1600.
While generally a good CPU, the CP1600 had poor I/O performance, and the 8-bit PIC was
developed in 1975 to improve performance of the overall system by offloading I/O tasks from
the CPU. The PIC used simple microcode stored in ROM to perform its tasks, and although the
term was not used at the time, it shares some common features with RISC designs. In 1985,
General Instrument spun off their microelectronics division and the new ownership cancelled
almost everything — which by this time was mostly out-of-date. The PIC, however, was
upgraded with internal EPROM to produce a programmable channel controller and today a huge
variety of PICs are available with various on-board peripherals (serial communication modules,
UARTs, motor control kernels, etc.) and program memory from 256 words to 64k words and
more (a "word" is one assembly language instruction, varying from 12, 14 or 16 bits depending
on the specific PIC micro family). PIC and PIC micro are registered trademarks of Microchip
Technology. It is generally thought that PIC stands for Peripheral Interface Controller, although
General Instruments' original acronym for the initial PIC1640 and PIC1650 devices was
"Programmable Interface Controller" The acronym was quickly replaced with "Programmable
Intelligent Computer". The Microchip 16C84 (PIC16x84), introduced in 1993, was the first
Microchip CPU with on-chip EEPROM memory. This electrically erasable memory made it cost
less than CPUs that required quartz "erase window" for erasing EPROM.

PIC 16F877A microcontroller hardware description

PIC 16F877A generally has 40 pins. The 40 pins make it easier to use the peripherals as the
functions are spread out over the pins. This makes it easier to decide what external devices to
attach without worrying too much if there enough pins to do the job.
Figure: PIC 16F877A Microcontroller

Note: A disadvantage of the device is that it has no internal oscillator so you will need an
external crystal of other clock source.

Fig: Pin diagram of PIC 16F877A

The 16F877A has 8k byte of code space, 368 bytes of RAM and 256 bytes of EEPROM.
The description of the main pins of PIC16F877A microcontroller
The main pins of PIC 16F877A are:

I. input/output ports or pins

II. Power supply pin

III. Clock supply pin

Input/output Ports of PIC 16F877A

PIC16F877A has the following digital I/O ports:

Port A RA0- RA5 6 bits

Port B RB0-RB7 8 bits

Port C RC0-RC7 8 bits

Port D RD0-RD7 8 bits

Port E RE0-RE2 3 bits

Total I/O port 33 bits

PIC 16F877A normally has five input/output ports. They are used for the input/output
interfacing with other devices/circuits. Most of these port pins are multiplexed for handling
alternate function for peripheral features on the devices. All ports in a PIC chip are bi-
directional. When the peripheral action is enabled in a pin, it may not be used as its general
input/output functions. The PIC 16F877A chip basically has 5 input/output ports. The five
input/output ports and its functions are given below.

PORTA and the TRISA Registers

PORTA is a 6-bit wide bi-directional port, the direction of this port is controlled by TRISA data
direction register. Setting a TRISA (=1) makes corresponding PORTA pin as an input, clearing
the TRISA (=0) making the corresponding PORTA pin as an output. Pin RA4 is multiplexed
with the “Timer0” module clock input to become the RA4/T0CKI pin and functioning either
input/output operation or Timer 0 clock functioning module. The RA4/T0CKI pin is a Schmitt
Trigger input and an open-drain output. All other PORT A pins has TTL input levels and full
CMOS output drivers. Other PORT A pins in this microcontroller multiplexed with analog inputs
and the analog VREF input for both the A/D converters and the comparators. The operation of
each pin is selected by clearing/setting the appropriate control bits in the ADCON1 and/or
CMCON registers. The TRIS A register controls the direction of the PORT pins even when they
are being used as analog inputs. The user must ensure the bits in the TRISA register are
maintained set when using them as analog inputs.

PORTB and the TRISB Registers

PORTB is also an 8 bit bi-directional PORT. Its direction controlled and maintained by TRISB
data direction register. Setting the TRISB into logic ‘1’ makes the corresponding “PORTB” pin
as an input. Clearing the TRISB bit make PORTB as an output. Three pins of PORTB are
multiplexed with the In-Circuit Debugger and Low-Voltage Programming function: RB3/PGM,
RB6/PGC and RB7/PGD for performing its alternate functions.

PORTC and the TRISC Registers

PORTC is an 8-bit wide. It is bidirectional PORT which controlled and maintained by TRISC
data direction register. Setting a TRISC bit (= 1) will make the corresponding PORTC pin an
input (i.e., put the corresponding output driver in a High-Impedance mode). Clearing a TRIS C
bit (= 0) will make the corresponding PORTC pin an output PORTC is also multiplexed with
several peripheral functions. PORTC pins have Schmitt Trigger input buffers.

When enabling peripheral functions, more care should be taken in defining TRIS bits for each
PORTC pin as compared to other. Some peripherals override the TRIS bit to make a pin an
output, while other peripherals override the TRIS bit to make a pin an input. Since the TRIS bit
override is in effect while the peripheral is enabled, read-modify write instructions (BSF, BCF,
and XORWF) with TRISC as the destination, should be avoided. The user should refer to the
corresponding peripheral section for the correct TRIS bit settings.

PORTD and TRISD Registers

PORTD is an 8-bit PORT with bi-directional nature. This port also with Schmitt Trigger input
buffers, each pin in this PORTD individually configurable as either input or output.
PORTE and TRISE Registers

PORTE has only three pins (RE0/RD/AN5, RE1/WR/AN6 and RE2/CS/AN7) which are
individually configurable as inputs or outputs. These pins controllable by using its corresponding
data direction register “TRISE”and have Schmitt Trigger input buffers. The PORTE pins become
the I/O control inputs for the microprocessor PORT when bit PSPMODE is set. In this mode, the
user must make certain that the TRISE bits are set and that the pins are configured as digital
inputs. Also, ensure that ADCON1 is configured for digital I/O.
TRISE register which also controls the Parallel Slave PORT operation. PORTE pins are
multiplexed with analog inputs. When selected for analog input, these pins will read as ‘0’s.
TRISE controls the direction of the RE pins, even when they are being used as analog inputs.
The user must make sure to keep the pins configured as inputs when using them as analog inputs.
VSS and VDD
These are power supply pins .VDD is the positive supply and VSS is the negative Supply or
0V.The maximum supply voltage that you can use is 6V and the minimum is 2V.
MCLR
Master clear (reset) input is connected to pin 1. This pin is an active low to the device. This pin is
used to erase the memory locations inside the PIC (i.e. when we want to re-program it).In normal
use it is connected to the positive supply rail.
OSC1/CLK IN and OSC2/CLKOUT
These are crystal oscillator input and output and are connected to pins 13 & 14 respectively.
These pins are where we connect an external clock, so that the microcontroller has some kind of
timing. These are connected to crystal or resonator in crystal oscillator mode.
The crystal oscillator used in the electrical circuit connection is shown below.

Figure: The symbol of crystal oscillator

The detail of crystal oscillator is shown below.


Introduction to mikroC
MikroC is a powerful, feature rich development tool for PIC micros. It is designed to provide the
customer with the easiest possible solution for developing applications for Embedded systems,
without compromising performance or control. 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

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. It develops applications quickly and easily with the world's most intuitive C
compiler for PIC Microcontrollers (familiesPIC12, PIC16, and PIC18).Highly sophisticated IDE
provides the power which is needed with the simplicity of a windows based point-and-click
environment. With useful implemented tools, many practical code examples, broad set of built-in
routines, and a comprehensive Help, mikroC makes a fast and reliable tool.

MikroC allows developing and deploying complex applications:

 Write C source code using the highly advanced Code Editor.


 Use the included MikroC libraries to dramatically speed up the development:

data acquisition, memory, displays, conversions, communications…

 Monitor program structure, variables, and functions in the Code Explorer.


 Generate commented, human-readable assembly, and standard HEX

compatible with all programmers.

 Inspect program flow and debug executable logic with the integrated

Debugger.
Figure 2.9: MikroC window

Building Application

Creating applications in micro C is easy and intuitive. Project Wizard allows to set up the project
in just few clicks: name the application, select chip, set flags, and get going. MikroC allows
distributing the projects in as many files as we find appropriate. We can then share micro C
compiled Libraries (.mcl files) with other .mcl developers without disclosing the source code.
The best part is that bundles created by micro Pascal or micro Basic can be used.

MikroC language Reference

C offers unmatched power and flexibility in programming microcontrollers. MikroC adds even
more power with an array of libraries, specialized for PIC hardware modules and
communications. Along with the specifics of programming PIC microcontrollers, this can help to
learn and recollect C syntax.
MikroC libraries

MikroC provides a number of built-in and library routines which help to develop the application
faster and easier. Libraries for ADC, CAN, USART, SPI, I2C, 1-Wire, LCD, PWM, RS485,
numeric formatting, bit manipulation, and many other are included along with practical, ready-
to-use code examples

Proteus Software

Proteus is best simulation software for various designs with microcontroller. It is mainly popular
because of availability of almost all microcontrollers in it. So it is a handy tool to test programs
and embedded designs for electronics. It is easily possible to simulate the result of programming
of microcontroller in Proteus Simulation Software.
After simulating any circuit in Proteus Software you can directly make physical wiring and PCB
design. So this software is adequate to show the simulation result of practically implementable
circuits or systems.
Examples:

1. Develop a program for blinking of a diode in both ports A and B continuously


Solution:
The code (program) in MicroC is given below

void main() {

TRISB = 0x00; // set direction to be output

TRISBD =0x00; // set direction to be output

do {

PORTB = 0x0F; // Turn ON LEDs on PORTB of PINS 0,1,2,3

PORTD = 0x0F; // Turn ON LEDs on PORTD of PINS 4,5,6,7

Delay_ms(1000); // 1 second delay


PORTB = 0x00; // Turn OFF LEDs on PORTA

PORTD = 0x00; // Turn OFF LEDs on PORTB

Delay_ms(1000); // 1 second delay

} while(1); // Endless loop

The circuit is designed in proteus as shown below.

U1
13 33
OSC1/CLKIN RB0/INT
14 34
OSC2/CLKOUT RB1
X1 RB2
35
2 36
RA0/AN0 RB3/PGM
3 37
RA1/AN1 RB4
4 38
RA2/AN2/VREF-/CVREF RB5
5 39
CRYSTAL RA3/AN3/VREF+ RB6/PGC
6
RA4/T0CKI/C1OUT RB7/PGD
40 D1 D2 D3 D4
7 LED-GREEN LED-GREEN LED-GREEN LED-GREEN
RA5/AN4/SS/C2OUT
15
RC0/T1OSO/T1CKI
C1 C2 8
RE0/AN5/RD RC1/T1OSI/CCP2
16
22pF 22pF 9 17
RE1/AN6/WR RC2/CCP1
10 18
RE2/AN7/CS RC3/SCK/SCL
23
RC4/SDI/SDA
1 24
MCLR/Vpp/THV RC5/SDO
25
RC6/TX/CK
26
RC7/RX/DT
19
RD0/PSP0
20
RD1/PSP1
BAT1 RD2/PSP2
21
5V 22
RD3/PSP3
27
RD4/PSP4
28
RD5/PSP5
29
RD6/PSP6
RD7/PSP7
30 D7 D8
D5 D6 LED-RED LED-RED
PIC16F877A LED-RED LED-RED

2. Develop a program for blinking of a diode in both ports B and D five times
Solution:
The code (program) in MicroC is given below

void main() {

int k;
TRISB = 0x00; // set direction to be output

TRISD =0x00; // set direction to be output


for (k=0;k<=5;k++)
{
PORTB = 0x0F; // Turn ON LEDs on PORTB

PORTD = 0x0F; // Turn ON LEDs on PORTD

Delay_ms(1000); // 1 second delay

PORTB = 0x00; // Turn OFF LEDs on PORTB

PORTD = 0x00; // Turn OFF LEDs on PORTD

Delay_ms(1000); // 1 second delay

}
}
The circuit is the same as shown above.
3. Develop a program to control Street traffic Light
Solution:
The code (program) in MicroC is given below
void main() { //main program starts here
int k;
TRISB=0x00; //initialize port B as o/p
TRISC=0x00; //initialize port C as o/p
PORTB=0x00; //initialize port B to zero
PORTC=0x00; //initialize port C to zero
for (k=0;k<=5;k++)
{
PortB=0x92;
portC=0x04;
delay_ms(100);
PortB=0x00;
portC=0x00;
delay_ms(100);
}
while(1) // infinite loop(24 hours)
{
PORTB = 0x21;
PORTC = 0x09;
Delay_ms(600);
PORTB = 0x22;
PORTC = 0x09;
Delay_ms(100);
PORTB = 0x0C;
PORTC = 0x09;
Delay_ms(600);
PORTB = 0x14;
PORTC = 0x09;
Delay_ms(100);
PORTB = 0x64;
PORTC = 0x08;
Delay_ms(600);
PORTB = 0xA4;
PORTC = 0x08;
Delay_ms(100);
PORTB = 0x24;
PORTC = 0x03;
Delay_ms(600);
PORTB = 0x24;
PORTC = 0x05;
Delay_ms(100);
}
}
The circuit is designed as shown below in proteus professional-8
U2
13 33
OSC1/CLKIN RB0/INT
14 34
OSC2/CLKOUT RB1
35
RB2
X1 2
RA0/AN0 RB3/PGM
36
3 37
RA1/AN1 RB4
4 38
RA2/AN2/VREF-/CVREF RB5
5 39
RA3/AN3/VREF+ RB6/PGC
6 40
CRYSTAL RA4/T0CKI/C1OUT RB7/PGD
7
RA5/AN4/SS/C2OUT
C2 RC0/T1OSO/T1CKI
15
C1 22pF 8
RE0/AN5/RD RC1/T1OSI/CCP2
16
22pF 9 17
RE1/AN6/WR RC2/CCP1
10 18
RE2/AN7/CS RC3/SCK/SCL
23
RC4/SDI/SDA
1 24
MCLR/Vpp/THV RC5/SDO
25
RC6/TX/CK
26
RC7/RX/DT

BAT1 RD0/PSP0
19
5V 20
RD1/PSP1
21
RD2/PSP2
22
RD3/PSP3
27
RD4/PSP4
28
RD5/PSP5
29
RD6/PSP6
30
RD7/PSP7
PIC16F877A

4. Develop a program to control Forward and reverse operation of a motor and display its
direction in LCD
Solution:
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit ;
sbit LCD_D4 at RB0_bit ;
sbit LCD_D5 at RB1_bit ;
sbit LCD_D6 at RB2_bit ;
sbit LCD_D7 at RB3_bit ;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;

char txt3[]="Motor Direction ";


char txt2[]="Forward ";
char txt1[]="Reverse ";
void main() {
trisd0_bit=0;
trisd1_bit=0;
trisd2_bit=0;
trisd3_bit=1;
trisd4_bit=1;
LCD_init();
LCD_Cmd(_LCD_CLEAR);
LCD_cmd(_LCD_CURSOR_OFF);
while(1)
{
LCD_out(1,1,txt3);
delay_ms(500);
if(rd3_bit)
{
LCD_out(2,1,txt2);
rd1_bit=0;
rd0_bit=1;
}
if(rd4_bit)
{
LCD_out(2,1,txt1);
rd0_bit=0;
rd1_bit=1;
}
if(rd3_bit & rd4_bit)
{
LCD_out(2,1," MOtor off ");
rd1_bit=0;
rd0_bit=0;
}
if(!rd3_bit & !rd4_bit)
{
LCD_out(2,1," MOtor off ");
rd1_bit=0;
rd0_bit=0;
}
}
}
The circuit is shown below
LCD1
LM016L
RV1
BAT3
5V
54%

VDD
VSS

VEE
1k

RW
RS

D0
D1
D2
D3
D4
D5
D6
D7
E
1
2
3

4
5
6

7
8
9
10
11
12
13
14
U1
13 33
OSC1/CLKIN RB0/INT
14 34
OSC2/CLKOUT RB1
X1 RB2
35
2
RA0/AN0 RB3/PGM
36 BAT4
3 37 5V
RA1/AN1 RB4
4 38
RA2/AN2/VREF-/CVREF RB5
5 39
CRYSTAL
6
RA3/AN3/VREF+ RB6/PGC
40 9 4 U2
RA4/T0CKI/C1OUT RB7/PGD
7
RA5/AN4/SS/C2OUT
15 5
RC0/T1OSO/T1CKI IN1 VCC VS
C1 C2 8
RE0/AN5/RD RC1/T1OSI/CCP2
16 7
IN2 OUT1
2
22pF 22pF 9 17 10
RE1/AN6/WR RC2/CCP1 IN3
10
RE2/AN7/CS RC3/SCK/SCL
18 12
IN4 OUT2
3 BAT2
23 6 12V
RC4/SDI/SDA ENA
1 24 11 13
MCLR/Vpp/THV RC5/SDO ENB OUT3
25 -360
RC6/TX/CK
26 1 14
RC7/RX/DT SENSA OUT4
15
SENSB GND
19
RD0/PSP0
20
RD1/PSP1
21 8 L298
RD2/PSP2
22
RD3/PSP3
27
RD4/PSP4
28
RD5/PSP5
29
RD6/PSP6
30
RD7/PSP7
PIC16F877A

BAT1 5V

You might also like