![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| 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. | |
| |
| | (permalink) |
| 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. | |
| |
| | (permalink) |
| Code: BANKSEL TRISA Code: include "P16F819.inc" 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 Code: bsf TRISA 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. | |
| |
| | (permalink) | |
| 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:
Last edited by m_saeed_soliman; 18th January 2008 at 07:11 PM. | ||
| |
| | (permalink) |
| 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
__________________ Superman returns.. Last edited by bananasiong; 18th January 2008 at 05:36 PM. | |
| |
| | (permalink) | |
| Quote:
__________________ ========================= Futz's Microcontrollers & Robotics ========================= | ||
| |
| | (permalink) |
| 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.. | |
| |
| | (permalink) | |
| Quote:
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. | ||
| |
| | (permalink) | |
| Quote:
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 Pull your MCLR pin high with a 33K or so resistor.
__________________ ========================= Futz's Microcontrollers & Robotics ========================= | ||
| |
| | (permalink) | |
| Quote:
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. | ||
| |
| | (permalink) |
| 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 | |
| |
| | (permalink) | ||
| Quote:
Quote:
Your code has benn assembled properly here. You could use MPASMWIN (Start Menu->Microchip->MPLAB IDE) while you try and solve the problem. | |||
| |
| | (permalink) |
| Oh it appears to be different here.
__________________ Superman returns.. | |
| |
| | (permalink) | |
| Quote:
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. Code: A language-plugin exception occurred and was logged. 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 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 ========================= | ||
| |
| | (permalink) | |
| Quote:
__________________ ========================= Futz's Microcontrollers & Robotics ========================= | ||
| |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| 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 |