Trigger Counting


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2007
    Posts
    34

    Default Trigger Counting

    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
    Attached Files Attached Files

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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...
    Code:
    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.
    Last edited by mister_e; - 10th December 2007 at 03:00.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. COUNT is not counting again
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 33
    Last Post: - 19th June 2009, 04:52
  2. Replies: 2
    Last Post: - 8th February 2009, 05:10
  3. Need Help... 16f630 Schmitt Trigger
    By tohu thomson in forum mel PIC BASIC
    Replies: 1
    Last Post: - 13th August 2007, 15:13
  4. Remain counting while sending out a pulse
    By ultiblade in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 10th January 2007, 15:51
  5. continious counting process (capture)
    By asynch in forum General
    Replies: 1
    Last Post: - 17th February 2006, 07:42

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts