> > Wilf Melling wrote: > > > I have made a start on my very first PIC project, it is to be a home > > alarm system (hopefully). So here my very first plea for help, I > > keep getting the following message. I have read the manuals but the > > answer does not jump out at me. > > > > Message[302] C:\MPASM\HALARM.ASM 40 : Argument out of range. Least > > significant bits used. > > > > Code sample with line numbers:- > > 39 Movlw PORT_B_OUT ;Define PORTB > > 40 Movwf TRISB ;as output > > > > PORT_B_OUT EQUates to b11111111 > > Wilf: > > This has nothing to do with your problem, but if you want all the > PORTB pins to be outputs, PORT_B_OUT must equate to 00000000. > > Ok... > > The MPASM message refers not to PORT_B_OUT but to TRISB. > > If you look at the instruction set for your PIC, you'll see that > register-oriented instructions only have room for 7-bit register > addresses, so they can only address 128 registers. To accomodate > more than 128 registers, PICs employ a banking scheme that uses a few > bits of the STATUS register to select from multiple 128-register > banks. > > If you try to directly access a register in any bank other than Bank > 0, MPASM won't be able to fit the register's 8-bit address into the > instruction. Instead, it'll just use the low 7 bits of the > register's address and generate the message you're seeing. > > TRISB is located at address 086H, which puts it in Bank 1. To access > it, you need to select bank 1 (by setting the RP0 bit in the STATUS > register), then write to register 006H. Before accessing registers on > Bank 0, you'll need to switch back to that page by clearing the > RP0 bit. Your code should look like this: > > BSF STATUS,RP0 > > MOVLW PORT_B_OUT > MOVWF 080H ^ TRISB > > BCF STATUS,RP0 > > The "080H ^ TRISB" exclusive-ORs the TRISB address with 080H, thereby > clearing the high bit of the address... It's equivalent to "07FH & > TRISB", "TRISB - 128", and "006H". > > -Andy That's a great explaination Andy. Now can I ask a dumb question? The 16C84 Datasheet (and I assume the others too) state that the FSR will utilize all 8 bits of the file address on indirection. So would the following work? movlw TRISB movwf FSR movlw .0 ; Note that 0 bits are required for output movwf INDF It's the same number of instructions but I find it slightly more straight- forward personally. BTW I just re-read the databook and in fact the IRP bit in the status register is prepended to the FSR giving a nine bit address. So in fact 4 128 register pages are accessible using indirection. Cool. BAJ