In: Electrical Engineering
) Design a simple embedded system with PIC16F84A microcontroller (using 20MHz resonator). The system can drive a LED light on for 52.6ms on and 26ms off repeatedly. A watchdog timer should be enabled and have a time out period of 72 ms. Sketch the circuit and write the complete assembly program.
Assembly Program:
Basics of PIC 16F84A Microcontroller which is useful to solve this problem
1.It is an 8 bit microcontroller.
2.It has two PORTS named as PORT A and PORT B which are used to interface interface input / output devices.
3.PORT A has 5 I/O pins.
4.PORT B has 8 I/O pins. A total of 13 I/O pins available in PIC 16F84A
5.TRIS register is used to configure these 13 pins as input or output pins.
6.To make all the port A pins as input pins, TRIS A should be set as 1.
7.If TRIS <pinno> = 1 it configures particular pin as input.If TRIS <pinno> = 0 then particular pin acts as output.
Initial assumptions for the given question:
1.let us consider the led light is connected to PORT B5.
2. Initially that particular B5 should be configured as output because microcontroller is driving an led light by supplying 5V.
3.Using TRIS B register configure that particular pin as output, i.e. TRISB5=0.
MAIN PROGRAM:
Program is written in C language
#include<pic.h> / Include all the supported PIC files
#include<htc.h> / Include the hitech compiler files
#define _XTAL_FREQ 20000000 /Define theexternalclock frequency 20 Mhz
void main()
{
TRISB5 = 0 / Configuring the PIN B5 as output pin using TRIS B register
PORTB =0b00000000 / Initially resetting all the pins which means supplying 0V to the led light. b indicates binary. There are 8 pins in port b so all the 8 pins are assigned 0 initially.
WDTE = 1 /Enabling the watch dog timer
OPTION_REG = 0b00001010 / Configuring the watch dog timeout peroid to 72 ms i.e making B0,B1,B2 as 0,1,0 respectively.
while(1) / loop executes continuously
{
WDTON(); / Watch dog timer function is on which implies count starts from 72ms to 0ms
PORTB = 0b00100000 ; / order is 0bB7 B6 B5 B4 B3 B2 B1 B0. In our assumption led light is connected to B5 pin so that B5 pin isset high which implies 5V is suppiled.
__delay_ms(52.6) ; / delay_ms is a function which takes milliseconds as arguments. Here led is turn on and we are delaying the next action by 52.6 ms
PORTB = 0b00000000; / allthe pins are resetted which means led is off
__delay_ms(26) ; /led is off for 26 ms
CLRWDT(); /clearing the counter
}
}
Embedded circuit connection diagram:
1. Here led light is connected to pin 12 i.e. PORT B5.
2.Microcontroller is powered by 5 V power supply which is connected at 16th pin i.e Vdd pin.
3.Ground is connected to Vss pin i.e pin no. 5.
CIRCUIT: