Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Button Input BCD/7 Seg. output?

Status
Not open for further replies.

lburrowes

New Member
What I want to do is have a button connected to Port A, 0

I want to push the button N amount of times and then display it on a
BCD
encoder that I have hooked to RA1-4.

The amount of time I want it to wait before it ouputs to the BCD is
about
5-10 seconds then after it outputs the BCD then it will just stop.


---------------------
LIST P=16F84A
INCLUDE "p16f84A.inc"

CBLOCK 0CH
count ; count storage
ENDC
;**********************
; CPU EQUATES
;**********************


#DEFINE BTN PORTA, 0


org 0x00
goto main ; jump over to main routine

;****************
;Port Init
;****************
Init:
clrf PORTA
clrf PORTB

movlw B'00000111' ; RA0-2 input, others outputs
; tris PORTA
movlw B'00000000' ; RB all outputs
; tris PORTB

; option
return

;**************************
;Lookup table for BCD
;**************************

LEDLOOKUP:
addwf PCL, f
retlw 0x00 ;led drive za 0
retlw 0x01 ;1
retlw 0x02 ;2
retlw 0x03 ;3
retlw 0x04 ;4
retlw 0x05 ;5
retlw 0x06 ;6
retlw 0x07 ;7
retlw 0x08 ;8
retlw 0x09 ;9

return


;**************************
;Delay Subroutines
;**************************

onesecond: ; a subroutine that delays for 1 seconds
call msec250
call msec250
call msec250
call msec250
return

msec40 movlw D'40' ; 40 msec delay entry point
goto nmsec
msec250: ; a subroutine to delay 250 msec
movlw D'250' ; W is changed but no separate register needed
nmsec: ; could call it here with # msec in W
nop ; each nop is 0.122 milliseconds
nop
nop ; each total loop is 8 X 0.122 = 0.976 msec
nop
addlw 0xFF ; same as subtracting 1 from W
btfss STATUS, Z ; skip if result is zero
goto nmsec ; this is 2 X 0.122 msec
return ; back to calling point


;*******************
;Main Program
;*******************
main:
call Init ; initialize ports, set up timer
call press
movf count, w ; Display number in binary
movlw PORTB

press:
btfss BTN ; wait until pushbutton
incf count ; increment
call onesecond ; wait 5 seconds
call onesecond
call onesecond
call onesecond
call onesecond

return

; doThis call BUTNPRESS
; movf LEDLOOKUP, w ; Get lookup received
; movwf portB ; Display on 7 segment display
; circle goto doThis ; Done
; movwf portB ; Display on 7 segment display

end
 
But what is your question?

Does your programme work? Or do you need help with the hardware?

Your post is not specific.
 
This is advice that should be put into a sticky...

***Always debug in small, incremental steps.***

If you throw together something that does a bunch of things not only are you making it difficult to debug, but you are also making it less likely that anyone will help you find the problem.

First. Write a program to turn an LED on.
Second. Write a program to turn the LED on when a button is pushed.
Third. Write a program to display a number on your display.
THEN put the whole thing together.

Mike
 
There are parts of the code that will not run.. After onesecond.

Also, you will want press in a loop with debounce (or release check) for 5 seconds.

Maybe tie the button to an interrupt line, and bump the counter and just have the main loop 5 seconds?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top