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.

programming/compiling in MPLAB problem

Status
Not open for further replies.
I'll give that a try. I'm sure with Bill's code it's something basic I'm missing in terms of writing, compiling, programming the PIC.
Well, mine is missing the config line. I need to add one. It's assuming you're setting it with MPLAB.

Here's a bad, but working, config line, shown in context with the preceding two lines:
Code:
	LIST	p=16F88
	include "P16F88.inc"
	__config _CONFIG1, 0x3f2a
That really should have the actual definitions in there rather than just a number, so you could see at a glance what fuses you were setting. At the time I did that I didn't know any better. But it should work fine anyway. Fix it later.

1) I open up MPLAB.
2) I select File> New.
3) This opens an "Untitled" window, which I notice is very bare, as in no code or even PC numbers in the margin when I type stuff in. That's new to me, because they're always there when you compile from GCBASIC.
4) I copy and paste in futz's code, but the text is all black, as in no colour-coding that I usually see in a compiled GCBASIC program. Also, the "program," "release from reset," etc icons are not present.

That's where I'm at. Can you get me to point B?
No.

Do this:
1. Start MPLAB
2. Click Project/Project Wizard
3. Click Next
4. Select your exact MCU from the list and hit Next
5. Select your language toolsuite (Microchip MPASM Toolsuite) and Next
6. Create a directory for it and a New Project File in that directory and Next
7. Hit next at Step Four as you don't have a source file saved yet
8. Hit Finish
9. Click Project/Add New File To Project. Be sure you're pointing to the correct directory. Name the file something.asm and hit Save.
10. Paste the source code into the window and hit CTRL-S

Assemble and program at will
 
Last edited:
kchriste said:
That's because you haven't saved the file yet. Save it as blinky.asm and then you'll get your code colours.
Yay, I have colours now!

To get these, you need to select your programmer. Click "Programmer/Select Programmer" and select the ICD2, etc.
D'oh! I should have realized that. This has been wearing on me a bit, I think!

futz said:
Well, mine is missing the config line. I need to add one. It's assuming you're setting it with MPLAB.
Okay, I'll give that a try. I'm gonna go with kchriste's suggestions first, and if that doesn't work I'll try doing through the project wizard.
 
Argh! That's still not working for me. Is this suppose to be making PortA.1 flash (so pin 18 of the IC)?

The only configuration bit I changed was the internal oscillator as RB6.
 
No PORTA.7 pin 16
Many A ports are A/D or have comparators that have to be disabled, A7 is a digital I/O pin by default.
I'm still getting nothing.

Wait,

Did you mean pin 16 with just your code, or futz's as well?
 
OK. Here it is, complete, and all in one post, with photos. :D

That's a blue LED, so I used a 180 ohm resistor. For a red or green or amber LED you'd probably use a 330 ohm or even 470. Not terribly critical. But do use a current limiting resistor somewhere in that range.

It has a 33K MCLR pullup. Any value from 10K to 33K is fine. It's not critical at all.

16f88_blinky_ra1_001sm.jpg16f88_blinky_ra1_002sm.jpg16f88_blinky_ra1_003sm.jpg

Code:
	LIST	p=16F88
	include "P16F88.inc"
	__config _CONFIG1, _WDT_OFF & _INTRC_IO & _MCLR_ON
	ERRORLEVEL 0, -302

	cblock	0x20
	d1,d2,d3
	endc

	org	0x0000
init
	banksel	CMCON		;bank 1
	movlw	0x72		;8MHz internal osc
	movwf	OSCCON
	movlw	0x07		;turn comparators off
	movwf	CMCON
	clrf	ANSEL		;all pins digital
	movlw	0x00		;all pins outputs
	movwf	TRISA
	movwf	TRISB
	banksel	PORTA		;select bank 0

main	bsf	PORTA,1
	call	delay
	bcf	PORTA,1
	call	delay
	goto	main

delay	movlw	0x15
	movwf	d1
	movlw	0x74
	movwf	d2
	movlw	0x02
	movwf	d3
delay_0	decfsz	d1,f
	goto	dd2
	decfsz	d2,f
dd2	goto	dd3
	decfsz	d3,f
dd3	goto	delay_0
	return

	end
 
Last edited:
And here's the same thing in C (SourceBoost BoostC):
Code:
#include <system.h>
#include <stdio.h>
#pragma CLOCK_FREQ 8000000
#pragma DATA _CONFIG, _WDT_OFF & _INTRC_IO & _LVP_OFF & _MCLR_ON

void main(void)
{
	osccon=0x72;
	cmcon=0x07;
	ansel=0;
	trisa=0;
	while(1){
		porta.1=1;
		delay_ms(500);
		porta.1=0;
		delay_ms(500);
	}
}
 
Still nothing. Once I've saved the .asm, how do I get the .hex file? I've been going to file>export, then leaving the options as they are, and then saving as a .hex file. Then I import the .hex file. Is that right?
 
Okay, if only to prove that I'm not a complete idiot, here's what I can make work quite easily. In fact, I've got an LED blinking steadily off pin 18 as I write this. Here's the GCBASIC code:
Code:
#chip 16F88, 8
#config OSC = INTRC_IO, MCLR_ON

'Set the pin directions
dir PORTA.1 out 'check the PIC pins for these ports!

'Main routine
Start:
SET PORTA.1 ON 
wait 1 sec
SET PORTA.1 OFF
wait 1 sec
goto Start

When you put the above code into the GCBASIC compiler, it automatically creates a .asm and .hex file. In MPLAB, I go to file>open and I open up the .asm file, which looks like this:
Code:
;Program compiled by Great Cow BASIC (0.9 10/2/2007)
;Need help? See the GCBASIC forums at http://sourceforge.net/forum/?group_id=169286,
;check the documentation or email hconsidine@bigpond.com.

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

;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

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

;Set aside memory locations for variables
DELAYTEMP	equ	32
DELAYTEMP2	equ	33
DELAYTEMP4	equ	34
SysTemp1	equ	35
SysTemp2	equ	36
SysWaitTempMS	equ	37
SysWaitTempS	equ	38

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

;Jump to initialisation code when PIC is reset
	ORG	0
	call	INITSYS
	goto	SystemInitialise

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

;Interrupt vector
	ORG	4
	retfie	

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

;Various initialisation routines, automatically called by GCBASIC
SystemInitialise

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

;Start of the main program
	banksel	TRISA
	bcf	TRISA,1
START		
	banksel	PORTA
	bsf	PORTA,1
	movlw	1
	movwf	SysWaitTempS
	call	Delay_S
	bcf	PORTA,1
	movlw	1
	movwf	SysWaitTempS
	call	Delay_S
	goto	START
BASPROGRAMEND		
	sleep	
	goto	$
		
;********************************************************************************
;Subroutines included in program
;********************************************************************************
		
DELAY_MS		
DMS_START		
	movlw	10
	movwf	DELAYTEMP2
DMS_OUTER		
	movlw	66
	movwf	DELAYTEMP
DMS_INNER		
	decfsz	DELAYTEMP, F
	goto	DMS_INNER
	decfsz	DELAYTEMP2, F
	goto	DMS_OUTER
	decfsz	SysWaitTempMS, F
	goto	DMS_START
	return	
		
;********************************************************************************
		
Delay_S		
DS_START		
	movlw	10
	movwf	DELAYTEMP4
DS_OUTER		
	movlw	100
	movwf	SysWaitTempMS
	call	Delay_MS
	decfsz	DELAYTEMP4, F
	goto	DS_OUTER
	decfsz	SysWaitTempS, F
	goto	DS_START
	return	
		
;********************************************************************************
		
INITSYS		
	movlw	112
	movwf	SysTemp1
	banksel	OSCCON
	movf	OSCCON,W
	banksel	SysTemp1
	iorwf	SysTemp1,W
	banksel	OSCCON
	movwf	OSCCON
	banksel	PORTA
	clrf	PORTA
	clrf	PORTB
	movlw	7
	banksel	CMCON
	movwf	CMCON
	banksel	ADCON0
	bcf	ADCON0,ADON
	banksel	ADCON1
	bcf	ADCON1,ADFM
	clrf	ANSEL
	banksel	STATUS
	return	
		
;********************************************************************************

 END
Next, all I have to do is import the .hex file that was automatically created by GCBASIC when I compiled my BASIC text. I just go to file>import and import the .hex, and that's it. Then I just insert my chip, click program, click release from reset, and insert the chip into the circuit. And there it is, blinking away... wait, it's behind me... yep, still going!

Which brings me to the point where I must be screwing up the process when I'm not using GCBASIC. You guys say your program's work for you, so I must be doing something wrong in MPLAB, but I can't figure out what. Please help, this is driving me nutty!
 
It would help if we knew the programmer / software you're using. Some do not import the config fuses properly.
I used GCBASIC for the above, but when I started this thread (and what I'm trying to learn here) I was just writing the assembly code into MPLAB. The programmer is an ICD2 clone (called ICD2.5) that I bought from a Vancouver distributor. I'd link to it, but I don't think they're selling it anymore. It's worked great up to now, and I'm humble enough to admit that I'm more inclined to think it's (my) human error at this point.
 
Last edited:
Post your .hex file that doesn't work.

PS try using your ICD2 as a debugger. You can see exactly what it's doing that way.
 
Last edited:
I tried to do a Quick Build (just experimenting with things) on the text I posted earlier of Bill's blinking program, and this is what happened:
Code:
Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p16F88 "billink.asm" /l"billink.lst" /e"billink.err"
Warning[205] C:\PROGRAM FILES\GCBASIC\NOT GCBASIC FILES (ASSEMBLY CODED)\BILLINK.ASM 1 : Found directive in column 1. (list)
Error[105]   C:\PROGRAM FILES\GCBASIC\NOT GCBASIC FILES (ASSEMBLY CODED)\BILLINK.ASM 2 : Cannot open file (Include File "(p16f88.inc)" not found)
Error[113]   C:\PROGRAM FILES\GCBASIC\NOT GCBASIC FILES (ASSEMBLY CODED)\BILLINK.ASM 3 : Symbol not previously defined (_CONFIG1)
Error[126]   C:\PROGRAM FILES\GCBASIC\NOT GCBASIC FILES (ASSEMBLY CODED)\BILLINK.ASM 3 : Argument out of range (not a valid config register address)
Error[113]   C:\PROGRAM FILES\GCBASIC\NOT GCBASIC FILES (ASSEMBLY CODED)\BILLINK.ASM 5 : Symbol not previously defined (STATUS)
Error[113]   C:\PROGRAM FILES\GCBASIC\NOT GCBASIC FILES (ASSEMBLY CODED)\BILLINK.ASM 5 : Symbol not previously defined (RP0)
Error[113]   C:\PROGRAM FILES\GCBASIC\NOT GCBASIC FILES (ASSEMBLY CODED)\BILLINK.ASM 7 : Symbol not previously defined (OPTION_REG)
Error[113]   C:\PROGRAM FILES\GCBASIC\NOT GCBASIC FILES (ASSEMBLY CODED)\BILLINK.ASM 9 : Symbol not previously defined (TRISA)
Error[113]   C:\PROGRAM FILES\GCBASIC\NOT GCBASIC FILES (ASSEMBLY CODED)\BILLINK.ASM 10 : Symbol not previously defined (STATUS)
Error[113]   C:\PROGRAM FILES\GCBASIC\NOT GCBASIC FILES (ASSEMBLY CODED)\BILLINK.ASM 10 : Symbol not previously defined (RP0)
Error[113]   C:\PROGRAM FILES\GCBASIC\NOT GCBASIC FILES (ASSEMBLY CODED)\BILLINK.ASM 12 : Symbol not previously defined (PORTA)
Error[173]   C:\PROGRAM FILES\GCBASIC\NOT GCBASIC FILES (ASSEMBLY CODED)\BILLINK.ASM 15 : Source file path exceeds 62 characters (C:\PROGRAM FILES\GCBASIC\NOT GCBASIC FILES (ASSEMBLY CODED)\BILLINK.ASM)
Halting build on first failure as requested.
BUILD FAILED: Sat Jun 07 23:23:10 2008

Here's my copy of Bill's code again (I copied by hand from the PDF, so maybe I made I mistake?). I guess I did the brackets for the include wrong, or something?
Code:
list p=16f88
	include (p16f88.inc)
	__CONFIG _CONFIG1, 0x2F34
	org 0
	bsf STATUS, RP0
	movlw b'00001110'
	movwf OPTION_REG
	movlw b'00111111'
	movwf TRISA
	bcf STATUS, RP0
	movlw b'10000000'
	xorwf PORTA, f
	sleep
	end
 
Last edited:
I guess I did the brackets for the include wrong, or something?
Huh, those really are supposed to be greater and less than signs around the include! Fixed the "list" error and deleted the superfluous "config," but I'm still getting this:
Code:
Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p16F88 "billink.asm" /l"billink.lst" /e"billink.err"
Message[302] C:\PROGRAM FILES\GCBASIC\NOT GCBASIC FILES (ASSEMBLY CODED)\BILLINK.ASM 7 : Register in operand not in bank 0.  Ensure that bank bits are correct.
Message[302] C:\PROGRAM FILES\GCBASIC\NOT GCBASIC FILES (ASSEMBLY CODED)\BILLINK.ASM 9 : Register in operand not in bank 0.  Ensure that bank bits are correct.
Error[173]   C:\PROGRAM FILES\GCBASIC\NOT GCBASIC FILES (ASSEMBLY CODED)\BILLINK.ASM 15 : Source file path exceeds 62 characters (C:\PROGRAM FILES\GCBASIC\NOT GCBASIC FILES (ASSEMBLY CODED)\BILLINK.ASM)
Halting build on first failure as requested.
BUILD FAILED: Sat Jun 07 23:33:53 2008
Help!
 
Are you using the Wizard, if not then follow the posters instructions.

I've attached your code as my MPLAB sees it. You need to copy all the files into a directory called
C:\Internet PIC\

From MPLAB open workspace and locate C:\Internet PIC\HANK

Then hit Build All, then Animate...
 

Attachments

  • Hank.zip
    10.7 KB · Views: 124
Booya! Just moving the billink.asm file to another location to fix Error[173] sorted the rest out. The LED's blinking, and it only took me the better part of a day!

I wonder why I was having so much trouble making a .hex, but the Quickbuild function worked just fine? If there are two things I'd like to get out of this, it's:
1) How to get it to work without using Quickbuild;
2) The nitty-gritty of what's going on in Bill's program.

Thanks all!
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top