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.

Help pls. Up/Down counter, two buttons, PIC 16872-I/sp, 7 segment

Status
Not open for further replies.

Rapetacular

Newbie level 3
Newbie level 3
Joined
Dec 21, 2014
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
32
So I'm pretty new and raw to this whole programming thing...
If anything I'm close to clueless and to be honest it feels like being thrown in the ocean not knowing how to swim. ._.''

Essentially I need help with coding a PIC 16872-I/sp.
The goal calls for two buttons to count up and down with a limit of 9

one button to increase the count
one button to decrease the count

depends on the buttons pressed at a certain amount, the total will be displayed in the 7 segment.

BUT the 7 segment should not display over 9 until its counted down.
Because 9 is the limit...

I really hope that's pretty clear and you guys could help me D:
Future hangin' in balance and all that.

More info;
Compiler: Mplab
7 segment: http://www.electron-pv.com/images/ebay_pic/man72a-1.gif (simillar to these, we got two of these, supply was limited :c)
 

If I understand correctly you need a C code for your project and your system will have a single 7 Segment and it will display 0 to 9 digits and there will be two buttons, one to increment and other to decrement. Right ? If yes, then do you want the display to show 9 when decrement is pressed and the previous value was 0 and do you want the display to show 0 when increment button is pressed when the previous displayed digit was 9 ? Are you going to use Common Cathode or Common Anode 7 Segment display ? Can you post your circuit ? Does your system do any other thing other than displaying 0 to 9 digits, because if it has to do other things then interrupt has to be used for 7 Segment display else it can be done without Timer interrupts.

MPLAB and MPLAB X are IDE's and not compilers. Are you using Hi-Tech PICC, PICC18, C18 or XC8 Compiler ? If yes, which one ?
 

To count using 7 segment from 0 to 7 using buttons, all you need is to keep checking Pin status using button and Pull up or Pull down resistor.

Code:
   TrisB = 0xFF;
   PortB = 0xFF;
   TrisC = 0x00;
    PortC = 0x00;


   While(1){
       If(Rb0 ==0) cnt++;
      If(Rb1==0) cnt --;
        PortC =table[cnt];
    
}
Array Table contains binary or hex value from 0-9
 

Code:
While(1){
   If(Rb0 ==0) cnt++;
   If(Rb1==0) cnt --;
   PortC =table[cnt];
}
Gives a basic idea, but won't actually work. Debouncing and key-press event detection is missing. Also the said counter constraints.
 

Hey there :D
Thanks for the speedy reply guys

Yep, we need one button to increment, and the other to decrement.
Yep, well kinda, we need the display to be constantly lit with total value. So we know what the total is in real time.
Im not entirely sure :s. the words "5082-7653, 319 E TH" are imprinted on the side.
It only requires to display the numbers from 0 to 9.

as for the circuit, i'll try to make one soon and post it up here.
Again i'd like to apologize if im being hard on the details, I blame my lack of knowledge on these things D:
And also thank you for helping out.
 

There will be one transistor driving the 7 Segment display. See if it is BC547 or BC337 or BC557. If it is any other transistor then mention the part name.
 

Unfortunately, thats pretty much all i can see from the 7segment LED
It just says "5082-7653, 319 E TH".

As for the transistor apparently we've only got a BC547. though i think we can get a replacement if its not the right one?
 

Start with making a state Diagram of all inputs and outputs ( including transient switch contact states)

Your inputs are 2 switches Normally Open (NO) connected to ground or Vcc with SIP resistors or discrete R's to the other polarity.

Your Outputs are either 7 segments for Common Cathode LED you specified or using a BCD to 7Seg chip.. Your homework is 7 segment out ( direct non multiplexed)

Next make a truth table for each decimal state 0~9 and define the logic in truth tables then in code for count up and down separate from decoder for binary to 7segment for a decimal number. THis is well documented.

Define overall functions then break down into smaller functions or routines.

Common Cathode means common (-) to ground and positive logic level thru series limited R to turn on LED for 10mA or so. or 200mA Max. to all segments.

The 8th bit can be used for the decimal point or DP LED.

Red LEDs need > 2V. typ (2.5V max) so uC with 3.3 or 5V affects series R per segment choice using Ohm's Law.

- - - Updated - - -

You wont need any transistors for 1 Digit. as the PIC can drive each LED direct with a series R. Keep in mind all drivers have an equivalent series R ( which also has a temperature coefficient) We call this ESR.

Can you see the value of ESR from the slope of these curves? When choosing Vcc and R just subtract the ESR of the driver from the Rs value needed for its Voltage drop required.
pic Vol.jpg

Electrical specs like this are always near the end of the 200 pages PIC specs.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top