Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
45 views

Introduction To Microcontrollers

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Introduction To Microcontrollers

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

PIC16F84A Microcontroller

Mr. TS Phali
Central University of Technology, Free State
Expected Outcomes
 Explain what is a Microcontroller.
 Basic Microcontroller System
 How does it differ from other known ICs (Logic Gates).
 What are the building blocks of a Microcontroller.
 Functions of different parts in a Microcontroller.
 How you connect inputs and outputs to
Microcontroller.
Continued: PIC16F84A
 PIC16F84A (Hardware).
 Functions of PIC16F84A hardware.
 PIC16F84A Memory Organization and Special
Function Registers (Introduction).
Continued: Using MPLAB
 Basic Instructions and Registers.
 How do you Interpret a Problem Statement.
 Translate Problem Statement into Flowchart.
 Why and How do you Initialize a PIC Microcontroller.
 How do you implement your Flowchart in a Program.
 Creating a Project using MPLAB.
 Problem Statement Examples.
What is a Microcontroller???
 A Microcontroller is a small computer on a single
integrated circuit containing a processor core,
memory, programmable I/O & other peripherals.
Basic Microcontroller System

INPUT OUTPUT
[Switches, Sensors, [Visual, Audio,
CONTROL
Serial/ Parallel Switching,
[uController]
communication, Serial/parallel
etc] comms, etc]
Logic Gates vs. Microcontroller
TTL or CMOS Logic Gates Microcontroller
 They have fixed hardware  Have configurable hardware
functionality (inputs and functionality.
outputs).  Can perform specific/
 They perform specific multiple tasks, depends on
functions, depending on the the program.
logic gate used.  Have other peripherals
embedded in it.
Building Blocks of Microcontroller
 CPU
 Program Memory
 Memory (EEPROM and/or RAM)
 Programmable I/O pins
 Timers
 Other peripherals (serial comm. ADCs, Comparator
etc.)
Functions:
 CPU – Fetching and execution of instructions from
program memory, performing arithmetic etc.
 Program Memory – Store program to be executed by the
CPU.
 Memory – Store data for execution or after execution, data
can be store in volatile RAM memory or in non-volatile
EEPROM memory.
 I/O – to interface the microcontroller with the rest of the
hardware (Sensors, Switches, LEDs etc.).
 Timers – Can be implemented as counters, for delays or for
RTC applications.
 Peripherals – This are software configurable, and some of
them are assigned to certain I/O pins of a microcontroller.
Connecting Inputs and Outputs to
Microcontroller
Connecting Inputs Connecting Outputs
 PullDown (N/O Switch) -  There are two ways to connect
When a switch is not pressed, outputs to a microcontroller,
the logic is zero (zero volts) at where the current flows into the
the input of the microcontroller. microcontroller (Sinking), or
When the switch is pressed then where the current flows out of
the logic changes to one (5V) at the microcontroller (Sourcing).
the input of the microcontroller.  PIC uController
 For PullUp connection the I/O pin can only
operation is the opposite. source or sink a
maximum of
25mA.
PIC16F84A Hardware
Functions:
 VDD - supply voltage +5V (pin14)
 VSS – Ground 0V (pin5)
 MCLR- Microcontroller Reset (pin4 - Active Low)
 OSC1 – Oscillator input pin (XT, RC, LP). (pin16)
 OSC2 – Oscillator / Output clock (XT, LP). (pin15)
 PortA – I/O port (pin 1-3,17,18) programmable I/O
 PortB – I/O Port (pin6-13) programmable I/O
Memory Organization and
Special Function Registers
(Introduction)
 PIC16F84A has two memory blocks,
being the Program memory and the
Data memory.
 Data memory is divided into Special
Function Registers (SFRs) and General
Purpose Registers.
 General Purpose Registers are used to
store user data.
 A Special Function Registers controls
and/ or monitors specific/ various
aspects of the microcontroller during
normal operation.
 EEPROM is also part of Data memory,
but is not directly mapped into the Data
memory.
Basic Instructions and Registers
 Register – An 8bit Random Access Memory with a
specific address (memory location).
 Bit Oriented Instructions – This instructions affects a
single bit in a register (e.g. BSF, BTFSS etc.).
 Byte Oriented Instructions – This Instructions affects
the whole 8bits in a register. (MOVF, COMF etc.).
 Branching Instructions – This Instructions Jumps form
the main program to a specified location (e.g. GOTO,
CALL etc.)
Interpreting Problem Statement
Keywords: Helps you decide how to setup (Initialize)
your microcontroller.
 Read – Input
 Write – Output
 Other specifications like using Interrupts, Timers etc.
Expected outcomes from the problem statement should..
 Enable you to identify the initial/ start point.
 Identify logic/ arithmetic necessary for the next steps.
 Reach the final goal.
 Return to 2nd step above or remain in an endless loop.
Problem Statement to Flowchart
 Flowchart always should begin with Start/ Power
On. Start/
 Then you Initialize your microcontroller, this step Power On
can be done once after power up and need not be
repeated.
 After Initialization, the main program begins, this
will be guided by the statement. In most cases the Initialize
main program will loop forever repeating the
required task, whereas in some cases after
completing the task the program enters an endless
loop until user reset through MCLR, watchdog
timer reset, RESET instruction or until power off. Main
 The main program block can be devided into Functions
other smaller blocks provided the expected
outcomes are knows.
Initialization: Why and How???
 The reason you initialize your controller is because you
need to inform it where you want your inputs and outputs,
which peripherals you will be using and you may also need
to setup few other registers.
 You initialize your controller by writing to SFRs. For
example if you need to setup I/O you need to write to
TRISA and TRISB registers.
 Be aware that your registers are grouped into two banks
(bank 0 and 1), you will need to switch between these
banks to access different registers.
 Bit 5 of the STATUS register (RPO) is used to switch
between the banks. When the bit is set you are in bank1,
when the bit is cleared then you are in bank0.
Implementing Solution (Program)
 When implementing your solution you are guided by your
flowchart. You first need to inform the compiler which
microcontroller you are using. This is done by making use of the
LIST instruction (LIST P=16F84A).
 The next step is to ask the compiler to make use of .INC file
which assigns SFRs names to their memory locations (address).
To do this you make use of the #INCLUDE<P16F84A.INC>
instruction.
 These two instructions should be written at the top of the code,
before you initialize the controller.
 After initialization, the main program can be written making use
of supported instructions and registers, the main program is
guided by the flowchart and the PIC executes the instructions
sequentially.
Creating a Project using MPLAB
 Open MPLAB program.
 Go to Project, select Project Wizard, click Next, select
the Device (PIC16F84A), click Next.
 Active Toolsuite: Microchip MPASM Toolsuite
 Click Next, Click Browse, great a folder and save the
project file in it (give the project file a suitable name).
 Click Next, Click Next again, Click Finish
 Go to File, select New File, go to File again, select save as,
give your file a name with .asm extension, tick the Add File
to Project box found at the bottom and save your file
where you saved your project file (in the same folder).
Problem Statements:
Draw a flowchart and write assembly program to do the following:
 Write the values 0x00 on PortA & 0xff on PortB.
 You are expected to read PortA and write the value to PortB.
 Read PortA, invert the value and write the results on PortB.
 Implement an AND gate using PortA,1 and 2 as inputs and
PortA,3 as output.
 Implement an OR gate using PortB,4 and 5 as inputs and PortB,7
as output.
 You are expected to implement an AND gate and an OR gate
using PortA,1 and 2 as inputs and PortB,3 as output for the AND
gate and PortB,4 as output for the OR gate.
 Add more logic gates to the previous task.

You might also like