Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

what wrong with my coding

Status
Not open for further replies.

muizzuddin_afifi

Junior Member level 2
Joined
Apr 4, 2011
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Malaysia
Activity points
1,419
Code:
	list		p=16F887
	#include	<p16F887.inc>

	__CONFIG	_CP_OFF&_WDT_OFF&_PWRTE_ON&_LVP_OFF&_HS_OSC


		ORG		0x000
		goto 	main

main

		banksel	TRISA
		movlw	0xFF
		movwf	TRISA
		clrf	TRISC
		clrf	TRISD
		banksel	ADCON0

		movlw	b'10000001'
		movwf	ADCON0
		banksel	ADCON1
		movlw	b'10001110'
		movwf	ADCON1
		banksel	ADCON0


		bsf		ADCON0,2
		btfsc	ADCON0,2
		goto	$-1
		movf	ADRESH,0
		andlw	b'00000011'
		movwf	PORTC
		banksel	ADRESL
		movf	ADRESL,0
		banksel	ADRESL
		movwf	PORTD

	return

	end

have error
Executing: "C:\Program Files\Microchip\MPASM Suite\MPASMWIN.exe" /q /p16F887 "as.asm" /l"as.lst" /e"as.err"
Error[126] D:\USERS\GH0STSHIFT\DOCUMENTS\STUDY\PROGRAM\CNTH\AS.ASM 4 : Argument out of range (not a valid config register address)
Message[302] D:\USERS\GH0STSHIFT\DOCUMENTS\STUDY\PROGRAM\CNTH\AS.ASM 14 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] D:\USERS\GH0STSHIFT\DOCUMENTS\STUDY\PROGRAM\CNTH\AS.ASM 15 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] D:\USERS\GH0STSHIFT\DOCUMENTS\STUDY\PROGRAM\CNTH\AS.ASM 16 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] D:\USERS\GH0STSHIFT\DOCUMENTS\STUDY\PROGRAM\CNTH\AS.ASM 23 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] D:\USERS\GH0STSHIFT\DOCUMENTS\STUDY\PROGRAM\CNTH\AS.ASM 34 : Register in operand not in bank 0. Ensure that bank bits are correct.
Halting build on first failure as requested.
 

Check the parameters in the __CONFIG are all valid. The number (14, 15, 16, 23, 34) are line numbers in the listing file so you can check what caused them.
"Message[302]" is just a warning, not an error. All it means is the register being used is not shared across all the banks so be careful to ensure the correct bank is selected. You can stop it being displayed if you want by adding the line "errorlevel -302" just after the #include line.

Another hint: "goto $-1" is not a good idea. It will work properly in your case but it stops the program being portable. The reason is that it tells the assembler to jump back one address from where it is at the moment ($ means the current address) which is fine on 16F processors but if you ever try it on 18F or other 16-bit PICs it will not work properly. On 16 bit processors each instruction uses two 8-bit addresses so using $-1 jumps back half an instruction! If you use labels instead it stops the problem because the assembler always works out where the 'goto' should really point to. there are some circumstances where "goto $-1" can be used safely but this isn't one of them.
Instead of :
Code:
		bsf		ADCON0,2
		btfsc	ADCON0,2
		goto	$-1
		movf	ADRESH,0

use a label instead:

Code:
		bsf		ADCON0,2
myLabel
		btfsc	ADCON0,2
		goto	myLabel
		movf	ADRESH,0

Brian.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top