PIC16F84A Microcontroller Introduction and Features
PIC16F84A Microcontroller Introduction and Features
PIC16F84A Microcontroller Introduction and Features
This tutorial is an introduction to PIC16F84A microcontroller. We will talk about
pinout, main features, different GPIO ports, How to use these input outputs pins to
blink an LED or control a switch button and how to use timers of PIC16F84A. Let’s
start with history of these microcontrollers.
It has thirtheen GPIO pins and each pin can be used either as digital input or
digital output.
These 13 GPIO pins are shared with PORTA and PORTB.
PORTA consists of 5 pins from RA0-RA4 and PORTB has 8 pins from RB0-RB7.
You can also consult with the datasheet for further information.
Specifications
PIC16F84A specifications
RAM 68 Bytes
EEPROM 64 Bytes
Supports ICSP: ICSP stands for In-Circuit Serial Programming. With little careful,
you can program the microcontroller deprived of eliminating it from the target
board for example in-circuit. This is widely used for in-circuit programming as it
contains a USART module.
Registers: There are two types of registers which are as follow here.
General Purpose Registers (GPR): These general purpose registers are used
to store any arbitrary value in which you can operate.
Special Function Registers (SFR). The special function registers are used to
perform various functions which can help to control the device.
Timer: PIC16F84a contains one 8-bit timer that can be utilized in both ways i.e.
timer and counter. Furthermore, accompanies internal and external clock select
capability.
Sleep Mode: This mode is included the chip that produces a low current power
down mode. The sleep mode can be removed using an interrupt, external reset,
and watchdog timer.
Power on Reset: This feature is utilized in various other PIC microcontrollers when
it is powered on. If there arises a problem in the chip, powering on the device will
dismiss it from the loop of any malfunctioning in the device.
PIC16F84a Projects: This version of PIC controllers are mostly used in students
projects where the main concern is automation. This is also used in Central heating
projects, Production of the temperature data logger, and gas sensor projects. Also
used in security systems and setting up serial communication with other devices.
Compilers: PIC controller has different compilers MPLAB C18 Compiler and MikroC
Pro for a compiler. The code written in the compiler creates a hex record that is
transferred on the PIC Microcontroller.
Ram Memory Banks: the RAM is consist of four banks. Before accessing any
register during the time of programming or program writing, you must need to
select the particular bank which contains that register. Handling banks may be
steep if you write the code in assembly language.
Flash Memory: This consist of Flash memory based on 8-bit microcontroller packs.
The same microcontroller device can be used for prototyping and production.
We are using Mikro C for pic to write code for LED example. But if
you have no idea about Mikro C for pic and did not use it before.
you can read our step by step guide on how to create project and
write code with Mikro C for pic.
There are two registers used for GPIO pins of PIC16F84A and these registers are
also same in almost all microchip family of 16F and 18F.
TRISX registers
This register is used to define GPIO pins either as a digital input or output. PORTA
has TRISA register and PORTB has TRISB register. Both these registers are bit
addressable. For example, if you want to define RB0 pin as digital output pin,
Follow command will declare RB0 as a digital output pin.
TRISB.B0=0;
Here TRISB define PORTB direction control register and B0 defines pin number
zero or RB0. Initializing any pin with zero using TRISX register will declare it a
digital output and if you initialize it as with 1, it will declare it as pin as a digital
input pin like this:
TRISB.B0=1;
Now, if you want to make digital pin logical HIGH, you simply assign it as value 1
and otherwise 0. Like following examples.
PORTB.B0=1; // assign logical high to RB0
PORTB.B1=0; // assign logical low to RB1
PORTA.B3=1; // make RA3 output high or 5 volt
PORTA.B3=0;
This sketch will make the LED toggle with a delay of once second.
void main()
{
TRISB.B0=0;
PORTB.B0=0;
while(1)
{
PORTB.B0=1;
delay_ms(1000);
PORTB.B0=0;
delay_ms(1000);
}
}
Upload hex file to pic microcontroller and you will see LED blinking.
Code
// Constants
#define E_Delay 500
void ToggleEpinOfLCD(void)
{
LCD_E = 1; // Give a pulse on E pin
delay_us(E_Delay); // so that LCD can latch the
LCD_E = 0; // data from data bus
delay_us(E_Delay);
}
void InitLCD(void)
{
// Firstly make all pins output
LCD_E = 0; // E = 0
LCD_RS = 0; // RS = 0
LCD_Data_Bus_D4 = 0; // Data bus = 0
LCD_Data_Bus_D5 = 0; // Data bus = 0
LCD_Data_Bus_D6 = 0; // Data bus = 0
LCD_Data_Bus_D7 = 0; // Data bus = 0
LCD_E_Dir = 0; // Make Output
LCD_RS_Dir = 0; // Make Output
LCD_Data_Bus_Dir_D4 = 0; // Make Output
LCD_Data_Bus_Dir_D5 = 0; // Make Output
LCD_Data_Bus_Dir_D6 = 0; // Make Output
LCD_Data_Bus_Dir_D7 = 0; // Make Output
delay_us(300);
delay_ms(2);
delay_ms(2);
/////////////// Reset Process End ////////////////
WriteCommandToLCD(0x28); //function set
WriteCommandToLCD(0x0c); //display on,cursor off,blink off
WriteCommandToLCD(0x01); //clear display
WriteCommandToLCD(0x06); //entry mode, set increment
}
void ClearLCDScreen(void) // Clear the Screen and return cursor to zero position
{
WriteCommandToLCD(0x01); // Clear the screen
delay_ms(2); // Delay for cursor to return at zero position
}
// Main function
void main()
{
InitLCD(); // Initialize LCD in 8bit mode
Code
void interrupt(void)
{
if( INTCON.INTF) // check if interrupt occurs due to external event on RB0
{
PORTA.B0 = ~PORTA.B0; // Invert the state of RA0 pin
while(1)
{
}
}
As you can see inside the while loop, we are not executing anything and
state of LED will change on interrupt only.
Further explanation of control registers is given in this picture.
You will see a square wave on oscilloscope.
void interrupt(void)
{
if(INTCON.T0IF) //If Timer0 Interrupt
{
while(1)
{
}
}
UART Protocol 1
you may also like to check pic microcontroller based projects list.
Email Address
SUBSCRIBE
Leave a Comment
Name *
Email *
Website
POST COMMENT
Advertisement
Subscribe to Blog via Email
Email Address
SUBSCRIBE
Categories
Select Category
Recent Posts
HC-SR04 Ultrasonic Sensor with STM32 Nucleo using STM32CubeIDE
STM32 Nucleo Timer in Counter Mode with STM32CubeIDE and HAL Libraries