![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
Hi! i need to make an up/down counter using a pic16f877, the count must b from 0 to 9 and 9 to 0 via PortD and must b displayed on a 7-segment display. The control of the counting cycle must b done using two switches connected to PortA switch 1 = Up (0-9) switch 2 = down (9-0) Reversal of the count must continue from previous count (don't reset counter when changing from switch1 to 2 or vice versa) I know how to do this as i'v builded a counter before and displayed on a 7-segments! the tricky part is the reversal of the counting sequence! i don't know how to do it! what i mean is i can hav two sub routines, 1 for UP another for down, and i'll do a bit test to call them (or goto) but how would i make the pic remenber the previous count? thanx | |
| |
| | #2 | |
| Quote:
![]() You would assign a Register as say 'Count'. The UP switch would increment the Count value and the DOWN switch would decrement the Count value. After the Count value has been changed you output that value to the display. The UP/DOWN subr would require code that detects > 9 and < 0. Is this what you are asking.? EDIT: if it was necessary to remember the Count value during power down, use the EEPROM to hold the Count.
__________________ Eric " Good enough is Perfect " I will NOT answer PM's requesting technical help, please use the Forum PIC tutorials: Nigel's www.winpicprog.co.uk/ Bill's: www.blueroomelectronics.com/ Last edited by ericgibbs; 10th September 2008 at 08:39 AM. | ||
| |
| | #3 |
|
Thanx eric how would i display the value of count(register) on the display? so far what i do is turning on (set) the pins of the pic wich r connected to the display in order to count! can u tell me to detect >9 and <=0 ?
| |
| |
| | #4 | |
| Quote:
Can you post the code you have written.?
__________________ Eric " Good enough is Perfect " I will NOT answer PM's requesting technical help, please use the Forum PIC tutorials: Nigel's www.winpicprog.co.uk/ Bill's: www.blueroomelectronics.com/ | ||
| |
| | #5 |
|
You might have a look at my seven segment tutorial, while it uses two displays and counts from 0 to 99, it does pretty well what you want.
| |
| |
| | #6 |
|
like i said b4, all i can do is to set the pins that r connected to the display in order to count. this is jus a short section of the code LIST p=16F877 #include <P16F877.inc> __config _XT_OSC & _PWRTE_ON & _WDT_OFF &_LVP_OFF ;*****Equates************************************* ********* status equ 03h PortA equ 05h PortD equ 08h TRISA equ 85h TRISD equ 88h count0 equ 25h count1 equ 26h count2 equ 27h ;******Main Program**************************************** org 05h bsf status,RP0 movlw B'11111111' ; set portA as input movwf TRISA movlw B'00000000' ; set PortD as outpout movwf TRISD movlw D'6' movwf ADCON1 bcf status,RP0 start btfsc PortA,0 goto up btfsc PortA,1 goto down goto start up movlw b'11101111' ; display 0 movwf PortD call delay movlw b'10001001' ; display 1 movwf PortD call delay movlw b'11010111' ; display 2 movwf PortD call delay movlw b'11011101' movwf PortD call delay movlw b'10111001' movwf PortD call delay delay movlw 05h Movwf count2 Loop decfsz count0,1 Goto Loop Decfsz count1,1 Goto Loop Decfsz count2,1 Goto Loop Return End i also know that i can assign a register, increment it and send it to PortD! but how would i display the values? sice the count will b in binary! plus how to stop at 9? | |
| |
| | #7 | |
| Quote:
| ||
| |
| | #8 |
|
hi josi, As I understand, you have one digit to display, with a value of 0 to 9 Which is 00000000 thru 00001001 so where is the binary number you refer too.? Its BCD If you connect the LOW PORTD pins to a 7447 BCD to 7 segment driver it will show decimal 0 thru 9 on the LED. Do you follow.? EDIT: Code fragment. Code: ;test for > 9 MOVLW 0x09 ;load Wreg with 9 SUBWF Counter,W ;sub Counter from W reg BTFSC STATUS,C ;if carry set goto to inc GOTO its9 ;its 9 already ;inc the counter value its9: ................................ ;test for 0 MOVF Counter,W ;load W with Counter SUBLW 0x00 ;sub 0 from W BTFSC STATUS,Z ;if zero skip dec GOTO its0 ;dec the counter value its0:
__________________ Eric " Good enough is Perfect " I will NOT answer PM's requesting technical help, please use the Forum PIC tutorials: Nigel's www.winpicprog.co.uk/ Bill's: www.blueroomelectronics.com/ Last edited by ericgibbs; 10th September 2008 at 10:09 AM. | |
| |
| | #9 | |
| Quote:
| ||
| |
| | #10 | |
| Quote:
The point of PIC's is to simplify designs, not to add old IC's that you don't need. | ||
| |
| | #11 | |
| Quote:
As Nigel points out, for 7 seg displays a 7447 isn't necessary. I thought you had already connected one. ![]() Look at the tutorials. Hint: a look up table of the segment pattern is whats needed, using the BCD counter value as a table pointer .OK.?
__________________ Eric " Good enough is Perfect " I will NOT answer PM's requesting technical help, please use the Forum PIC tutorials: Nigel's www.winpicprog.co.uk/ Bill's: www.blueroomelectronics.com/ | ||
| |
| | #12 |
|
guys i know this is an old topic. can you post the code in picbasic form?
| |
| |
|
| Tags |
| counter, up or down |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| Counter (when counter > x, vibrate) | adwilk | Electronic Projects Design/Ideas/Reviews | 6 | 15th May 2008 11:16 AM |
| Innovation for Cash Counter>>Letter Size Page Counter-Is This Possible | mycam524 | Electronic Projects Design/Ideas/Reviews | 2 | 26th November 2007 09:29 AM |
| Counter 555+ 4 bit binary counter | psymon | Electronic Projects Design/Ideas/Reviews | 12 | 25th April 2007 09:51 AM |
| counter emf | jin29_neci | General Electronics Chat | 18 | 1st September 2005 08:42 PM |
| Mod 5 counter | digital_geek | Electronic Projects Design/Ideas/Reviews | 7 | 10th July 2005 05:42 PM |