PDA

View Full Version : Trigger Counting



jhorsburgh
- 10th December 2007, 02:26
Hi All,
Attached is a simple code for flashing an LED when a Button is pressed.
I would like to be able to count how many times the button has been triggered and when the count reaches a predefined value, it will stop all operation until the chip is reset.

Any help will be greatly appreciated.

Regards,
Jeremy

mister_e
- 10th December 2007, 02:46
several way to do it, use T0CKI pin. Each time you will press on the button, TMR0 register will increment (if properly configured) .

Then you just need to read TMR0 register, XOR it results with your Max value, the read STATUS,Z bit. If zero, you have reached the Max value.

Could still be done using a variable, same concept, every time a button have been pressed, increment the variable etc etc. test it and do your thing.

In your code, you will increment your variable and test it in SEMI routine.

could be something like that...


SEMI
INCF COUNTERVAR,F
MOVF COUNTERVAR, W
XORLW .10 ; XOR With 10 (max value)
BTFSC STATUS,Z ; reach Max Value?
GOTO $ ; YES, Spin in round forever
MOVLW B'00000001' ; NO, continue
MOVWF PORTB
CALL DELAY_ROUTINE
CALL DELAY_ROUTINE
MOVLW B'00000000' ;
MOVWF PORTB
CALL DELAY_ROUTINE
CALL DELAY_ROUTINE
S1 BTFSC PORTA,SW1
GOTO S1
GOTO MENU

Now... i have to say that you're on a PICBasic forum, even if there's some tolerance for few assembler line here and there, it's not the main purpose/knowledge of this forum. Here, we use Melabs PicBasic or Melabs PICBasic PRO.

Microchip have it's forum, and there's a lot of clever assembler programmer over there.
http://forum.microchip.com/

:( sorry :( ... don't give up... maybe you'll see me over there as well.