|
View:
New views
7 Messages
—
Rating Filter:
Alert me
|
|
|
Not being able to use variables on pic18fxx50Hi list!
I'm new to microcontrolers, and I'm tying to program a pic18f4550, under gnu/linux and/or freebsd. The main problem I'm finding is with variables. I can't make them work. gpasm would say "Warning [231] No memory has been reserved by this instruction." when it sees: myvar res 1 I tried with: myvar res 2 with no succesful results, I've tried something like this: ;; setup processor and output format list p=p18f4550,f=inhx32 include <p18f4550.inc> ;; disable watchdog timer config wdt = off ;; chip will use internal oscillator (4 mhz) config fosc = intoscio_ec org 0 goto main ;; let `count1' and `count2' live after the previous ;; `goto' instruction on code-memory, where shouldn't ;; clash with program's instructions count1 equ 0x6 count2 equ 0x8 ;; offset our program by 32 bytes, so we have space for the previous and other variables I might want to use org 0x20 main: ..... After I started "decoding" hex-files' dumps, doesn't work either, so I'm a bit lost, have tried even more different approaches but I can't get the pic to "respect" and work with any variables other than constants. This is an example program I wanted to start with: ;; setup processor and output format list p=pic18f4550,f=inhx32 include <p18f4550.inc> ;; disable watchdog timer config wdt = off ;; chip will use internal oscillator (4 mhz) config fosc = intoscio_ec org 0 counter res 2 main: ;; portd will be all outputs clrf PORTD clrf TRISD restart: ;; give the memory address location `0x0' the value `5' movlw 5 movwf 0x0 loop: ;; decrement this value till it's 0, what will cause the decfsz 0x0, f goto loop btg PORTD, RD1 goto restart end __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ¡gratis! Regístrate ya - http://correo.yahoo.es --------------------------------------------------------------------- To unsubscribe, e-mail: gnupic-unsubscribe@... For additional commands, e-mail: gnupic-help@... |
|
|
Re: Not being able to use variables on pic18fxx50It looks like you're reserving memory in ROM and then accessing addresses in
RAM. The RES directive allocates memory in the section you're defining, so look at UDATA and similar directives in the manual. David On Mon, Aug 18, 2008 at 12:20 PM, Lope Vega <vega_lope@...> wrote: > ...but I can't get the pic to "respect" and work with any variables other > than constants. > > This is an example program I wanted to start with: > > ... org 0 > > counter res 2 > > main: > ;; portd will be all outputs > clrf PORTD > clrf TRISD > > restart: > ;; give the memory address location `0x0' the value `5' > movlw 5 > movwf 0x0 > > loop: > ;; decrement this value till it's 0, what will cause the > > decfsz 0x0, f > goto loop > > btg PORTD, RD1 > goto restart > end > |
|
|
Re: Not being able to use variables on pic18fxx50Hello again,
Thanks a lot, but it didn't do the trick either. By looking at this a bit more indeep, while in relocatable mode I've noticed I can't use `udata_shr' (it throws an error about a not existing .udata_shr on the linker script, even when I gave that section a name to avoid it making use of the default value). I still haven't been able to use variables reliably even with the most simple of the programs. I'm pasting today, the program, and dumps from the chip's code and eeprom memories, and if somebody could tell me something about what's going on here, that would be great. Here is the code: ;; setup processor and output format list p=p18f4550,f=inhx32 include <p18f4550.inc> config plldiv = 1 config fosc = intoscio_ec config fcmen = off config ieso = off config pwrt = off config bor = off config borv = 0 config vregen = off config wdt = off config mclre = on config lpt1osc = off config pbaden = off config ccp2mx = on config stvren = off config lvp = on config icprt = off config xinst = on config debug = off config cp0 = off config cp1 = off config cp2 = off config cp3 = off config cpb = off config cpd = off config wrt0 = off config wrt1 = off config wrt2 = off config wrt3 = off config wrtb = off config wrtc = off config wrtd = off config ebtr0 = off config ebtr1 = off config ebtr2 = off config ebtr3 = off config ebtrb = off udata counter res 1 code 0 pagesel main goto main code main ;; PORTB is all inputs, it just got an active-high switch ;; on RB4 clrf PORTB movlw 0xff movwf TRISB ;; PORTD is all outputs clrf TRISD banksel counter restart movlw 0x05 movwf counter loop ;; has the switch been pressed? btfsc PORTB, RB4 ;; no, continue polling goto loop ;; it's been, turn on the led @ RD0, just to have some feedback bsf PORTD, RD0 debounce ;; has the switch been released? btfss PORTB, RB4 ;; no, poll some more goto debounce ;; yes, turn the led @ RD0 off bcf PORTD, RD0 decrement ;; decrement `counter', store result in that variable itself, and ;; and skip the instruction after this one if `counter == 0' decfsz counter, f goto loop ;; toggle led @ RD1 btg PORTD, RD1 ;; goto start, where the counter gets set to 5 again, in theory goto restart end This is a dump of the code's memory once burned: ADDRESS DATA -------- ----------------------------------------------- 0x000000 81 6A FF 0E 93 6E 95 6A 00 01 05 0E 60 6F 81 B8 0x000010 07 EF 00 F0 83 80 81 A8 0B EF 00 F0 83 90 60 2F 0x000020 07 EF 00 F0 83 72 05 EF 00 F0 And this a dump of the epprom as well: ADDRESS DATA -------- ----------------------------------------------- 0x000000 9F FF If somebody could compile the above program and provide me with similar device's dumps that would be same as helpful as any explanation probably. The problem could very be due to the only program I could use for burning the chips on my freebsd: Broccoli18. Many thanks. --- El mar, 19/8/08, David Barnett <daviebdawg@...> escribió: > De: David Barnett <daviebdawg@...> > Asunto: Re: [gnupic] Not being able to use variables on pic18fxx50 > Para: gnupic@... > Fecha: martes, 19 agosto, 2008 12:37 > It looks like you're reserving memory in ROM and then > accessing addresses in > RAM. The RES directive allocates memory in the section > you're defining, so > look at UDATA and similar directives in the manual. > > David > > On Mon, Aug 18, 2008 at 12:20 PM, Lope Vega > <vega_lope@...> wrote: > > > ...but I can't get the pic to "respect" > and work with any variables other > > than constants. > > > > This is an example program I wanted to start with: > > > > ... > > org 0 > > > > counter res 2 > > > > main: > > ;; portd will be all outputs > > clrf PORTD > > clrf TRISD > > > > restart: > > ;; give the memory address location `0x0' > the value `5' > > movlw 5 > > movwf 0x0 > > > > loop: > > ;; decrement this value till it's 0, what > will cause the > > > > decfsz 0x0, f > > goto loop > > > > btg PORTD, RD1 > > goto restart > > end > > __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ¡gratis! Regístrate ya - http://correo.yahoo.es --------------------------------------------------------------------- To unsubscribe, e-mail: gnupic-unsubscribe@... For additional commands, e-mail: gnupic-help@... |
|
|
Re: Not being able to use variables on pic18fxx50On Thu, Aug 21, 2008 at 03:13:19PM +0000, Lope Vega wrote:
> udata > counter res 1 Good so far. > code 0 > pagesel main > goto main > > code These lines should read: code org 0 pagesel main goto main A small note on the code: > debounce > ;; has the switch been released? This debounce is not really debouncing but the program will fall through the code on the first bouncy switch press, making the LED flash for only a few instructions which will not be noticeable to the eye. :) You could capture the edge with an oscilloscope. //Peter --------------------------------------------------------------------- To unsubscribe, e-mail: gnupic-unsubscribe@... For additional commands, e-mail: gnupic-help@... |
|
|
Re: Not being able to use variables on pic18fxx50On Fri, 22 Aug 2008, Peter Stuge <peter@...> wrote :
> >> code 0 >> pagesel main >> goto main >> >> code > >These lines should read: > > code > org 0 > pagesel main > goto main > argument which acts as an "org" hint for the linker. In fact Peter's suggestion is wrong, because the "org 0" takes the assembler out of relocatable mode and back to absolute, so it makes no sense to put one immediately after a "code" directive. However, use of the "pagesel" macro is redundant on 18F series devices, since the "goto" instruction on them has a 24-bit range. What Lope has not told us, which does matter given the errors he reports, is what his linker file contains. Also, the dump from the chip is of far less use than the hex/lst/map files built by the linker. -- Rob Pearce http://www.bdt-home.demon.co.uk The contents of this | Windows NT crashed. message are purely | I am the Blue Screen of Death. my opinion. Don't | No one hears your screams. believe a word. | --------------------------------------------------------------------- To unsubscribe, e-mail: gnupic-unsubscribe@... For additional commands, e-mail: gnupic-help@... |
|
|
Re: Not being able to use variables on pic18fxx50--- El jue, 21/8/08, Peter Stuge <peter@...> escribió: > De: Peter Stuge <peter@...> > Asunto: Re: [gnupic] Not being able to use variables on pic18fxx50 > Para: gnupic@... > Fecha: jueves, 21 agosto, 2008 11:40 > On Thu, Aug 21, 2008 at 03:13:19PM +0000, Lope Vega wrote: > > udata > > counter res 1 > > Good so far. > > > > code 0 > > pagesel main > > goto main > > > > code > > These lines should read: > > code > org 0 > pagesel main > goto main > > > A small note on the code: > > > debounce > > ;; has the switch been released? > > This debounce is not really debouncing but the program will > fall > through the code on the first bouncy switch press, making > the LED > flash for only a few instructions which will not be > noticeable to > the eye. :) You could capture the edge with an > oscilloscope. > Hello, and thanks a lot. Yes, I know the "debouncing" part is not reliable, but I was more interested in having some code working before I could get on that, which already happened, see my next message, and many thanks for replying. > > //Peter > > --------------------------------------------------------------------- > To unsubscribe, e-mail: gnupic-unsubscribe@... > For additional commands, e-mail: > gnupic-help@... __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ¡gratis! Regístrate ya - http://correo.yahoo.es --------------------------------------------------------------------- To unsubscribe, e-mail: gnupic-unsubscribe@... For additional commands, e-mail: gnupic-help@... |
|
|
Re: Not being able to use variables on pic18fxx50--- El vie, 22/8/08, Robert Pearce <rob@...> escribió:
> De: Robert Pearce <rob@...> > Asunto: Re: [gnupic] Not being able to use variables on pic18fxx50 > Para: gnupic@... > Fecha: viernes, 22 agosto, 2008 7:55 > On Fri, 22 Aug 2008, Peter Stuge <peter@...> > wrote : > > > >> code 0 > >> pagesel main > >> goto main > >> > >> code > > > >These lines should read: > > > > code > > org 0 > > pagesel main > > goto main > > > Actually the former is acceptable - the 'code' > directive accepts an > argument which acts as an "org" hint for the > linker. In fact Peter's > suggestion is wrong, because the "org 0" takes > the assembler out of > relocatable mode and back to absolute, so it makes no sense > to put one > immediately after a "code" directive. > > However, use of the "pagesel" macro is redundant > on 18F series devices, > since the "goto" instruction on them has a 24-bit > range. Ops, I didn't know it where redundant on 18f's, still I'm new to this whole thing, thanks. > > What Lope has not told us, which does matter given the > errors he > reports, is what his linker file contains. Also, the dump > from the chip > is of far less use than the hex/lst/map files built by the > linker. I didn't think of that either, sorry, your completely right though. The linker script I've been using is the default one. Now, I solved it yesterdeay at least!. At some point, I took the PORTB part out, and got back to a "count from 5 to 0 and turn the led on/off" program-model, and started checking with the multimeter pin by pin. Then I noticed that when I had the + on RB3, and the - in ground, the pic started behaving completely normal, such like if a reset would have taken place. I then recompiled the program initializing properly the ports I wasn't using and all the problems solved!. Now I can use variables as reliably as I was meant to. While I can compile and make relocatable code work, still I haven't looked at why .udata_shr doesn't work (probably because the original defaul script needs some addendums), and in absolute mode, still I wouldn't know how to setup a variable of 1 byte, since `res' throws that message, but by now I'll be using relocatable code anyways. So thanks so much for your help and your attention guys, I might be able to start exploring the pic and the loads of things it comes with (timers, adc, etc). Regards. > -- > Rob Pearce > http://www.bdt-home.demon.co.uk > > The contents of this | Windows NT crashed. > message are purely | I am the Blue Screen of Death. > my opinion. Don't | No one hears your screams. > believe a word. | > > --------------------------------------------------------------------- > To unsubscribe, e-mail: gnupic-unsubscribe@... > For additional commands, e-mail: > gnupic-help@... __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ¡gratis! Regístrate ya - http://correo.yahoo.es --------------------------------------------------------------------- To unsubscribe, e-mail: gnupic-unsubscribe@... For additional commands, e-mail: gnupic-help@... |
| Free embeddable forum powered by Nabble | Forum Help |