"Jinx has answered this comprehensively..." No doubt about it! ... You too, thanks! On 8/31/07, Howard Winter wrote: > > Carol, > > Jinx has answered this comprehensively... > > On Thu, 30 Aug 2007 22:41:31 -0300, Carolina Dieguez wrote: > > > Howard, > > You've also asked me some days before about writing > "org 80h". I > > guess I did not even consider that seriously, I've used "org 00h" times > > before and now I wanted to know what happened. > > > > I think this has to do with the fact I'm still not so sure > about > > PIC memory and where or in which order set the ISR, inicialisation part, > > main program and then the subrrutines. > > > > I've followed your scheme: > > > > ORG 0 > > CALL INIT > > GOTO MAIN > > ORG 4 > > - interrupt processing... > > RETFIE > > INIT > > - initialisation... > > RETURN > > MAIN > > - main loop... > > GOTO MAIN > > DELAY > > - etc... > > > > However, in other examples, I try to do it this way > -subrrutines > > at the last part of the whole code- and compiler do not make its job > saying > > I'm "Overwriting previous address contents (0000)" > > This is a wrap-round of the program counter - either the whole program is > too big to fit the chip (upgrade to a bigger chip) or you used ORG and left > too big a gap. Make the gap smaller (or remove it completely) in this > case. > > My example is just that - an example, not a rule. I just used your > original layout and changed it a little, it's not necessarily what I would > always use, > although it is close! You can organise your code in memory as you like, > with the only fixed items being the two vectors (0 and 4) as Jinx mentioned. > As long as you have something appropriate at these two addresses (or, if > you never activate GIE, only the first one), the rest is up to you. > > Personally I like to have the ISR starting at 4, because I don't like > having a GOTO that's not necessary, then the initialisation, then the Main > code, then > the subroutines. This is probably because the first language I used > commercially (COBOL) tends to encourage this. Other people have the Main at > the > end and subroutines in front, others have the subroutines interleaved > through the Main loop so they're close to the code that calls them. This > can be > easier to navigate when you're reading the program, but can end up with a > lot of GOTOs to step over the subroutines, and it can obscure the main > logic flow. > > Then there's the question of where to put the various pieces of code. At > one end of the scale you can have a Main Loop with no subroutines at all, > all the code is "in line". At the other extreme the Main Loop does > nothing but call subroutines (or in the case we're discussing, nothing at > all except > wait for an Interrupt). I try to have the program structure mimic the > problem. If the problem is a simple sequence of events, I tend to have the > sequence progress through the Main Loop. If a lot of things happen that > aren't in a sequence (responding to external events, including timers) then > I > tend to have the Main Loop doing nothing but calling subroutines as they > are needed. Of course, the Main "loop" doesn't have to be looping all the > time, it can go to sleep if there's nothing happening and rely on > interrupts to wake it up. > > My advice is to go for the simplest structure that works, and that seems > logical to you. If you are the only one who has to understand it, that's > the > most important thing - it's only when you start posting it here that > others will see it, so at that point it needs to be "obvious" so that we can > understand it too! > > But to sum up: Find a structure that you like! :-) > > Cheers, > > > Howard Winter > St.Albans, England > > > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist