Author Topic: another question about MPLAB assembler  (Read 5249 times)

0 Members and 1 Guest are viewing this topic.

Offline RodHTopic starter

  • Newbie
  • Posts: 6
another question about MPLAB assembler
« on: February 13, 2013, 11:58:12 pm »
Can anyone tell me what the problem is with error [126]?


Warning[224] C:\PIC DOCUMENTS\MEDTIM.ASM 47 : Use of this instruction is not recommended.
Warning[224] C:\PIC DOCUMENTS\MEDTIM.ASM 51 : Use of this instruction is not recommended.
Warning[224] C:\PIC DOCUMENTS\MEDTIM.ASM 55 : Use of this instruction is not recommended.
Warning[224] C:\PIC DOCUMENTS\MEDTIM.ASM 59 : Use of this instruction is not recommended.
Error[126]   C:\PIC DOCUMENTS\MEDTIM.ASM 59 : Argument out of range (0008 not between 0005 and 0007)
Message[305] C:\PIC DOCUMENTS\MEDTIM.ASM 217 : Using default destination of 1 (file).
Message[305] C:\PIC DOCUMENTS\MEDTIM.ASM 228 : Using default destination of 1 (file).
Message[305] C:\PIC DOCUMENTS\MEDTIM.ASM 242 : Using default destination of 1 (file).
Message[305] C:\PIC DOCUMENTS\MEDTIM.ASM 324 : Using default destination of 1 (file).

   list    p=pic16f877
   radix   hex
;   #include   <p16f877>

      

;================================================================================================================================================================================
;
;       cpu equates (memory map)

tmro   equ   0x01
status   equ   0x03
porta   equ   0x05
portb   equ   0x06
portc   equ   0x07
portd   equ   0x08
porte   equ   0x09
intcon   equ   0x0c
t1con   equ   0x10
second   equ   0x20
minute   equ   0x21
hours   equ   0x22
minutes   equ   0x23




;============================================================================================================================================================
   org   0x00
   goto   start       ;skip interrupt vector
start
   org   0x004
   bcf   intcon,7    ;disable global interrupt
   movlw   b'000001'   ;setup port a
   tris   porta      ;setup port a 1=in,0=out
   movlw   b'000000'   ;clear porta
   movwf   porta
   movlw   b'00000111'   ;setup portb
   tris   portb      ;setup portb 1=in, 0=out
   movlw   b'00000000'   ;clear b
   movwf   portb
   movlw   b'00001100'   ;portc
   tris   portc      ;setup portc 1=in,0=out
   movlw    b'00000000'   ;clear c
   movwf    portc
   movlw   b'00000000'   ;setup d
   tris   portd      
   movlw   b'00000000'   ;clear d
   movwf   portd
pgm
   clrw         ;clear w
   clrf   second      ;clear second count
   clrf   minute      ;clear minute count
   clrf   minutes      ;clear clock mintes
   clrf   hours      ;clear clock hours
   btfss   porta,5      ;test port a5, skip next if set(low active)
   goto   two
   btfss   portb,5      ;test portb5, skip next if set
   goto   four
   btfss   portb,6      ;test portb6
   goto   six
   btfss   portb,7      ;test portb7
   goto   eight
   btfss   portc,4      ;test portc4,skip next if set
   goto   ten
   btfss   portc,5      ;test portc5
   goto    twelve


 

Offline baljemmett

  • Supporter
  • ****
  • Posts: 665
  • Country: gb
Re: another question about MPLAB assembler
« Reply #1 on: February 14, 2013, 12:45:06 am »
Can anyone tell me what the problem is with error [126]?

Warning[224] C:\PIC DOCUMENTS\MEDTIM.ASM 47 : Use of this instruction is not recommended.
Warning[224] C:\PIC DOCUMENTS\MEDTIM.ASM 51 : Use of this instruction is not recommended.
Warning[224] C:\PIC DOCUMENTS\MEDTIM.ASM 55 : Use of this instruction is not recommended.
Warning[224] C:\PIC DOCUMENTS\MEDTIM.ASM 59 : Use of this instruction is not recommended.
Error[126]   C:\PIC DOCUMENTS\MEDTIM.ASM 59 : Argument out of range (0008 not between 0005 and 0007)

That has the slight smell of a possible bug in the assembler, to be honest -- the 16F877 doesn't have a real 'TRIS' instruction like some of the really small chips, but rather has TRISx registers that correspond to each PORTx.  Presumably MPASM implements a TRIS pseudo-instruction to allow this to work for PORTA, PORTB and PORTC (whose register addresses are the 0005 - 0007 referred to in the error message) but for some reason it doesn't want to do the same thing for PORTD...  I can see no obvious cause for that from the quoted code!  However, since it warns you (four times!) that use of TRIS is not recommended, there's a reasonable chance you'll just be bashing your head against the wall trying to make it work.

Instead, I would try manipulating the TRISD register directly; to do this you'll first need to add a 'trisd equ 0x88' to your list of registers at the top, and it wouldn't hurt to add the other TRISx registers too -- just add 0x80 to the PORTx addresses.  (By the way, is there any particular reason you're declaring your own equates for a few registers, instead of including the p16f877 include file that should bring them all in?)

Once you have the register addresses defined, you can substitute TRISx register accesses for the 'tris' lines you have the moment.  So the code around that error location would become:

Code: [Select]
banksel trisd
movlw b'00000000' ;setup d
movwf trisd
banksel portd
movlw b'00000000' ;clear d
movwf portd

... in other words, 'tris PORTx' becomes 'movwf TRISx', but you have to take care of bank switching yourself -- which is what the added 'banksel' pseudo-instructions are doing.  The reason for that is simply that instructions like movwf can only address registers by their lower 7 bits, which means they have to be grouped into four banks of 128; you need to make sure you have the right bank selected before you can access any given register.  In fact, you'll probably find MPASM emits an annoying warning whenever you access one of the registers that's not in bank 0, in an effort to remind you about this!
 

Offline fcb

  • Super Contributor
  • ***
  • Posts: 2174
  • Country: gb
  • Test instrument designer/G1YWC
    • Electron Plus
Re: another question about MPLAB assembler
« Reply #2 on: February 14, 2013, 12:55:56 am »
don't use "tris" instruction, it's very old

instead write directly to the register TRISD (if your using port D)
https://electron.plus Power Analysers, VI Signature Testers, Voltage References, Picoammeters, Curve Tracers.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

-->