In this experiment, we will program the PIC16F628A as an UP/DOWN Decade Counter. The count value will be displayed on a Seven-Segment Display and will be incremented/decremented by two push buttons on the board.
Experimental Setup:
The board has built in interface for a multiplexed 4-digit seven segment display (HS-5461AS2 from www.futurlec.com).We will select only one digit by connecting a Digit Select pin to Vcc, as shown in figure below. A black jumper wire is used for this purpose. The seven segments will be driven through PORTB (already wired on the board). Connect Push Buttons (PB3 and PB4) to RA1 and RA0 female headers using jumper wires.
Here is the complete C program written for mikroC for PIC 2009.
Experiment Output Video:
Experimental Setup:
The board has built in interface for a multiplexed 4-digit seven segment display (HS-5461AS2 from www.futurlec.com).We will select only one digit by connecting a Digit Select pin to Vcc, as shown in figure below. A black jumper wire is used for this purpose. The seven segments will be driven through PORTB (already wired on the board). Connect Push Buttons (PB3 and PB4) to RA1 and RA0 female headers using jumper wires.
Software:
We will use in-built 'Button Library' to detect push button press.
/*
* Project name:
UP/DOWN Decimal Counter with Push Button and 7-Segment Interface
* Copyright:
(c) Rajendra Bhatt, 2009.
* Description:
This code is an example of Seven Segment Display and Push Button interface.
A decimal counter value will be displayed on the seven segment display.
The value of the counter can be incremented or decremented through push
buttons.
* Test configuration:
MCU: PIC16F628A
The two push buttons are connected to RA0(Increment) and RA1(Decrement)
and the seven segment display connected to PORTB (Segment a to PB.0,
Segment b to PB.1 and so on)
*/
//-------------- Function to Return mask for common cathode 7-seg. display
unsigned short mask(unsigned short num) {
switch (num) {
case 0 : return 0x3F;
case 1 : return 0x06;
case 2 : return 0x5B;
case 3 : return 0x4F;
case 4 : return 0x66;
case 5 : return 0x6D;
case 6 : return 0x7D;
case 7 : return 0x07;
case 8 : return 0x7F;
case 9 : return 0x6F;
} //case end
}
unsigned int digit; // To Hold Decimal Value
unsigned short number; // To Hold Equivalent Seven Segment Value
void main() {
CMCON |= 7; // Disable Comparators
TRISB = 0x00; // Set PORTB direction to be output
PORTB = 0x00; // Turn OFF LEDs on PORTB
TRISA0_bit = 1; // PA.0 Input for Increment
TRISA1_bit = 1; // PA.1 Input for Decrement
digit = 0; // Initial Value of Counter
number = mask(digit) ;
PORTB = number;
do {
if (Button(&PORTA, 0, 1, 0)) { // Detect logical one to zero
Delay_ms(300);
digit ++; // Increase Counter
number = mask(digit) ;
PORTB = number;
}
if (Button(&PORTA, 1, 1, 0)) { // Detect logical one to zero
Delay_ms(300) ;
digit = digit-1; // Decrease Counter
number = mask(digit) ;
PORTB = number; // Update flag
}
} while(1); // endless loop
}
Experiment Output Video:
i am very interest in this project pls send circuit diagram and source code in my mail id kavi.paradise@gmail.com
ReplyDeleteHello Mr.Raj.I'm quite interested in your project.But I'm using MPLAB.Can I do it in there?If I can then please send me the circuit diagram and the source code.Thanks...
ReplyDeleteMy mail id = samitbsk6@googlemail.com
I am using mikroC for writing the software for PIC. It is an high level (C) compiler. You can use MPLAB but then you have to write in assembly language. I don't have specific circuit diagrams, all the projects I am doing are on my board. The circuit diagrams of my development board is here.
ReplyDeletehttp://pic16f628a.blogspot.com/2009/09/pic16f628a-development-board-part-1.html
hi..im interesting to your..i want two decimal digit..but my problem is what codes can i use and condition..can you help me..TIA
ReplyDeletehi.. im interesting to your project..i want two decimel digit to count..it is possible?..i have codes..but the problem is nothing display or output in the seven segment..do you have any idea..TIA
ReplyDeleteDo you know how to code for pic18f4520?
ReplyDeleteHi, I am new in learning C program for PIC. Do you mind to explain the code:
ReplyDelete" unsigned short mask( unsigned short num)"
thank you
hi
ReplyDeletemerci deja pour votre très grand travail
votre programme est très intéressant
mais comment donner un nombre au depart comme 473 avant de commencer a compter ou decompter
merci cordialement
I cant find code of Button function. can you please show me
ReplyDelete