Up Down Counter - MPLAB code - Proteus Simulation - PIC 16F877A - LEDs


Problem - Design an Up Down counter for PIC 16F877A.

Software Support - MPLAB IDE for C programming,Proteus for simulation purpose.

Components - PIC 16F877A- Micro controller,SPDT switch as input,LEDs for output.

Theory :-

The program should work as follow,
If switch is high,then it must work as up counter.
If switch is low,then it must work as down counter.

In this program,switch is connected to RD3,LEDs to lower pins of port B.
It will check for switch status continuously and when 
high,Port B is incremented 
low,Port B is decremented

Value in port B is multiplied by 0x0F so it remain as a 4 bit counter. 


Circuit Setup & Output :-

Program:-

#include<pic.h>
#define _XTAL_FREQ 1000000
void main()
{
TRISB=0;
while(1)
{
if(RD3==1)
PORTB=(PORTB+1)&0X0F;
else
PORTB=(PORTB-1)&0X0F;
__delay_ms(500);
}
}

For more PIC 16F877A programs - click here

Popular posts from this blog

Mini Militia Chat Codes - Shortforms

8051 Assembly Program Code for Sorting in Ascending Order - Keil -AT89C51