Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

4 bit binary counter

Status
Not open for further replies.

hemnath

Advanced Member level 3
Joined
Jun 24, 2012
Messages
702
Helped
61
Reputation
120
Reaction score
57
Trophy points
1,308
Location
Chennai
Activity points
6,588
can anyone help me how to do 4 bit binary counter program using pic microcontroller in ccs c compiler?
 

What kind of help you are looking for.
 

4-bit binary counter (using 4 LEDs) that counts from 0 to 15 (0000-1111 binary). four LEDs are connected to RB0 through RB3 port pins of PIC18F2520. A push button switch is connected to pin RA1 to provide input for the counter. The counter starts from 0, and increase by 1 every time the button is pressed. When the counter reaches 15 (all LEDs on), it will reset to 0 on the next press of the button.

pls explain how to do in ccs c compiler?

- - - Updated - - -

This is i ve tried in CCS c compiler. please correct me if wrong


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "18F2520.h"
#fuses HS,NOPROTECT,INTRC_IO
#use delay(clock=4000000)
 
#define PUSH_BUTTON PIN_A1
 
void main()
{
setup_oscillator(OSC_4MHZ);
set_tris_a(0x02);
set_tris_b(0x0F);
 
int count;
count = 0;
do
{
if(input_state(PUSH_BUTTON)==0)
{
count++;
output_b(count);
}while(count==16) count=0;
}while(1);
}

 
Last edited by a moderator:

my program works fine with certain changes. when i pressed the button once, corresponding LED must glow. but due to switch bouncing, i've got some problem. i have reduced with some delays in the program. but still i want a perfect solution. how to do debouncing program in ccs c compiler? please help me.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top