Searching \ for '[PIC] 12F629, sequencing LEDs' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page:
Search entire site for: '12F629, sequencing LEDs'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] 12F629, sequencing LEDs'
2007\08\13@221122 by Jinx

face picon face
(subject added)

Brian, I haven't tested the following code (and to be honest didn't
test all the logic, though I know what I want it to do), but it may
work as written. If not, apologies, it's a start

There's no software debouncing of the input switch. I'd suggest an
RC filter. For example, a 10k pull-up from GPIO,5 to Vdd via the
switch contacts, and a 100n capacitor to 0V. This should filter out
a lot of contact noise. Don't forget a 10k pull-up on /mclr

  list P = 12F629
  include ""

  errorlevel -305, -302, -306   ;MPLAB message suppression


;Instruction cycle time = 1us
;Timer1 rollover = 65536 * 8 = 524288us = approx 0.5s

        cblock 0x20

        temp1                   ;state counter
        temp2                   ;timer counter


#define  rled     gpio,0         ;red LED, output
#define  bled     gpio,4         ;blue LED, output
#define  push     gpio,5         ;pushbutton, input

 org 0x00

        goto    start

start    banksel osccal

        call    0x3ff
        movwf   osccal

        banksel trisio
        movlw   b'00101000'
;                    1            pushbutton input
;                     0           blue LED
;                      1          /mclr
;                       0
;                        0
;                         0       red LED
        movwf   trisio

        banksel option_reg
        movlw   b'10000000'
;                  1              pullups off
        movwf   option_reg

        banksel temp1           ;bank0

        clrf    temp1
        clrf    temp2

rst_tmr1 clrf    tmr1l
        clrf    tmr1h

        movlw   b'00110000'
;                    11           pre-scaler 1:8
;                         0       TMR1 off
        movwf   t1con
        bcf     pir1,tmr1if     ;clear rollover flag

main     btfsc   push            ;wait for button push (active low)
        goto    main

        bsf     t1con,tmr1on    ;start timer1

rollover btfsc   pir1,tmr1if     ;look for either release or rollover
        goto    bump_rof        ;if TMR1 rollover occurs, increment counter

release  btfss   push            ;wait for button release
        goto    rollover

        incf    temp            ;increment state counter
        movf    temp,w
        xorlw   0x01            ;test for 1
        bz      red_on
        xorlw   0x01 ^ 0x02     ;test for 2
        bz      blue_on

leds_off bcf     rled            ;must be 3, both off
        bcf     bled
        goto    rst_tmr1

red_on   bsf     rled            ;red on, blue off
        bcf     bled
        goto    rst_tmr1

blue_on  bcf     rled            ;red off, blue on
        bsf     bled
        goto    rst_tmr1

bump_rof incf    temp2           ;increment rollover count
        movlw   0x02
        xorwf   temp2,w         ;= 2 = 1s
        goto    release         ;not 1s

        bcf     t1con,tmr1on    ;timer off
        sleep                   ;power down
        goto    start           ;reset


2007\08\13@221535 by Jinx

face picon face
Brian, one thing you must add -

        bcf     pir1,tmr1if     ;clear rollover flag

at bump_rof

More... (looser matching)
- Last day of these posts
- In 2007 , 2008 only
- Today
- New search...