--2oS5YaxWCcQjTEyO Content-Type: text/plain; charset=us-ascii Content-Disposition: inline I've got a minor project using a 16lf88 running at 3V with some LEDs attached to PORTA and PORTB and a microswitch to cycle between display patterns. Dead simple thing, a client just needed a mockup of a bike light. The circuit is equally simple, LEDs connected to ground and the pins, all LEDs setup to consume 5ma (white or red w/ resistor) The power source is two fresh 3V lithium's in parallel. Finally the normally open microswitch is connected between ground and RB5. I have the weak pullups enabled. The problem is that ICSP doesn't work unless the microswitch is pressed *down*. This happens even when the PIC is completely out of the circuit, and the only thing connected is the ICSP pins and my microswitch via jumper cables. (and the capacitor, I just soldered it on directly) This has happened with two seperate PIC chips and seems very reproducable. The programmer works fine on different code, but once I program the firmware in, I simply have to have that switch pressed down for ICSP to work. My quite short firmware is attached. I got everything working for the client, but I'd love to figure out what the root cause of this was. Incidentally, I think this is the first post I've made to piclist about pic chips rather than tricked-out scooters or very large numbers... I've been subscribed for about 6 months I think... -- pete@petertodd.ca http://www.petertodd.ca --2oS5YaxWCcQjTEyO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="lights.asm" ; (c) 2006 Peter Todd ; Lights for Adam's bike thing ; CPU configuration processor 16f88 include __CONFIG _CPD_OFF & _CP_OFF & _BODEN_OFF & _MCLR_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_CLKOUT & _LVP_OFF ; Declare variables cblock H'20' ; backup vars for int routine safe_w safe_s PAUSEJ PAUSEK endc steptmr_constant_init equ D'48' ; ############### Start of ROM ############### org 0x00 nop clrf STATUS clrf PCLATH goto Start ; ############### Interrupt Service Routine ################### org 0x04 movwf safe_w ; save w swapf STATUS,w clrf STATUS movwf safe_s int_done: banksel INTCON bcf INTCON,TMR0IF ;clear interrupt flag before return bcf INTCON,RBIF swapf safe_s,w ;fetch status, reswap nibbles movwf STATUS ;restore status swapf safe_w,f ;swap nibbles in preparation swapf safe_w,w ;for the swap restoration of w retfie ;return ; ############## start of main program ####################3 Start: banksel OSCCON movlw b'01001010' movwf OSCCON ; init ports, everything but RB5 are outputs banksel TRISA movlw b'00000000' movwf TRISA banksel TRISB movlw b'00100000' movwf TRISB ; turn on weak pullups banksel OPTION_REG bcf OPTION_REG,NOT_RBPU ; disable ADC banksel ANSEL movlw b'00000000' movwf ANSEL ; setup interrupt on change for PORTB so we can sleep on keypresses banksel INTCON bsf INTCON,RBIE bcf INTCON,RBIF banksel PORTB clrf PORTB clrf PORTA main_loop: ; we sleep until the first keypress ; ### 1: front white on call wait_for_keypress_sleep movlw B'00000000' movwf PORTB movlw B'00000011' movwf PORTA ; ### 2: lower blue on call wait_for_keypress movlw B'00000001' movwf PORTB movlw B'00000011' movwf PORTA ; ### 3: middle blue on call wait_for_keypress movlw B'00000010' movwf PORTB movlw B'00000011' movwf PORTA ; ### 4: upper blue on call wait_for_keypress movlw B'00000100' movwf PORTB movlw B'00000011' movwf PORTA ; ### 5: upper blue on, red on call wait_for_keypress movlw B'00000100' movwf PORTB movlw B'00000111' movwf PORTA ; ### 6: all off call wait_for_keypress clrf PORTB clrf PORTA goto main_loop ; waits in until there is a keypress wait_for_keypress: ; this is a little backwards, since we are assuming we were just in another wait_for_keypress above ; so first check if the switch is back *up* btfss PORTB,5 goto $-1 ; switch is up, wait for debouncing, and check again movlw D'50' movwf PAUSEJ ; J := w jloop: movwf PAUSEK ; K := w kloop: decfsz PAUSEK,f ; K = K-1, skip next if zero goto kloop decfsz PAUSEJ,f ; J = J-1, skip next if zero goto jloop btfss PORTB,5 goto wait_for_keypress ; just a bounce, restart wait_for_keypress_down: btfsc PORTB,5 goto wait_for_keypress_down return wait_for_keypress_sleep: ; this is a little backwards, since we are assuming we were just in another wait_for_keypress above ; so first check if the switch is back *up* btfss PORTB,5 goto $-1 ; switch is up, wait for debouncing, and check again movlw D'50' movwf PAUSEJ ; J := w jloop2: movwf PAUSEK ; K := w kloop2: decfsz PAUSEK,f ; K = K-1, skip next if zero goto kloop2 decfsz PAUSEJ,f ; J = J-1, skip next if zero goto jloop2 btfss PORTB,5 goto wait_for_keypress_sleep ; just a bounce, restart sleep banksel INTCON bcf INTCON,RBIF banksel PORTB ; switch actually down? btfsc PORTB,5 goto wait_for_keypress_sleep return end --2oS5YaxWCcQjTEyO Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist --2oS5YaxWCcQjTEyO--