Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 18th January 2008, 01:36 PM   (permalink)
Default bank selection instruction

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 by m_saeed_soliman; 18th January 2008 at 07:42 PM.
m_saeed_soliman is offline  
Old 18th January 2008, 02:43 PM   (permalink)
Default

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.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 18th January 2008, 04:43 PM   (permalink)
Default

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.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 18th January 2008 at 04:56 PM.
futz is online now  
Old 18th January 2008, 05:17 PM   (permalink)
Default

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:


Quote:
;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 by m_saeed_soliman; 18th January 2008 at 07:11 PM.
m_saeed_soliman is offline  
Old 18th January 2008, 05:34 PM   (permalink)
Default

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.
__________________
Superman returns..

Last edited by bananasiong; 18th January 2008 at 05:36 PM.
bananasiong is offline  
Old 18th January 2008, 09:16 PM   (permalink)
Default

Quote:
Originally Posted by bananasiong
the text 'code' in the square bracket, followed by the program code, then '/code' in the square bracket.
Easier way: Simply click on the # in the menu immediately before pasting your code.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is online now  
Old 19th January 2008, 01:31 AM   (permalink)
Default

I use quick reply usually

BTW, I can't see any menu in my reply page. There are only Title, Message, Post Icons and Additional Options. Anything missing?
__________________
Superman returns..
bananasiong is offline  
Old 19th January 2008, 02:33 AM   (permalink)
Default

Quote:
Originally Posted by bananasiong
I use quick reply usually

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.
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
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 19th January 2008 at 08:17 AM.
futz is online now  
Old 19th January 2008, 03:22 AM   (permalink)
Default

Quote:
Originally Posted by m_saeed_soliman
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.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is online now  
Old 19th January 2008, 07:54 AM   (permalink)
Default

Quote:
Originally Posted by m_saeed_soliman
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:
Overview
Closeup
Angle closeup
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
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 19th January 2008 at 08:19 AM.
futz is online now  
Old 19th January 2008, 08:45 AM   (permalink)
Default

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
m_saeed_soliman is offline  
Old 19th January 2008, 10:00 AM   (permalink)
Default

Quote:
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).


Quote:
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.
eng1 is offline  
Old 19th January 2008, 10:18 AM   (permalink)
Default

Oh it appears to be different here.
Attached Images
File Type: gif diff.GIF (37.5 KB, 11 views)
__________________
Superman returns..
bananasiong is offline  
Old 19th January 2008, 10:24 AM   (permalink)
Default

Quote:
Originally Posted by m_saeed_soliman
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.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is online now  
Old 19th January 2008, 10:25 AM   (permalink)
Default

Quote:
Originally Posted by bananasiong
Oh it appears to be different here.
How did you get there? I've never seen that one.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is online now  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
PIC16F690 EEPROM counter issue pgenereu Micro Controllers 4 1st July 2007 02:21 AM
PIC programming!!! Styx General Electronics Chat 10 24th April 2006 06:23 PM
PIC 12 and 14 bits instruction sets Joel Rainville Micro Controllers 4 20th September 2005 09:15 AM
Question about bank selection, 16F628A, Nigel's tutorial kcn Micro Controllers 4 13th March 2005 07:23 AM
Processor Instruction Format mus3na Micro Controllers 1 19th January 2004 07:13 PM



All times are GMT. The time now is 03:58 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker