You are on page 1of 109

Course On

Basic Microcontroller Based Design

By
Zubayer Al Billal Khan
zubayer_007@yahoo.com
01913469663
What is Embedded System ?

Embedded System is a combination of


Software & hardware designed to perform
a specific task
What is a Microprocessor (up)?
Microprocessor is the Central Processing
unit
Microprocessor is just simply the processor.
To make it to work it will need lots of
external parts called peripherals.
Microprocessor need s many external circuit
to make it work. So Microprocessor based
system is called System on Board(SOB)
What is a Microcontroller(uc)?
#Microcontroller is the processing part in
which all the essential Peripherals are
integrated in a single chip
#Microcontroller = microprocessor +
peripherals
#It can process as well as control
#It include all the necessary parts in IC. So
microcontroller based system called system
on Chip(SOC)
History
 The first microprocessor was developed by what was
then a small company called Intel (short for Integrated
Electronics) in the early 1970s.
 The chipset was a success and within a short while Intel
developed a general purpose 4 bit microprocessor called
the 4004.
 In 1974 the more powerful second generation
microprocessor (the 8008) wasannounced fabricated as a
single chip.
Why Important?
Embedded Inside:
◦ Automotive systems
◦ Airplanes
◦ Toys
◦ Medical Devices
◦ Furniture

Billions of units
Available uC in Bangladesh
AT89C51 AT89C52 AT89S51 AT89S52
ATMEGA-8 AT89C2051 AT89C4051
AT89C55WD AT89S8252 AT90S2313
AT90S8515 AT90S8535 ATMEGA-16
ATMEGA-32 ATMEGA-64 ATMEGA-88
ATTINY-13
ATTINY-15 ATTINY-26 AT89C51ED2
AT89C51RD2 AT91RM9200
AT91SAM256 ATMEGA-128 ATMEGA-162
W78E052B40DL
Available uC in Bangladesh
PIC16F72 PIC16F73
PIC16F74 PIC16F76
PIC16F77 PIC16F88
PIC10F200 PIC12F508
PIC12F629 PIC12F675
PIC16C54C PIC16C57C
PIC16C65B PIC16C923
PIC16F676 PIC16F84A
PIC18F452 PIC16C622A
PIC16F628A PIC16F648A
PIC16F873A PIC16F876A
PIC16F877A PIC18F2550
PIC18F4550
About Microchip(PIC)
PIC= Peripheral Interface Controller
PIC is a Family of Harvard Architecture
Microcontrollers made by Microchip
Technology.
Microchip Technology is an American
Manufacture of microcontroller. memory
and analog semiconductors.
The company founded in 1987.
PIC16F877A
40-Pin Pin Enhanced Flash, 8-Bit
CMOS Microcontrollers with
Nano Watt Technology

 Wide operating voltage range (2.0V-5.5V)


 33 I/O pins
 Two 8-bit Timer, One 16-bit Timer
 8-channel, 10-bit ADC
 Programmable Serial USART
 Internal Calibrated RC Oscillator
 DC – 20 MHz oscillator/clock input
 Software selectable frequency range of 8 MHz to 32
kHz
Pin Diagram
Pin Out And Data Sheet
What do I need to start?
To start C programming language on Microchip
PIC Microcontroller you need these following
tools:

Down load the latest Microchip MPLAB IDE


The MPLAB IDE is already come with the
HITECH PICC-Lite C compiler
The PIC16F877A datasheet
Microchip Programmer.
Trainer Board
Software Installation

1. MPLab
2. Programmer Software
3. Proteus
END OF CLASS -1
Open MPLAB

Start -> All Programs -> Microchip ->


MPLAB IDE ver 8.60 -> MPLAB IDE
Create New Project

Project -> Project Wizard… from MPLAB IDE and this will
launch the project wizard, just continue with Next
Give Project Name
Creating the .C file

File -> New and save it as test.c


Pull
Up &
Down
Switch
Sensor ?

A device which detects or measures a


physical property and records, indicates,
or otherwise responds to it.
END OF CLASS - 2
I/O Port
For Port A, B, C, D, E there are control
bytes TRISx.
Setting a TRISx bit (= 1) will make the
corresponding PORTx pin an input
Clearing a TRISx bit (= 0) will make the
corresponding PORTx pin an output
TRISA and PORTA
TRISB and PORTB
TRISC and PORTC
TRISD and PORTD
TRISE and PORTE
Write the first code and simulate
#include<pic.h>

void main() // main function


{
TRISA0 = 1; // declare RA0 pin as input
TRISC = 0; // declare POART C as output
ADCON1=0b00000110; //declare RA0 pin as digital
while (1) // working loop
{
if(PORTA == 0)
{
PORTC = 0;
}

else if (PORTA0 == 1)
{
PORTC = 1;
}
}
}
Open ISIS Professional from
Proteus Program
Draw the circuit
Specify HEX file to Microcontroller
Simulate the Circuit with
Microcontroller Program
Output current caution
Ensure that the output current <20mA
Maximum output current sunk by any I/O
pin .................................................................................................... 25 mA

Maximum output current sourced by any I/O


pin .............................................................................................. 25 mA

Maximum current sunk by PORTA, PORTB and PORTC


(combined) ............................................................ 200 mA

Maximum current sourced PORTA, PORTB and PORTC


(combined) ............................................................ 200 mA
Input
Input Arrangement
For hardware side, use 1uf-10uf Capacitor
across the push button if the input source
is a push button.
Solve the de-bouncing problem by
programming accordingly.
Class work
Write a program that
◦ takes input from PORTC1 and PORTA0
◦ Output LED at PORTC2 is light while any of
the input is high
◦ Output LED as PORTC3 is light while both of
the inputs are high
Simulateit and run it to the
Microcontroller
Basics Of Display Driver

BCD to 7-segment Decoder


LCD Driver
Display Driver 7447
Display test and blank input are active-
low so they should be high for normal
operation.
If the blank input is low the display will
be blank when the count input is zero
(0000).
PIN Out
Difference between Common anode &
cathode
Analog to Digital Converter
10-bit Resolution
13 - 260 μs Conversion Time
8 Multiplexed Single Ended Input
Channels
0 - VCC ADC Input Voltage Range
Selectable 2.56V ADC Reference
Voltage
A general diagram of ADC
Block Diagram
ADC Block Diagram(PIC16F690)
Related Pins
Configuration Sequence
Enable ADC
Analog input channel declaration
Channel Selection
Clock Selection
Start a conversion
Wait until the conversion finishes
When the conversion is done, read the 8 bit
LSB from ADRESL and 2 bit MSB from
ADRESH byte.
Concatenate them to get 10 bit conversion
Configuration Bytes
There are four registers available to control
the
functionality of the A/D module:
1. ADON=1
2. ADCS2,1,0
3. CHS2,1,0
Enabling ADC
Analog input channel declaration

Set the corresponding TRISx bits to ‘1’ to


set the pin output driver to its high-
impedance state.
Likewise, set the corresponding ANSx bit
to disable the digital input buffer.
ADC
ADC clock source
CONVERSION OUTPUT
The A/D conversion can be supplied in
two formats: Left or right justified.
The ADFM bit (ADCON0<7>) controls
the output format.
VOLTAGE REFERENCE
There are two options for the voltage
reference to the A/D converter: either
VDD is used or an analog voltage applied
to VREF is used.
The VCFG bit (ADCON0<6>)controls
the voltage reference selection.
If VCFG is set, then the voltage on the
VREF pin is the reference;otherwise,
VDD is the reference.
Voltage Reference(not applicable)
CONVERSION CLOCK
The source of the conversion clock is
software selectable via the ADCS bits
(ADCON1<6:4>).
STARTING A CONVERSION
The A/D conversion is initiated by setting
the GO/DONE bit (ADCON0<1>).
When the conversion is complete, the
A/D module: Clears the GO/DONE bit
ADC
END OF CLASS
Interrupt
Basics of Interrupt
◦ Interrupted operation while normal operation
is going on
◦ Very good option for taking input
Interrupt Basic
So far functions were called from the main program or
other functions. The interrupt functions is called by
the hardware itself and operates by following steps:
 After the interrupt function is loaded into the memory,
the function waits for a moment for the interrupt to
occur;
 When the interrupt has occurred, the operating system
stops the execution of the main function and “free
itself” to perform the interrupt function;
 After the execution of the interrupt function, the
operating system continues to run the main function
from the place it stopped before the interrupt has
occurred.
Interrupt Pins
Interrupts
Interrupt Configuration
 RB0/INT Must be configured as Digital I/O
 Interrupt Mode selection
 Initializing the flag bit
 Enable External Interrupt
 Enable Global interrupt

 In the Interrupt service routine, clear flag bit every time.


RB0/INT pin as digital IO

Configure
TRISB0=1
ADCON1=0b00000110; for digital input
Mode Selection
INTERRUPT External interrupt on
RB0/INT pin is edge-triggered;
◦ either rising if the INTEDG bit (REGISTER
5-1: OPTION_REG REGISTER) is set,
◦ or falling, if the INTEDG bit is clear.
Initializing Flag bit
When a valid edge appears on the RA2/INT
pin, the INTF bit (INTCON<1>) is set.

So initialize the INTF=0


Enable External Interrupt
Enable Global Interrupt
Software handling of INTF
 The INTF bit must be cleared in software in the
Interrupt Service Routine before re-enabling this
interrupt.

void interrupt isr ( )


{

……………………………………..
INTF=0;
}
END OF CLASS
Timer/ Counter
3timers/Counters
Two 8-bit timers and One 16-bit timer
Easily selectable clock source
How timer works?

It’s a 8 or 16 bit register. Its value increases


with each clock cycle. So, bigger the no of
bits, the bigger the range of counting.
By setting modes, we can calculate intervals
or generate events at regular interval.
Timer0 Diagram
Timer Configuration
Clock selection
Mode Selection
Interrupt configuration
Clock Input Pins
The external
clock source
must be at
least 2.5 less
than the µC
clock source.
Clock Source
The internal clock can be used as the
clock source. For timers, the internal
clock can be pre-scaled.
There is option for external clock source
also.
Clock Selection and Configuration
Clock Pre-scalar Selection
Timer Interrupt Configuration
END OF CLASS
Timer 1
Timer Configuration
Clock selection
Mode Selection
Set TCNT1, OCR1
Interrupt configuration
GIE Enable
Peripheral Interrupt configuration
TIMER1 EDGE
TIMER1
END OF CLASS
EEPROM
256 Byte
The EEPROM has an endurance of at
least 100,000 write/erase cycles.
EEPROM(Writing Procedure)
Set data
Set address
Start write if EEWE is 0
EEPROM
END OF CLASS
USART
Universal Synchronous and Asynchronous serial Receiver and
Transmitter

 Full Duplex Operation (Independent


Serial Receive and Transmit Registers)
Asynchronous or Synchronous Operation
Master or Slave Clocked Synchronous
Operation
Double Speed Asynchronous
Communication Mode
Two Types of serial communication
Synchronous
◦ Clock source is synchronized
◦ Data is synchronized with clock
◦ i.e. a common clock source for the
communicating devices is necessary
Asynchronous
◦ No common clock source is required
◦ Clock is recognized by the receiver
automatically
Frame Format
Transmit block Diagram
For Transmit
Receive block Diagram
For Receive
What is Baud Rate ?
In telecommunication and electronics is
the unit for symbol rate or modulation rate
in symbols per second or pulses per
second. It is the number of distinct
symbol changes (signaling events) made
to the transmission medium per second in
a digitally modulated signal or a line
code.
Baud Rate formula
END OF CLASS

You might also like