It sounds as though it's possibly compiling for a different model uController. My guess as to why it's not working is that it's placing the code somewhere it can't actually get to. Just a guess. I don't have the datasheet for your micro to look at to verify it. It's good that you've solved the problem, but bad that you wasted all that time when you could have written the program in ASM in no more than 10 minutes... ...Just an observation. -Shawn Adam Woodworth wrote: >Thanks for the idea! Disassembling the .hex file showed me what was >wrong, although I don't know why it's wrong... It turns out HiTech C was >splitting the code into a couple sections and putting them in different >places in the memory space for some reason. > >Here's the disassembled .hex file: > >000000: 0183 clrf 0x3 >000001: 3000 movlw 0 >000002: 008a movwf 0xa >000003: 2804 goto 0x4 >000004: 0183 clrf 0x3 >000005: 2bfa goto 0x3fa >0003fa: 1683 bsf 0x3, 0x5 >0003fb: 0186 clrf 0x6 >0003fc: 30ff movlw 0xff >0003fd: 1283 bcf 0x3, 0x5 >0003fe: 0086 movwf 0x6 >0003ff: 2bff goto 0x3ff >002007: 3ff5 addlw 0xf5 > >As you can see, there's 2 extraneous goto statements, one at 0003 and one >at 0005. And the one at 0005 jumps to a completely different area in >memory. So for some reason after 0005 the compiler moved the code up to >03fa. Now if I take this assembly code and remove the gotos at 0003 and >0005 and compile it into .hex with gpasm, it works fine. I can load it >onto my PIC and the LED lights up. > >What I don't understand is 1) why HiTech is putting in these extra gotos, >and 2) why the extra gotos and splitting of code is causing the PIC not to >work as expected. > >Anyone have any ideas? > >Adam > >On Sat, 2 Oct 2004, Ivan Kocher wrote: > > > >>Have you tried your .hex in a simulator? >>picsim works for me quite good... or just disasseble the .hex and see >>what might be wrong ... >> >> >>Ivan Kocher >>--------------- >> >>Adam Woodworth wrote: >> >> >>>Hi Brent, >>> >>>Thanks for your response! Actually, I've been programming in C for years, >>>and I tried putting the code in a loop earlier and still nothing happens >>>to the LED. So I'm still clueless as to what the problem is. >>> >>>I even tried setting PORTB = 0 instead of 255 in case 0 meant high and 1 >>>meant low (which seems to be the case with gpasm). >>> >>>But would this program really require an endless loop? I'm still not too >>>familiar with PICs, but I would assume that the compiler would generate >>>code that would have an instruction to terminate the program, so that the >>>PIC wouldn't go off into never never land. I was expecting the code to >>>run, change the state of PORTB, and exit cleanly and the PIC would be >>>sitting "idle". Am I wrong? >>> >>>Thanks! >>>Adam >>> >>> >>>On Sun, 3 Oct 2004, Brent Brown wrote: >>> >>> >>> >>> >>>>Adam Woodworth wrote: >>>> >>>> >>>> >>>>>For example, the following simple program doesn't do anything when >>>>>loaded onto my PIC and put into a circuit with an LED attached to pin >>>>>1 of PORTB. >>>>> >>>>>#include >>>>>__CONFIG(WDTEN & XT & UNPROTECT & PWRTEN); >>>>>void main(void) >>>>>{ >>>>>TRISB = 0; >>>>>PORTB = 255; >>>>>} >>>>> >>>>> >>>>I think this is a fairly common hurdle for people to overcome when first >>>>learning C. Your two lines of code will get executed and then the processor >>>>will wander off into never never land because you haven't told it what to do >>>>next. You could add the following:- >>>> >>>>while(1) >>>> ; >>>> >>>>The above is a never ending loop. >>>> >>>>Or you could re-structure your program so all of function main gets repeated: >>>> >>>>void main(void){ >>>> while(1){ >>>> TRISB = 0; >>>> PORTB = 255; >>>> } >>>> } >>>> >>>>Hope this helps somewhat. >>>> >>>>-- >>>>Brent Brown, Electronic Design Solutions >>>>16 English Street, Hamilton, New Zealand >>>>Ph/fax: +64 7 849 0069 >>>>Mobile/txt: 025 334 069 >>>>eMail: brent.brown@clear.net.nz >>>> >>>> >>>>_______________________________________________ >>>>http://www.piclist.com >>>>View/change your membership options at >>>>http://mailman.mit.edu/mailman/listinfo/piclist >>>> >>>> >>>> >>>_______________________________________________________________________ >>> Adam Woodworth >>> SMTP : adam@mirkwood.com >>> HTTP : http://www.mirkwood.com >>> HAM : N1ZNN >>>_______________________________________________ >>>http://www.piclist.com >>>View/change your membership options at >>>http://mailman.mit.edu/mailman/listinfo/piclist >>> >>> >>> >>_______________________________________________ >>http://www.piclist.com >>View/change your membership options at >>http://mailman.mit.edu/mailman/listinfo/piclist >> >> >> > >_______________________________________________________________________ > Adam Woodworth > SMTP : adam@mirkwood.com > HTTP : http://www.mirkwood.com > HAM : N1ZNN >_______________________________________________ >http://www.piclist.com >View/change your membership options at >http://mailman.mit.edu/mailman/listinfo/piclist > > _______________________________________________ http://www.piclist.com View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist