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.

Error 302 explanation please..

Status
Not open for further replies.

MrNobody

New Member
Hi, I'm currently doing Nigel's Tutorial 3-1 on LCD. In it, i saw this line "ERRORLEVEL 0, -302 ;suppress bank selection messages". After looking at MPASM Assembler Help file, below is the explanation for Error 302.

Umm, how do I phrase the question...?
Ok.. The ERRORLEVEL line above merely suppress the error message but the error is still there. With the ERROR 302 still present, the code still work..
The source of the error is from "movwf LCD_TRIS".

Code:
SetPorts	bsf 	STATUS,		RP0	;select bank 1
		movlw	0x00			;make all pins outputs
		[B]movwf	LCD_TRIS     <<<---------- Source of error message[/B]
		bcf 	STATUS,		RP0	;select bank 0

		call	Delay100		;wait for LCD to settle


		call	LCD_Init		;setup LCD

My question is that what is Error 302 or rather, how can a working code contain Error messages...? Umm, its more for curiosity sake that i ask that question.. Hope somebody can spend some of their time in explaning..
Thanks.




Explanation for ERROR 302:
Code:
302 Register in operand not in bank 0. Ensure that bank bits are correct. 
This is a commonly seen reminder message to tell you that a variable that is being accessed in not in bank 0. This message was added to remind you to check your code, particularly code in banks other than 0. Review the section on banksel (banksel - Generate Bank Selecting Code) and bankisel (bankisel - Generate Indirect Bank Selecting Code (PIC12/16 MCUs)) and ensure that your code uses bank bits whenever changing from ANY bank to ANY other bank (including bank 0). 

Since the assembler or linker can't tell which path your code will take, you will always get this message for any variable not in bank 0. You can use the errorlevel command to turn this and other messages on and off, but be careful as you may not spot a banking problem with this message turned off. For more about errorlevel, see errorlevel - Set Message Level. 

A similar message is 306 for paging.
 
The answers to your question is in the text you posted. It is a warning. It wants you to check that the right bank is selected because it can not.

302 Register in operand not in bank 0. Ensure that bank bits are correct.
This is a commonly seen reminder message to tell you that a variable that is being accessed in not in bank 0. This message was added to remind you to check your code, particularly code in banks other than 0. Review the section on banksel (banksel - Generate Bank Selecting Code) and bankisel (bankisel - Generate Indirect Bank Selecting Code (PIC12/16 MCUs)) and ensure that your code uses bank bits whenever changing from ANY bank to ANY other bank (including bank 0).

Since the assembler or linker can't tell which path your code will take, you will always get this message for any variable not in bank 0. You can use the errorlevel command to turn this and other messages on and off, but be careful as you may not spot a banking problem with this message turned off. For more about errorlevel, see errorlevel - Set Message Level.

A similar message is 306 for paging.​
 
Oh.. so.. it isn't actually an error then.. Am I right..?
I thought it was an error.. And I was puzzeled because how can the code work if there is an error..
 
If you want to get rid of the warning without turning it off, you can do the following,

Code:
SetPorts	bsf 	STATUS,		RP0	;select bank 1
		movlw	0x00			;make all pins outputs
		movwf	LCD_TRIS[COLOR="Red"] & 0x7f[/COLOR]    <<<---------- Source of error message
		bcf 	STATUS,		RP0	;select bank 0
		call	Delay100		;wait for LCD to settle
		call	LCD_Init		;setup LCD

Doing this will give you a little memory jog and you can check that the correct bank is selected before adding the "& 0x7f".

Mike.
 
If you want to get rid of the warning without turning it off, you can do the following,

Code:
SetPorts	bsf 	STATUS,		RP0	;select bank 1
		movlw	0x00			;make all pins outputs
		movwf	LCD_TRIS[COLOR="Red"] & 0x7f[/COLOR]    <<<---------- Source of error message
		bcf 	STATUS,		RP0	;select bank 0
		call	Delay100		;wait for LCD to settle
		call	LCD_Init		;setup LCD

Doing this will give you a little memory jog and you can check that the correct bank is selected before adding the "& 0x7f".

Mike.
Thanks..
Umm.. I think i got it but still not sure if it is right or not..
Is it because MOVWF is a Byte-oriented file register operations and according to Figure 15-1 of PIC16F628 datasheet, it only receives 7-bit file register address. The statement "TRISA & 0x7f" is actually the same as "0x55 & 0x7F" where 0x55 is hexadecimal for 85 which is the address for TRISA.. And by doing that, I'm actually writing the 7 bit of the address instead of 8 bit.

When I do the same thing to other file registers in Bank 1 (because RP0 = 1 is to select Bank 1 registers) such as TXSTA, the same error message appear.

Is my understanding correct..? Thanks.
 
Yes, anding with 0x7f keeps only the lower 7 bits and so the assembler is happy. The RP0 and RP1 bits are actually bits 8 and 9 of the address and are combined with the 7 bits contained in the instruction.

When you write "TRISA & 0x7f" it's actually the same as "0x85 & 0x7F" which is equal to 0x55. At run time, this 0x55 has 0x80 added to it as RP0 is set and this is the address for TRISA. The same goes for TXSTA except 0x100 is added as RP1 is set. If both were set the 0x180 would be added.

Mike.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top