Skip to main content

UP & Down Counter Prrograme using PIC16F877

PIC16F877 up down counter code + Proteus
simulation


This PIC16F877 microcontroller tutorial answers the question,
" How to implement a up down counter using PIC16F877 ? "
Using PIC16 simulator (Proteus) you can verify this counter code and change it
according to your needs. Using one push button (Labeled as Count, as shown
in figure below) you can increment (When SW1 switch is towards up position) or
decrement (When SW1 switch is towards down position) count value (displayed
on LCD) as you desire. This code is written in C language using MPLAB with
HI-TECH C compiler. You can download this code from the 'Downloads' section
at the bottom of this page.
In this article, it is assumed that you know, how to interface LCD with
PIC16F877 microcontroller. If you don't then please read this page
/pic16f877-lcd-interfacing-code-in-8bit.html] .
The following diagram (made in Proteus) shows the PIC microcontroller circuit
diagram.


Figure 1. PIC16F877 based up down counter circuit
The above figure was taken after pressing Count button 4 times. SW1 switch
position is set towards 'Up' position, hence count value was incremented with
each press of Count button. LCD is updated with the new value of count after
every 200 milli second.
You can set SW1 switch to 'Down' position and then after pressing Count
button, count value will decrement. When count value reaches 100 then it resets
to 0 value again.
A crystal of 20MHz value is used in this circuit, which makes this PIC16F877
run at a speed of 5MIPS (Million of instructions per second). You can use any
other value of crystal ( From 0 to 20 MHz value only) as well.
The main function code is shown below.
PIC16F877 up down counter code + Proteus
simulation
Code

Figure 2. Main function code for up down counter on PIC16F877
In the main function, firstly LCD is initialized using InitLCD() function. Then
Count button pin and Up/Down button pin is made input. Then LCD screen is
cleared and "Starting..." is displayed on the LCD for half a second.
After that, in the while(1) loop, depending up the value of Up_Or_Down button
input value, Count variable is either incremented or decremented. In the end,
Count value is displayed on the LCD after clearing the LCD screen.

Comments

Popular posts from this blog

What is Transducers

About a Transducers. ट्रांसड्यूसर का मतलब है एक एनर्जी को दोसरे एनर्जी में बदलना। ये तो होता है किताब का परिभाषा but मेरे language में ट्रांसड्यूसर एक दुनिया को दूसरे दुनिया से जोड़ने का पुल है। क्योंकि बिना ट्रांसड्यूसर के हम एक एनर्जी फॉर्म को दूसरे एनर्जी फॉर्म में बदल ही नही सकते मतलब इलेक्ट्रान के flow को अगर हमें डिस्प्ले पर देखना है तो हमे एक ऐसे मध्यम की जरूरत होती है जो उस इलेक्ट्रान को हमारी आंखों के पढ़ने के लायक बना सके। हम हिंदी समझते जरूर है पर हमारा दिमाग का अपना एक अलग लैंग्वेज है वो उसको हमे समझने के लायक करता है उसी तरह से ट्रांसड्यूसर भी एक एनर्जी को दूसरे फॉर्म में बदलता है। अब बात करते है सबसे सिंपल ट्रांसड्यूसर की , आजकल सभी लोग ऑटो रिक्शा में सफर करए है अबतो फिलहाल इलेक्ट्रिकल हॉर्न चलता है पहले के रिक्शा ड्राइवर हाथ से दबाने वाला हॉर्न इस्तेमाल करते थे वो हॉर्न सबसे अच्छा example है ट्रांसड्यूसर को समझने के ...

WPLSoft Instruction

WPLSoft Instruction. सबसे पहला इंस्ट्रक्शन आता है LD means Load a Contact. ----] [---- ये इसका symbol है इस इंस्ट्रक्शन का उसे पीएलसी के किसी भी इनपुट को veryfy करने के लिए किया जाता है एक तरह से कह सकते है की यह ladder diagrame में इनपुट की तरह काम करता है पीएलसी के इनपुट एड्रेस को इसी पर दिया जाता है यह NO एलिमेंट की तरह काम करता है. 2:- LDI means NC element ये एक NC एलिमेंट की तरह होता है बाकी सं LD इंस्ट्रक्शन की तरह ही काम करता है. 3:-TMR मीन्स टाइमर. यह पीएलसी का टाइमर होता है यह दो टाइप्स का होता है एक On delay एंड Of Delay. ज्यादातर on delay का ही use किया जाता है ऑफ डिले का use जरूरत पड़ने पर किया जाता है TMR में दो सेट पॉइंट होते है एक S1 और दूसरा S2, S1 का मतलब होता है timer का no मतलब कोनसा timer है और S2 का मतलब होता है Delay time in second या mili second जैसे ही हैम timer के input को on करते है timer अपना time vallue या set vallue counting सुरु कर देता है और जैसे ही उसका टाइम पूरा होता है वो एक output भेज देता है वो आउटपुट T0 या जो भी Timer का no है उसके साथ T लगाकर एक NO ...