Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Mplab Error Msg Driving Me Mad!!

Status
Not open for further replies.

cyprio7

New Member
hi guys

i have been trying to write a program but i cant seem to be able to change the page from bank0 to 1.

i have attatched the code i am using called "prog2"


i keep getting the error message

"register in operand not in bank 0. ensure that bank bits are correct."

i am using pic16f628.

when this message comes up, it points to the lines of code where i am trying to load values into TRISA and TRISB.


i have tried someone elses source file too, called "sampleprog" and the same is happening for that too. i am using mplab IDE v7.50.

can somebody please help me coz im losing sleep over this, i cant even write values into TRIS A AND B!!!!!!

thanks
 
sorry forgot to attatch files. here they are
 

Attachments

  • sampleprog.asm
    3.5 KB · Views: 133
  • prog2.asm
    697 bytes · Views: 139
You didn't manage to attach the file, however, this is a common problem. The important thing is that this is not an error message, it is a warning and as such does not stop your file from assembling/compiling. You can get rid of this annoying warning with the following line,
Code:
            errorlevel    -302

This is of course assuming that you have switched banks before the error line.

Mike.
 
thanks for ur message. the thing is tho, when i watch the values in the watch window, i cant even see the values being moved into TRISA and TRISB from the accumilator, w.

and for exmaple, when i run the program on xp, it comes up as an error but it still buildsl the file, when i run it on vista, it comes up as error but doesnt build at all.

anyway i have attathed files as txt, i hope they work, mayb then u can see anything i am missing. thank you
 

Attachments

  • prog2.txt
    697 bytes · Views: 133
  • sampleprog.txt
    3.5 KB · Views: 142
hi,
It runs OK on my PIC Sim. I am running Win XP Pro.
 
Last edited:
Ah, I can now see your code.

The only thing I can see wrong is that both RX and TX have to be setup as input for the serial port to work.

Try,
Code:
        movlw b'11110110'       ; RB7-RB4, RB1(RX) and RB2(TX)=input, others output 
        movwf TRISB

HTH

Mike.
 
Why would you set TX to be an input?, it needs to be an output surely? - it's possible that setting it as TX overrides TRIS?, but in any case it still makes more sense to set it as an output.
 
well yes, you are sending data OUT from it, so why would it be an input? do you think if i used an older version of mplab it will sort this out? am i changing the bank pages properly in my code??
 
Nigel Goodwin said:
Why would you set TX to be an input?, it needs to be an output surely? - it's possible that setting it as TX overrides TRIS?, but in any case it still makes more sense to set it as an output.

From the data sheet, section 12,
Bit SPEN (RCSTA<7>) and bits TRISB<2:1> have to be set in order to configure pins RB2/TX/CK and RB1/RX/DT as the Universal Synchronous Asynchronous Receiver Transmitter.

Mike.
 
I suspect that means they have to be set correctly - not 'set' as opposed to 'cleared'

Here's the similar line for the 876/7 datasheet.

Bit SPEN (RCSTA<7>) and bits TRISC<7:6> have to
be set in order to configure pins RC6/TX/CK and
RC7/RX/DT as the Universal Synchronous Asynchronous
Receiver Transmitter.

That definitely works perfectly with TX set as an output, but I've never tried setting it as an input? - doesn't really seem much point?.
 
Try it, I just tried it with a 16F886 and the transmit does not work if the pin is set as output. I suspect the same with a 16F628.

Mike.
 
Pommie said:
Try it, I just tried it with a 16F886 and the transmit does not work if the pin is set as output.
Really? The E-USART is quite different. When you set the SPEN bit, the RX/TX pins should be configured automatically regardless of the TRIS bits (see notes on page 151/4). I will try that on next days.


Edit: cyprio7, I too can see the content of the registers with MPLAB SIM and WinXp.
Your program is not terminated properly. Add a goto $ instruction before the end directive.
 
Last edited:
It doesn't really matter in this case as the OP had RB2 set and so had the TX pin as input and the RX pin as output. However, the data sheet on the 16F628 is specific and states both TX and RX should be input. As to the 16F886, I may have a bug there.:eek:

From the attached code,
Code:
        movlw b'00000100'       ; RB2(TX)=1 others are 0 
        movwf PORTB

Mike.
 
This is interesting.

Many Microchip datasheets told user to set the TRIS bit of the TX pin high to use the USART function. Many of us are aware of that.

However, on the errata sheet of a newer PIC, the 18F2X1X, here:

https://www.electro-tech-online.com/custompdfs/2007/12/80227b.pdf

It specifically mentioned that "The correct setting of the TRIS bit is 0".

The TRIS setting for the TX pin on PORTC in
Table 9-5 of the Device Data Sheet was incorrectly
stated as ‘1’.
The correct TRIS setting for the TX pin on PORTC
is ‘0’.

So the datasheet should be consulted for the correct action in all these cases.
 
Looking at the block diagram for the 16F628A, RB1/2 port, the output of the TRIS latch is ANDed with a 'Peripheral OE' enable signal and this controls the output buffer. (Figures 5.9/10 in the datasheet)

Therefore if the peripheral is enabled, the state of the TRIS latch is irrelevant since the output buffer is controlled by the Peripheral output enable.

Looking at the block diagram for RC6/7 on the 16F866 shows that the output buffer is controlled only by the TRIS latch, so it would need setting correctly to use the EUSART. On the 16F88, some I/O pins have additional logic to force the state of the output buffer when a peripheral is in use, others don't.

It would appear that the requirement to set the TRIS latch to input or output when using the I/O pin with a peripheral would depend on the specific PIC and peripheral being used. A quick look at the port block diagram schematic will reveal all (assuming the datasheet is correct).
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top