Mmmmm. Firstly, as William says you need org 0x00 goto start org 0x04 ISR..... In ISR you say goto Sequence1 which flows into goto RefreshLeds And the goto Sequence1 means that goto Sequence2 never ever gets done, so why have it there at all And if it never gets done, your led never gets turned off :o) I'm gonna have to sit down now, my heads getting dizzy with all the goto this and goto that and,,, well its a very complicated go round the house code which could be done in a fraction of the space your using. as an example, why clear the SEQ reg then load the w reg with 2 then place it in the destination register, why not just start with 0x01 in the first place and then either increment or decrement, depending where you are, i.e. start off with clrf SEQ incf SEQ,f so now its set to 1 if you want it to be 2 then just incf SEQ,f and if you want to go back to 1 just do decf SEQ,f I was always told keep it simple, get it to flow and if your jumping all over the place start again cos its bad programming and harder to debug. ps, if you'd used the mplab simulator you would have spotted this within minutes. Ken -----Original Message----- From: Matt Marsh [mailto:matt@MATTMARSH.NET] Sent: 30 March 2004 3:14:pm To: PICLIST@MITVMA.MIT.EDU Subject: [PIC:] Problem with simple push button timer interrupt program Hi everyone, I'm in need of some help with a program I'm trying to put together. I'm still a newbie here so this is just something I'm putting together as a learning exercise and hopefully I'm just missing something obvious. Please note that the following is a cut down version of something much larger that I'm putting together. I've cut it down to the minimal version that I can that exhibits the behaviour I'm seeing. I have a circuit with one LED (connected to PORTB,2) and a push button switch (push-to-make) on PORTB,0. I have an interrupt service routine which wakes up when the timer expires. The ISR checks a register which I've named SEQ and if it is set to 1 it turns the LED on, if it is set to 2 it turns the LED off. Meanwhile, in the main program it loops around waiting for the pin that the push button is connected to going low. At that point it changes SEQ from 1 to 2 and then goes into and idle loop. So, the program should start and light the LED by default. When I press the button for the first time the LED should go out and stay out until the system is reset. However, the LED just comes on and stays on. Here is the code: ---------- list P=16F84A include "p16f84a.inc" LEDR1 equ 10h SEQ equ 17h org 0 goto Start Init clrf PORTA clrf PORTB goto InitCont goto ISR ; MUST BE INSTRUCTION 0x04 InitCont bsf STATUS,5 ; Select bank 1 movlw b'0000' movwf TRISA movlw b'00000001' ; Push button is connected to PORTB,0 movwf TRISB ; LED is connected to PORTB,2 movlw b'00000111' ; 1:256 pre-scaler on TMR0 movwf OPTION_REG bcf STATUS,5 ; Select bank 0 movlw b'10100000' ; Enable timer interrupts movwf INTCON clrf LEDR1 movlw d'1' movwf SEQ retlw 0 ISR clrwdt bcf INTCON,3 ; Reset timer interrupt movlw d'1' ; Subtract 1 from sequence number to subwf SEQ,w ; make it zero based addwf PCL,f goto Sequence1 goto Sequence2 Sequence1 movlw b'01111110' ; Set LED pins high movwf LEDR1 goto RefreshLEDs Sequence2 movlw b'00000000' ; Set LED pins low movwf LEDR1 goto RefreshLEDs RefreshLEDs movfw LEDR1 movwf PORTB retfie Start call Init Main clrwdt btfsc PORTB,0 goto Main movlw d'2' movwf SEQ Done clrwdt goto Done END ----------- I'm pretty happy that the circuit is ok as I have a simpler program (not using interrupts, timers etc) which just turns the LED on whilst the push button is held down and that works fine in the same circuit. I can post that program or more details of the circuit if it helps. Thanks, and sorry for the longish post, Matt -- Matt N. Marsh Email: matt@mattmarsh.net Yahoo: marshmn Web: http://www.mattmarsh.net/ Jabber: mattmarsh@jabber.org MSN: matt@mattmarsh.net ICQ: 250467363 AIM: MattMarshUK -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body