another question about MPLAB assembler - Page 1
Forum section: electronics / projects

author: RodH
author_rank: Newbie
timestamp: February 13, 2013, 11:58:12 pm
content: Can anyone tell me what the problem is with error ?Warning C:\PIC DOCUMENTS\MEDTIM.ASM 47 : Use of this instruction is not recommended.Warning C:\PIC DOCUMENTS\MEDTIM.ASM 51 : Use of this instruction is not recommended.Warning C:\PIC DOCUMENTS\MEDTIM.ASM 55 : Use of this instruction is not recommended.Warning C:\PIC DOCUMENTS\MEDTIM.ASM 59 : Use of this instruction is not recommended.Error C:\PIC DOCUMENTS\MEDTIM.ASM 59 : Argument out of range (0008 not between 0005 and 0007)Message C:\PIC DOCUMENTS\MEDTIM.ASM 217 : Using default destination of 1 (file).Message C:\PIC DOCUMENTS\MEDTIM.ASM 228 : Using default destination of 1 (file).Message C:\PIC DOCUMENTS\MEDTIM.ASM 242 : Using default destination of 1 (file).Message C:\PIC DOCUMENTS\MEDTIM.ASM 324 : Using default destination of 1 (file).list p=pic16f877radix hex; #include <p16f877>;================================================================================================================================================================================;; cpu equates (memory map)tmro equ 0x01status equ 0x03porta equ 0x05portb equ 0x06portc equ 0x07portd equ 0x08porte equ 0x09intcon equ 0x0ct1con equ 0x10second equ 0x20minute equ 0x21hours equ 0x22minutes equ 0x23;============================================================================================================================================================org 0x00goto start ;skip interrupt vectorstartorg 0x004bcf intcon,7 ;disable global interruptmovlw b'000001' ;setup port atris porta ;setup port a 1=in,0=outmovlw b'000000' ;clear portamovwf portamovlw b'00000111' ;setup portbtris portb ;setup portb 1=in, 0=outmovlw b'00000000' ;clear bmovwf portbmovlw b'00001100' ;portctris portc ;setup portc 1=in,0=outmovlw b'00000000' ;clear cmovwf portcmovlw b'00000000' ;setup dtris portdmovlw b'00000000' ;clear dmovwf portdpgmclrw ;clear wclrf second ;clear second countclrf minute ;clear minute countclrf minutes ;clear clock mintesclrf hours ;clear clock hoursbtfss porta,5 ;test port a5, skip next if set(low active)goto twobtfss portb,5 ;test portb5, skip next if setgoto fourbtfss portb,6 ;test portb6goto sixbtfss portb,7 ;test portb7goto eightbtfss portc,4 ;test portc4,skip next if setgoto tenbtfss portc,5 ;test portc5goto twelve

author: baljemmett
author_rank: Unknown
timestamp: February 14, 2013, 12:45:06 am
content: Quote from: RodH on February 13, 2013, 11:58:12 pmThat 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:bankseltrisdmovlwb'00000000';setup dmovwftrisdbankselportdmovlwb'00000000';clear dmovwfportd... 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!

author: fcb
author_rank: Super Contributor
timestamp: February 14, 2013, 12:55:56 am
content: don't use "tris" instruction, it's very oldinstead write directly to the register TRISD (if your using port D)