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.

bank selection instruction

Status
Not open for further replies.

m_saeed_soliman

New Member
hi all
i have downloaded and used Mplab
i build my programs but i faced only one problem
it is how to select banks or to switch between bank0 , and bank1
i am using Assembly language
i used "banksel TRISA" to access BANK1 but this failed
i also used "bsf STATUS,RP0" but it aslo failed
so what can i do?
please and one who know Mplab can help me
 
Last edited:
Check my tutorials (or any other source code out there, including the datasheet for the chip) and see how they do it.

But you need to alter a bit in the STATUS register.
 
Code:
BANKSEL	TRISA
should work fine, providing you have the line
Code:
	include "P16F819.inc"
at the top of your code (change the P16F819 to the model # you're using).

You should have one of those includes at the top of every program you write.

Navigate to 'Program Files/Microchip/MPASM Suite'. Open the inc (include) file for your PIC model number and have a look. Get in the habit of using those equate symbols in your code instead of the hex addresses. Makes things so much more readable and easily understood. There's an include file there for every PIC. Use the proper one for whichever PIC you're using.

Here's a snip of the working program that line came from:
Code:
	LIST	p=16F819
	include "P16F819.inc"
	__config _INTRC_IO & _WDT_OFF & _LVP_OFF

	org	0x0000
init	
	BANKSEL	TRISA		;select bank 1
	clrf	TRISA		;PORTA all outs
	movlw	b'00000010'
	movwf	TRISB
	BANKSEL	PORTA		;select bank 0
	clrf	PORTA
	clrf	PORTB
spiinit	bsf	PORTB,0		;CS high
	BANKSEL	SSPSTAT		;select bank 1
	movlw	b'11000000'	;init SPI Master
	movwf	SSPSTAT
	BANKSEL	SSPCON		;select bank 0
	clrf	SSPCON
	movlw	b'00000010'
	movlw	SSPCON
	bsf	SSPCON,SSPEN

Oh ya, your line
Code:
bsf TRISA
is totally wrong and will never do anything (except generate an error on assembly), let alone what you thought it would do.

bsf sets a bit in a register. "bsf TRISA" is missing the bit location value that would tell it which bit in TRISA to set. Typical syntax is "bsf TRISA,3" to set bit 3. Better yet, use an equate symbol from the include file in place of that 3 to tell bsf which bit of TRISA to set.
 
Last edited:
thanks you all for your advice
but i still have the problem
this is my code , if you find anyhting wrong with it please tell me


code:


;program to turn diodes on PORTB on and off
;versio=8.0 date: 18\1\2008 Name:mss
PROCESSOR 16F84A
#INCLUDE "P16F84A.INC"
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
ORG 0x00
banksel TRISA
movlw 0xff
movwf TRISA
CLRF TRISB
banksel PORTA
CLRF PORTB
ask BTFSS PORTA,0
GOTO ask
movlw 0xff
movwf PORTB
CALL delay
CLRF PORTB
CALL delay
goto ask
delay
movlw .130
movwf 0x0c
CLRF 0x0d
loop decfsz 0x0d,1
goto loop
decfsz 0x0c,1
goto loop
return
end
 
Last edited:
Hi,
How's the hardware connection? The LED is not blinking or what?
Since you've already added the include file, you can use the registers' name in the program such as STATUS, RP0 (case sensitive) to make your programming to be easier.

*EDIT: Please use this:
Code:
paste your program here

the text 'code' in the square bracket, followed by the program code, then '/code' in the square bracket.
 
Last edited:
I use quick reply usually :p

BTW, I can't see any menu in my reply page. There are only Title, Message, Post Icons and Additional Options. Anything missing?
 
bananasiong said:
I use quick reply usually :p

BTW, I can't see any menu in my reply page. There are only Title, Message, Post Icons and Additional Options. Anything missing?
So go to Advanced if you're going to post code. Pretty simple fix. :D
bleh2.JPG

Or do the (code) and (/code) tags before and after your code. Replace those parentheses with square brackets. I can't actually use them or they disappear and the word ' and ' gets put in a code box.

The menu looks like this:
bleh.JPG
 
Last edited:
m_saeed_soliman said:
thanks you all for your advice
but i still have the problem
this is my code , if you find anyhting wrong with it please tell me
I went through it and neatened a few things up but found nothing terribly wrong with it. As far as I can see it should work if it's wired correctly.

Here it is in readable form:
Code:
;program to turn diodes on PORTB on and off
;versio=8.0 date: 18\1\2008 Name:mss
	LIST	16F84A
	#INCLUDE "P16F84A.INC"
	__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC

	cblock	0x0c
	d1,d2
	endc

	org	0x0000
	BANKSEL	TRISA	;bank 1
	movlw	0x01	;porta all outs except bit 0
	movwf	TRISA
	clrf	TRISB	;portb all outs
	BANKSEL	PORTA	;bank 0
	clrf	PORTA	;clear porta
	clrf	PORTB	;clear portb
ask	btfss	PORTA,0	;check switch?
	goto	ask
	movlw	0xff	;leds on
	movwf	PORTB
	call	delay	;delay
	clrf	PORTB	;leds off
	call	delay	;delay
	goto	ask	;go again

delay	movlw	0x82	;$82 = 130 decimal
	movwf	d1
	clrf	d2
loop	decfsz	d2,1
	goto	loop
	decfsz	d1,1
	goto	loop
	return

	end

Double check that the oscillator is actually working (and that you've selected the correct config option) and that the delay isn't way too short or way too long to suit the clock speed. Too short and you might not be able to see the LED blink that fast.

Pull your MCLR pin high with a 33K or so resistor.
 
m_saeed_soliman said:
thanks you all for your advice but i still have the problem
this is my code , if you find anything wrong with it please tell me
I didn't have a 16F84A but I did have a 16F84 in the junk box, so I breadboarded up a circuit similar to what I assume you're using.

Here's some pics:
**broken link removed**
**broken link removed**
**broken link removed**
1.95MB AVI Movie

Here's the code:
Code:
	LIST	P=PIC16F84
	#INCLUDE "P16F84.INC"
	__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC

	cblock	0x0c
	d1,d2
	endc

	org	0x0000
	BANKSEL	TRISA	;bank 1
	movlw	0x01	;porta all outs except bit 0
	movwf	TRISA
	clrf	TRISB	;portb all outs
	BANKSEL	PORTB	;bank 0
	movlw	0xff	;turn LEDs off (set portb)
	movwf	PORTB	;clear portb
ask	btfss	PORTA,0	;check switch?
	goto	ask
	call	delay	;delay
	clrf	PORTB	;leds off
	call	delay	;delay
	movlw	0xff	;leds on
	movwf	PORTB
	goto	ask	;go again

delay	movlw	0x82	;$82 = 130 decimal
	movwf	d1
	clrf	d2
loop	decfsz	d2,1
	goto	loop
	decfsz	d1,1
	goto	loop
	return

	end
 
Last edited:
thanks all
but no one understood my problem
the Mplab did not say my program is correct
this is the program


Code:
;program to turn diodes on PORTB on and off
;versio=8.0 date: 18\1\2008 Name:mss
		PROCESSOR 16F84A
		#include "p16f84a.inc"
		__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
		ORG 0x00
		BANKSEL TRISA
		movlw 0xff
		movwf TRISA
		CLRF TRISB
		BANKSEL PORTA
		movlw 0xff
		CLRF PORTB
ask		BTFSS PORTA,0
		GOTO ask
		movlw 0xff
		movwf PORTB
		CALL delay
		CLRF PORTB
		CALL delay
		goto ask
delay
		movlw .130
		movwf 0x0c
		CLRF 0x0d
loop	decfsz 0x0d,1
		goto loop
		decfsz 0x0c,1
		goto loop
		return
		end




and this is the message Mplab tells me



Code:
Executing: "D:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p16F84A "ledsblink.asm" /l"ledsblink.lst" /e"ledsblink.err" /o"ledsblink.o"

Message[302] D:\DOCUMENTS AND SETTINGS\XPPRESP3\MY DOCUMENTS\MPLAB WORK\LEDSBLINK.ASM 9 : Register in operand not in bank 0.  Ensure that bank bits are correct.

Message[302] D:\DOCUMENTS AND SETTINGS\XPPRESP3\MY DOCUMENTS\MPLAB WORK\LEDSBLINK.ASM 10 : Register in operand not in bank 0.  Ensure that bank bits are correct.

A language-plugin exception occurred and was logged.

BUILD FAILED: Sat Jan 19 09:37:20 2008



please should anyone tell me what is wrong with my program
 
Message[302] D:\DOCUMENTS AND SETTINGS\XPPRESP3\MY DOCUMENTS\MPLAB WORK\LEDSBLINK.ASM 9 : Register in operand not in bank 0. Ensure that bank bits are correct.

Message[302] D:\DOCUMENTS AND SETTINGS\XPPRESP3\MY DOCUMENTS\MPLAB WORK\LEDSBLINK.ASM 10 : Register in operand not in bank 0. Ensure that bank bits are correct.

Those are just warnings (that can be suppressed with the errorlevel directive, you can look at other code examples in the forum).


A language-plugin exception occurred and was logged.

BUILD FAILED: Sat Jan 19 09:37:20 2008

I don't know what that means exactly, but it seems that the problem is with your MPLAB settings?
Your code has benn assembled properly here. You could use MPASMWIN (Start Menu->Microchip->MPLAB IDE) while you try and solve the problem.
 
m_saeed_soliman said:
thanks all
but no one understood my problem
the Mplab did not say my program is correct

and this is the message Mplab tells me
Code:
Message[302] D:\DOCUMENTS AND SETTINGS\XPPRESP3\MY DOCUMENTS\MPLAB WORK\LEDSBLINK.ASM 9 : Register in operand not in bank 0.  Ensure that bank bits are correct.

Message[302] D:\DOCUMENTS AND SETTINGS\XPPRESP3\MY DOCUMENTS\MPLAB WORK\LEDSBLINK.ASM 10 : Register in operand not in bank 0.  Ensure that bank bits are correct.
Those two are just warnings to remind you that you should have changed banks before accessing those registers. You did change banks so you can ignore these.

Code:
A language-plugin exception occurred and was logged.
That's one I've never seen before. How did you set up the project?

Here's the steps, in case you don't know:

1. Select Project/Project Wizard
2. Step One: Select your device from the list.
3. Step Two: Select a language toolsuite. For assembler, the Active Toolsuite should be "Microchip MPASM Toolsuite". Don't change anything else on that page. Hit Next.
4. Step Three: Create New Project File. Browse to where you want your project stored. Create a directory for it if you want. If you do, move into the directory before naming the project so the project is created inside the directory. You would end up with a line like this example project named "bong" in a directory named "flop":
Code:
C:\MCU\16F84A\flop\bong
Name the project and hit Next.
5. Step Four: Add existing files to your project. If you have any asm source files already in the directory that you want added to the project, add them now. Hit Next.
6. Finish

Now select your programmer. If you haven't added a source file yet go Project/Add New File to Project and name your new empty xxxx.asm file.

That's it. You probably already knew all that, but maybe not. Impossible to tell from here. :)
 
Don't know.. This is my advanced reply page all the while. I use typing for quote, code, bold and even smileys. colon D :D
 
bananasiong said:
Don't know.. This is my advanced reply page all the while. I use typing for quote, code, bold and even smileys. colon D :D
Looks like you've got something disabled either in your profile or in your browser. All the normal menus are missing! :p
bleh3.jpg
 
Here's the steps, in case you don't know:

1. Select Project/Project Wizard
2. Step One: Select your device from the list.
3. Step Two: Select a language toolsuite. For assembler, the Active Toolsuite should be "Microchip MPASM Toolsuite". Don't change anything else on that page. Hit Next.
4. Step Three: Create New Project File. Browse to where you want your project stored. Create a directory for it if you want. If you do, move into the directory before naming the project so the project is created inside the directory. You would end up with a line like this example project named "bong" in a directory named "flop":
Code:
C:\MCU\16F84A\flop\bongName the project and hit Next.
5. Step Four: Add existing files to your project. If you have any asm source files already in the directory that you want added to the project, add them now. Hit Next.
6. Finish

Now select your programmer. If you haven't added a source file yet go Project/Add New File to Project and name your new empty xxxx.asm file.

That's it. You probably already knew all that, but maybe not. Impossible to tell from here.



thank you for helping
but i made all this and i still have the problem
please if you can hgelp me more , i would be grateful
 
Status
Not open for further replies.

Latest threads

Back
Top