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
 
Tools
Old 8th June 2008, 08:30 PM   #1
Default programming/compiling in MPLAB problem

I'm having trouble getting some code going to do what I'd expect it to do. Can I have some pointers? Here's my code:

Code:
;********************************************************************************

;Set up the assembler options (Chip type, clock source, other bits and pieces)
 LIST p=16F88, r=DEC
#include <P16F88.inc>
 __CONFIG _CONFIG1, _INTRC_IO & _MCLR_ON & _WDT_OFF & _LVP_OFF

;********************************************************************************


;********************************************************************************

;Start of the main program
STATUS          equ  03h           ;this assigns the word STATUS to the value of 03h,
                                   ;which is the address of the STATUS register.

TRISB           equ 86h            ;This assigns the word TRISB to the value of 86h,
                                   ;which is the address of the Tri-State register for PortB

PORTB           equ 06h            ;This assigns the word PORTB to 06h which is the
                                   ;address of Port B.

;********************************************************************************

	bsf		STATUS,5		; select Bank 1
	movlw	00h				; set the W register to 00h which
    movwf	TRISB			; sets all pins on PortB as outputs
    bcf		STATUS,5		; select Bank 0

;Start of the main program
Start	movlw	b'10'	; put binary value in W register to
        movwf   PORTB   ; set PortB.1 high an PortB.0 low
       ; movlw   b'00'   ; put binary value in W register to
       ; movwf   PORTA   ; set both PortB pins low again
        goto    Start   ; rinse'n'repeat!

		

 END
I should remark this is my first attempt at writing directly in assembly, and compiling the code in MPLAB. Maybe I'm making a mistake there? Do I just have to export a hex file, and save my assembly, then import the hex file and then program the chip? That's what I've been doing, anyway, and every time I've programmed I haven't been warned of any errors.

I thought this code would set PortB.1 high, but testing with a voltmeter I don't see that happening (it just kind of sits like most of the other PortB pins around 0.05V when the power's on).

Everything after "Start of main program," is mine, but the code before that is part of the header I've copied from what GCBASIC compiles to initialize the chip. There's a variety of other stuff I cut that GCBASIC does by default to initialize the chip, too, so maybe there's something I'm missing about that, too?

Last edited by Hank Fletcher; 8th June 2008 at 08:31 PM.
Hank Fletcher is offline  
Old 8th June 2008, 08:33 PM   #2
Default

MPLABs built in simulator should be your first line of troubleshooting. First thing I noticed was you're missing an ORG statement.

ORG 0x000

Will tell MPASM where to put the code.

Second copy & paste from a compiled language is not a good idea IMO.

Your program should redefine definitions like the example you posted.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/

Last edited by blueroomelectronics; 8th June 2008 at 08:35 PM.
blueroomelectronics is offline  
Old 8th June 2008, 08:39 PM   #3
Default

If you have an ICD or the Simulator you can single step through the program, else the LED turns on & off way to fast to see.
Code:
        LIST p=16F88, r=DEC
        #include <P16F88.inc>
        __CONFIG _CONFIG1, _INTRC_IO & _MCLR_ON & _WDT_OFF & _LVP_OFF
        org     0x000
    bsf        STATUS,RP0        ; select Bank 1
    movlw    0x00                ; set the W register to 00h which
        movwf    TRISB            ; sets all pins on PortB as outputs
        bcf        STATUS,RP0        ; select Bank 0
;Start of the main program
Start    movlw    b'00000010'    ; put binary value in W register to
        movwf   PORTB           ; set PortB.1 high an PortB.0 low
        movlw   b'00000000'   ; put binary value in W register to
        movwf   PORTB           ; set both PortB pins low again
        goto    Start           ; rinse'n'repeat!
 END
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Old 8th June 2008, 08:40 PM   #4
Default

Quote:
Originally Posted by Hank Fletcher View Post
I'm having trouble getting some code going to do what I'd expect it to do. Can I have some pointers? Here's my code:
Code:
 LIST p=16F88, r=DEC
Better to leave out the "r=DEC" radix change and leave it at the default hex radix. No biggy though.


These are unnecessary and redundant:
Code:
STATUS          equ  03h           ;this assigns the word STATUS to the value of 03h,
                                   ;which is the address of the STATUS register.

TRISB           equ 86h            ;This assigns the word TRISB to the value of 86h,
                                   ;which is the address of the Tri-State register for PortB

PORTB           equ 06h            ;This assigns the word PORTB to 06h which is the
                                   ;address of Port B.
They're already defined in
Code:
#include <P16F88.inc>

Instead of this:
Code:
	bsf	STATUS,5		; select Bank 1
	movlw	00h			; set the W register to 00h which
	movwf	TRISB			; sets all pins on PortB as outputs
	bcf	STATUS,5		; select Bank 0
do this:
Code:
	banksel	TRISB		;bank 1
	movlw	0x00
	movwf	TRISB
	banksel	PORTA		;bank 0

You need an org statement before your code starts
Code:
	org	0x00
Start	movlw	b'00000010'	; put binary value in W register to
        movwf   PORTB   ; set PortB.1 high an PortB.0 low
       ; movlw   0   ; put binary value in W register to
       ; movwf   PORTA   ; set both PortB pins low again
        goto    Start   ; rinse'n'repeat!
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 8th June 2008 at 08:47 PM.
futz is offline  
Old 8th June 2008, 08:40 PM   #5
Default

Is this better? It's all me, although I'm trying to adapt the code from a tutorial to use PortA instead of PortB.
Code:
ORG 0x000

;********************************************************************************

;Start of the main program
STATUS          equ  03h           ;this assigns the word STATUS to the value of 03h,
                                   ;which is the address of the STATUS register.

TRISB           equ 86h            ;This assigns the word TRISB to the value of 86h,
                                   ;which is the address of the Tri-State register for PortB

PORTB           equ 06h            ;This assigns the word PORTB to 06h which is the
                                   ;address of Port B.

;********************************************************************************

	bsf		STATUS,5		; select Bank 1
	movlw	00h				; set the W register to 00h which
    movwf	TRISB			; sets all pins on PortB as outputs
    bcf		STATUS,5		; select Bank 0

;Start of the main program
Start	movlw	b'10'	; put binary value in W register to
        movwf   PORTB   ; set PortB.1 high an PortB.0 low
       ; movlw   b'00'   ; put binary value in W register to
       ; movwf   PORTA   ; set both PortB pins low again
        goto    Start   ; rinse'n'repeat!

	
 END
1) I don't know how to use the simulator
2) I don't know what you mean by this:
Quote:
Your program should redefine definitions like the example you posted.
3) Presuming I'm setting the configuration bits in MPLAB, what else am I missing?

Thanks.
Hank Fletcher is offline  
Old 8th June 2008, 08:41 PM   #6
Default

Whoa! Thanks for the fast response, guys! Just give me a second to read what you've written.

Last edited by Hank Fletcher; 8th June 2008 at 08:41 PM.
Hank Fletcher is offline  
Old 8th June 2008, 08:41 PM   #7
Default

LOL you'll have to scroll up to see my version of your program Meh here it is again
Code:
        LIST p=16F88, r=DEC
        #include <P16F88.inc>
        __CONFIG _CONFIG1, _INTRC_IO & _MCLR_ON & _WDT_OFF & _LVP_OFF
        org     0x000
    bsf        STATUS,RP0        ; select Bank 1
    movlw    0x00                ; set the W register to 00h which
        movwf    TRISB            ; sets all pins on PortB as outputs
        bcf        STATUS,RP0        ; select Bank 0
;Start of the main program
Start    movlw    b'00000010'    ; put binary value in W register to
        movwf   PORTB           ; set PortB.1 high an PortB.0 low
        movlw   b'00000000'   ; put binary value in W register to
        movwf   PORTB           ; set both PortB pins low again
        goto    Start           ; rinse'n'repeat!
 END
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Old 8th June 2008, 08:48 PM   #8
Default

I was wondering about banksel as I was working through the tutorial. Is that from the include file, too? How can I know what protocol to follow in accordance with the other details of the include file, such as simply saying "movwf TRISB."

Yeah, I saw your program and I'll give it a try - thanks, Bill! Thanks for breaking it down, too, futz.

FYI: I know I'm coding to make the LED blink really fast, but I should still be able to read one or two volts off the pin with a multimeter. That's good enough for me right now - this is all part of me learning to toggle two pins fast enough to get some kind of NTSC signal going with just an internal oscillator.

Last edited by Hank Fletcher; 8th June 2008 at 08:52 PM.
Hank Fletcher is offline  
Old 8th June 2008, 08:57 PM   #9
Default

Quote:
Originally Posted by Hank Fletcher View Post
FYI: I know I'm coding to make the LED blink really fast, but I should still be able to read one or two volts off the pin with a multimeter.
If the pin is toggling at anything faster than once every second or two, forget about getting a reading with a multimeter (unless maybe your meter is real high end). They just don't work fast enough. Set the pin high and leave it high and measure and it will read 5V.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is offline  
Old 8th June 2008, 08:58 PM   #10
Default

I tried Bill's correction to my program, but it doesn't seem to do anything. Am I missing something really goofy here, like it terms of saving the .asm and .hex and programming the mcu?
Hank Fletcher is offline  
Old 8th June 2008, 09:00 PM   #11
Default

Quote:
If the pin is toggling at anything faster than once every second or two, forget about getting a reading with a multimeter (unless maybe your meter is real high end). They just don't work fast enough. Set the pin high and leave it high and measure and it will read 5V.
Yeah, I thought that might be the deal, which is why setting both pins to zero is remmed out in my OP. I'll give Bill's code a try again with those two lines remmed (is that even a verb?) again, and see what the multimeter says.

Last edited by Hank Fletcher; 8th June 2008 at 09:00 PM.
Hank Fletcher is offline  
Old 8th June 2008, 09:01 PM   #12
Default

You need a delay, or a scope. The 16F88 runs way to fast to see it flash.

I have a demo program for the 16F88 in the Firefly manual, might be helpful.

PS it is RB1 (PIN7) your checking right? And you do have a 0.1uf cap near the power pins plus a 10K to 22K pullup on pin4 (MCLR)... Right...
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/

Last edited by blueroomelectronics; 8th June 2008 at 09:06 PM.
blueroomelectronics is offline  
Old 8th June 2008, 09:04 PM   #13
Default

Quote:
Originally Posted by Hank Fletcher View Post
with those two lines remmed (is that even a verb?)
More commonly known as "commented out". Remmed was an old BASIC thing from the BASIC "rem", or remark, command.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 8th June 2008 at 09:04 PM.
futz is offline  
Old 8th June 2008, 09:07 PM   #14
Default

One more thing, this poster should help. It's helped plenty of folks get their first LED flashing.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Old 8th June 2008, 09:09 PM   #15
Default

Quote:
PS it is RB1 (PIN7) your checking right? And you do have a 0.1uf cap near the power pins plus a 10K to 22K pullup on pin4 (MCLR)... Right..
Yeah, I'm working through the goof list. I'm checking the right pin, and I have MCLR pull up. I've never put a cap across the power pins, and I've never had any trouble by not doing so, but I'll give that a try.
Hank Fletcher is offline  
Reply

Tags
mplab, problem, programming or compiling

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
Programming C in MPLAB simrantogether Micro Controllers 11 11th February 2008 07:40 PM
Programming PICC through MPLAB MatrixPhreak Micro Controllers 25 9th December 2007 04:56 PM
Programming HEX file with MPlab/Inchworm gregmcc Micro Controllers 4 27th April 2007 04:20 PM
compiling with MPLAB evandude Micro Controllers 4 9th April 2005 09:08 AM
Compiling 16F628A - problem kenmac Micro Controllers 4 23rd September 2004 06:00 AM



All times are GMT. The time now is 05:28 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker