I missed the pcl bit,,, whoops -----Original Message----- From: Matt Marsh [mailto:matt@MATTMARSH.NET] Sent: 30 March 2004 6:15:pm To: PICLIST@MITVMA.MIT.EDU Subject: Re: [PIC:] Problem with simple push button timer interrupt progra m Hi Ken, On Tuesday 30 March 2004 16:45, Ken Walker wrote: > Firstly, as William says you need > > org 0x00 > goto start > > org 0x04 > ISR..... As Bill figured out, this does actually get to the right address, if by a convoluted mechanism. I'll change it, but at least it should be working ok > 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) The block of code you're talking about is: movlw d'1' subwf SEQ,w addwf PCL,f goto Sequence1 goto Sequence2 Where the idea was that it would take the value of SEQ (1 or 2), subtracts one from it to make it 0 or 1 and adds that to the program counter so that if SEQ=1 the next instruction executed would be 'goto Sequence1', and if SEQ=2 the next instruction executed would be 'goto Sequence2'. Again, this is a technique I'd read in my book, is this not reasonable/sensible? > 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. The pointless amount of looping etc is mainly due to the fact that this is a cut down version of the program in which the bug really exists in, cut down to a minimal test program exhibiting the behaviour for debugging purposes. But yes, I'm a newbie so I have much to do to improve my ability yet :) > 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 > ... Agreed and point taken... > 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. I haven't used any of the simulators yet. I'm actually running on Linux so I have no access to the mplab simulator, but there is a 'gpsim' on Linux which I believe is the same sort of thing. I haven't learnt how to use that yet though so thanks for the advice and maybe I should invest some time getting that up and running. Thanks for the comments, I appreciate all the feedback I'm getting from this and I'm sure it will help me get up to speed all the quicker! 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