Hi Colin I've changed the email address above because your inbox will be swamped with spam email. Automatic search bots find these addresses and fill them with rubbish. Never put an unaltered email address on a web page.
(John Main)
Sep 30, 2007
ASM file by: Colin Mitchell
;Project: Count Inputs on RA4 List P = 16F84 #include __CONFIG 1Bh ;_CP_OFF & _PWRTE_ON & _WDT_OFF & _RC_OSC
fileA equ 20h fileB equ 21h swflag equ 25h
ORG 0 ;Load the code at address 000 SetUp BSF 03,5 ;Select Bank1 MOVLW 10h ;Put 0001 0000 into W MOVWF 05 ;Load TrisA. Make RA4 input. Others output BCF 03,5 ;Select Programming area - Bank0 GOTO Main
;1mS delay
_1mS decfsz fileA,1 goto _1mS retlw 00
;100mS delay
_100mS movlw 60h movwf fileB AA call _1mS decfsz fileB,1 goto AA retlw 00
Main CLRF swflag CLRF 05 ;Clear Port A Main1 CALL _1mS BTFSS 05,4 ;Test the input line GOTO Main2 btfsc swflag,0 ;first time? GOTO Main1 bsf swflag,0 bcf 05,2 ;turn off the third line bsf 05,0 ;turn on the first line goto Main1 Main2 btfss 05,0 ;Is first line ON and no input signal? GOTO Main1
CLRF swflag Main3 CALL _1mS BTFSS 05,4 ;Test the input line GOTO Main4 btfsc swflag,0 ;first time? GOTO Main3 bsf swflag,0 bcf 05,0 ;turn off the first line bsf 05,1 ;turn on the second line goto Main3 Main4 btfss 05,1 ;Is second line ON and no input signal? GOTO Main3
CLRF swflag Main5 CALL _1mS BTFSS 05,4 ;Test the input line GOTO Main6 btfsc swflag,0 ;first time? GOTO Main5 bsf swflag,0 bcf 05,1 ;turn off the second line bsf 05,2 ;turn on the third line goto Main5 Main6 btfss 05,2 ;Is third line ON and no input signal? GOTO Main5 GOTO Main1
END
For more details: Colin Mitchell talking :at: tpg.com.au
Aug 27, 2007
Hows this? by: Justin
I don't understand. Do you want it to count the number of times you press a button and display a different LED for each press? That would be easily done with something like
unsigned short x = 0
void main () {
if (porta & (1<<4)) { // check key press delay_ms (20); // wait for boucing while (!porta & (1<<4)) ; //wait for release ++x } if x == 1 ... //first press if x == 2 ... //second press if x == 3 ... //etc }
Hope this helps, Justin
JFM Note there is formating problem to be sorted out.