Hello Mathew. I've had my nap. Not long enough but... > Thankyou to the people who who have given suggestions and help for the > following code, but no body has solved the problem of the " not in > bank 0 " error that it generates. > What is this line all about? > movwf TRISA ^ 0x080 The assembler, as I said, has no idea of which bank it is in. While as a matter of "form", PORTA is seen as address $05 and TRISA as $85, the assembler only sees the first seven bits and whinges if bit 8 is set as you have seen. One way of stopping it whinging is to continue to use the correct address, TRISA, but to hide it from the assembler by knocking off the eighth bit, either by AND-ing it with $7F or "flipping" the eighth bit by XOR-ing it with $80, and that is exactly what the above line does. "TRISA ^ 0x080" is a compound expression that evaluates to an address of $05. > Thanks for the advice I used the TRIS command as you suggested it gave > me a error saying that is suggests not using it??? Just another one of > those things I guess. "Use the ERRORLEVEL, Luke!" You should put " ERRORLEVEL -224" into your P16F84.INC file. This warning is so insane it is beyond description. The instruction works, it will *always* work, it has *no* bugs, it is the fastest and thus *preferred* way to set the (A and B only) TRIS registers in the vast majority of cases, it is independent of bank switching, and it is incorporated in the *latest* processors as well. ERRORLEVEL -305 appears to be useful for something also. > Also the code does not work when burn to a pic. When simulated it > works fine until it hit a loop. Then MPLAB starts "dinging" me > (making an error sound) I am not sure what thats for I think it is to > do with the loop being endless. I think that was the stack overflow someone else commented on. Your code appeared to be badly tabbed when posted. It should arguably look like the following for legibility. Double spacing is unnecessary: > ;********************************************************************* > ; INOUT.ASM > ; > ; This is a simple programs that pass the value entered into portb to > ;porta. > ; If portb bit 7 is high it does a little led chase. > ; > ;********************************************************************* > > LIST P=16F84, R=DEC > include "p16f84.inc" ERRORLEVEL -224 > __FUSES _CP_OFF & _WDT_OFF & _HS_OSC ;Set default config ** HS oscillator? 4 MHz? What's wrong with XT? > ;--------------------------------------------------------------------- > ScratchPadRam EQU 0x20 > ;--------------------------------------------------------------------- > ; Variables > ;--------------------------------------------------------------------- > dipvals EQU ScratchPadRam+0 ; ** Verbose if you ask me! > step1 EQU ScratchPadRam+1 ; ** Use CBLOCK to do this. > step2 EQU ScratchPadRam+2 > step3 EQU ScratchPadRam+3 > step4 EQU ScratchPadRam+4 > Steppos EQU ScratchPadRam+5 > Temp EQU ScratchPadRam+6 > ; Useful MOVLF MACRO lit,file MOVLW lit MOVWF file ENDM ; Also useful MOVFF MACRO source,dest MOVF source,W MOVWF dest ENDM > ;--------------------------------------------------------------------- > ; Program Code > ;--------------------------------------------------------------------- ** ; Is this right? > ; Set the reset vector here. If you are using a PIC16C5X device, > ; use: > ; ORG > ; Otherwise, use: > ; ORG 0 > ;--------------------------------------------------------------------- > ORG 0 > GOTO Start > ;--------------------------------------------------------------------- > ; Main Program > ;--------------------------------------------------------------------- > ORG H'50' > Start MOVLF B'00000001',step1 MOVLF B'00000010',step2 MOVLF B'00000100',step3 MOVLF B'00001000',step4 CLRF Steppos > CALL InitPortA ; Sets up porta to be outputs > CALL InitPortB ; Sets up portb to be inputs CALL Inittmr ; Initialise timer > Loop > MOVF PORTB,W ; Read Portb into w register > MOVWF PORTA ; Move W into Porta ** Can't do a bit test on W BTFSC PORTB,7 ; If bit 7 is set goto Chase > CALL Chase GOTO Loop > > ;--------------------------------------------------------------------- > Chase BTFSS PORTB,7 ; Switch bit still set? RETURN ; If not, return BTFSC INTCON,T0IF ; If timer has overflowed CALL Step ; then do a step GOTO Chase ; else try again > > ;--------------------------------------------------------------------- > Step ; ** Sorry, your code was not repairable(!!). BCF INTCON,T0IF ; Clear the interrupt (T-ZERO-I-F) INCF Steppos,F BTFSC Steppos,2 ; Is it 4? CLRF Steppos ; if so, zero MOVF Steppos,W ADDLW step1 ; Use as index, add to *address* step1 MOVWF FSR ; MOVF INDF,W ; load W with step(Steppos) ; MOVWF PORTA ; Output Step pattern ; Or, more neatly: MOVFF INDF,PORTA ; output step(Steppos) > RETURN > ;--------------------------------------------------------------------- > InitPortA > MOVLW 0 ; Clears w register TRIS PORTA ; Set port a as outputs > MOVWF PORTA ; clear outputs > RETURN > > ;--------------------------------------------------------------------- > InitPortB > MOVLW 255 ; TRIS PORTB ; Set port a as inputs > RETURN > > ;--------------------------------------------------------------------- > Inittmr ; BCF INTCON,INTF ; Clears interrupt if set (but why?) ; Port B pullups ON, TMR0 internal, prescale 256 > MOVLW B'00000111' ; OPTION ; Option reg, similar TRIS instruction > RETURN > > END Note that since I know the Register Bank Select bit defaults to zero, I need never alter it! -- Cheers, Paul B.