0% found this document useful (0 votes)
14 views20 pages

Lecture 8

This document discusses a lecture on programming essentials for input and output using the PIC16F84A microcontroller. The lecture covers 16F84A programming templates, introducing the microcontroller and simple circuits. It also discusses programming a seven-segment LED for displaying numbers using ports on the PIC16F84A and implementing a free running counter. The document ends with a brief description of demonstration boards for practicing PIC programming.

Uploaded by

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

Lecture 8

This document discusses a lecture on programming essentials for input and output using the PIC16F84A microcontroller. The lecture covers 16F84A programming templates, introducing the microcontroller and simple circuits. It also discusses programming a seven-segment LED for displaying numbers using ports on the PIC16F84A and implementing a free running counter. The document ends with a brief description of demonstration boards for practicing PIC programming.

Uploaded by

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

MEE 1133: Advanced Microcontroller

Lecture 8: Programming Essentials: Input


and Output
By the end of this topic, you should be able to:

 Understand 16F84A Programming Template


 Understand Introducing the 16F84A
 Understand Simple Circuits and Programs
 Understand Programming the Seven-Segment LED
 Understand A Demonstration Board

Dr. Khairil Ezwan Kaharudin


MEE 1133: Advanced Microcontroller

16F84A Programming Template


 We have found that program development can be simplified considerably by using
code templates.
 A code template is a program devoid of functionality that serves to implement the
most common and typical features of an application.
 The template not only saves the effort of redoing the same tasks but reminds the
programmer of program elements that could otherwise be forgotten.
 A professional developer will have collected many different templates over the years
for different types of applications on various processors.
MEE 1133: Advanced Microcontroller

16F84A Programming Template

Dr. Khairil Ezwan Kaharudin


MEE 1133: Advanced Microcontroller

Cont…

Dr. Khairil Ezwan Kaharudin


MEE 1133: Advanced Microcontroller

Cont…

Dr. Khairil Ezwan Kaharudin


MEE 1133: Advanced Microcontroller

Cont…

Dr. Khairil Ezwan Kaharudin


MEE 1133: Advanced Microcontroller

Introducing the 16F84A


16F84A Circuit Template

Dr. Khairil Ezwan Kaharudin


MEE 1133: Advanced Microcontroller

Power Supplies

 Every PIC-based circuit board requires a +5V power source.


 A possible source of power is one or more batteries.
 There is an enormous selection of battery types, sizes, and qualities.
MEE 1133: Advanced Microcontroller

Voltage Regulator
 A useful device for a typical PIC-based power source is a voltage regulator IC.
 The 7805 voltage regulator is ubiquitous in most PIC-based boards with AC/DC adapter sources.
 The IC is a three-pin device whose purpose is to ensure a stable voltage source which does not exceed
the device rating.
 The voltage regulator circuit requires two capacitors: one electrolytic and the other one not.
MEE 1133: Advanced Microcontroller

Simple Circuits and Programs

PIC16F84A LED blink


 This program shows a simple example for making an LED blinks using PIC16F84A
microcontroller and CCS PIC C compiler.
 It is easy to make an LED blinking, a few program lines are required and the
microcontroller PIC16F84A is a simple chip also.

Dr. Khairil Ezwan Kaharudin


MEE 1133: Advanced Microcontroller

PIC16F84A LED blink circuit

Dr. Khairil Ezwan Kaharudin


MEE 1133: Advanced Microcontroller

PIC16F84A LED blink C code


// PIC16F84A LED blink example
// https://simple-circuit.com/

#include <16F84A.h>
#use delay(crystal=8000000)

void main()
{
while(TRUE)
{ // Endless loop
output_low(PIN_A0); // LED OFF
delay_ms(500); // Delay 500 ms
output_high(PIN_A0); // LED ON
delay_ms(500); // Delay 500 ms
}
}

Dr. Khairil Ezwan Kaharudin


MEE 1133: Advanced Microcontroller

Programming the Seven-segment LED


 A 7-segment display can be connected to output ports on the PIC and used to display numbers and some
digits.
 This program provides the implementation of free running counter ( using c language ) for PIC16F84A
microcontroller.
 The code is written in such a way that, the counter starts from a value of ‘0’ ( displayed on the seven
segment ) and then increments this value after every second. So, the seven-segment display starts from
‘0’ and then displays ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘A’, ‘b’, ‘C’, ‘d’, ‘E’, and in the end ‘F’.
After displaying ‘F’, counter starts from ‘0’ again and this pattern repeats forever.
 A crystal of 20 MHz is used here. We can use any crystal value from 0 to 20MHz with PIC16F84A. The
PIC16F84A microcontroller has an architecture which executes an instruction in 4 CPU cycles, hence
this 20Mhz crystal makes this PIC16F84A run at 5.0 MIPS (Million of instructions per second).
 PORTB is used here to connect PIC16F84A with the seven segment display. RB0 pin is attached with
the ‘a’ segment of the seven segment display. Similarly, RB1 pin is connected with ‘b’ segment, RB2
pin is connected with ‘c’ segment and so on.
 Common cathode seven segment display is used in this example. We can easily modify this circuit and
code for the common anode seven segment display as well.

Dr. Khairil Ezwan Kaharudin


MEE 1133: Advanced Microcontroller

Programming the Seven-segment LED


The Common Cathode (CC)
In the common cathode display, all the cathode connections of
the LED segments are joined together to logic “0” or ground.
The individual segments are illuminated by application of a
“HIGH”, or logic “1” signal via a current limiting resistor to
forward bias the individual Anode terminals (a-g).

Dr. Khairil Ezwan Kaharudin


MEE 1133: Advanced Microcontroller

Programming the Seven-segment LED


The Common Anode (CA)
In the common anode display, all the anode connections of
the LED segments are joined together to logic “1”. The
individual segments are illuminated by applying a ground,
logic “0” or “LOW” signal via a current limiting resistor to
the Cathode of the segment (a-g).

Dr. Khairil Ezwan Kaharudin


MEE 1133: Advanced Microcontroller

Free running counter implementation using PIC16F84A

Dr. Khairil Ezwan Kaharudin


MEE 1133: Advanced Microcontroller

PIC16F84A free running counter implementation C code


 The following function is used in the code to display values on the seven segment display.

 For example, to display '0' on the


seven segment display, we can call
this function in the main as
DisplayOn7Segment('0');.

Dr. Khairil Ezwan Kaharudin


MEE 1133: Advanced Microcontroller

PIC16F84A free running counter implementation C code


 The code for the main function is shown below.

 In the main function code, a variable 'ch' is


displayed on the seven segment display.
 Then there is a delay of about 1 second.
 After that, a new value of ch is selected using
the switch statement.
 Then the new value present in ch variable is
displayed on the seven segment.
 This process continues forever.

Dr. Khairil Ezwan Kaharudin


MEE 1133: Advanced Microcontroller

A Demonstration Board
A demonstration board, also known as a
demo board, is a useful tool in mastering
PIC programming. Many are available
commercially; like programmers, there is
a cottage industry of PIC demo boards on
the internet. Constructing your own demo
boards and circuits is not difficult. The
components can be placed on a
breadboard, or wire-wrapped onto a
special circuit board, or a printed circuit
board can be homemade, or ordered
through the internet. Figure (next) shows
a simple 16F84A-based demo board with
a seven-segment LED, buzzer,
pushbutton switch, and a bank of four
toggle switches.

Dr. Khairil Ezwan Kaharudin


MEE 1133: Advanced Microcontroller

THANK YOU

Dr. Khairil Ezwan Kaharudin

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy