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 9th June 2008, 03:01 AM   #31
Default

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!
Hank Fletcher is offline  
Old 9th June 2008, 03:05 AM   #32
Default

Quote:
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 by Hank Fletcher; 9th June 2008 at 03:05 AM.
Hank Fletcher is offline  
Old 9th June 2008, 03:05 AM   #33
Default

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.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/

Last edited by blueroomelectronics; 9th June 2008 at 03:07 AM.
blueroomelectronics is offline  
Old 9th June 2008, 03:09 AM   #34
Default

Quote:
PS try using your ICD2 as a debugger. You can see exactly what it's doing that way.
I'm ashamed to say I don't know how to do that. I know that's embarrassing!
Hank Fletcher is offline  
Old 9th June 2008, 03:13 AM   #35
Default

Quote:
Post your .hex file that doesn't work.
Can I view that in MPLAB, and if so, how?

Last edited by Hank Fletcher; 9th June 2008 at 03:18 AM.
Hank Fletcher is offline  
Old 9th June 2008, 03:26 AM   #36
Default

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 by Hank Fletcher; 9th June 2008 at 03:28 AM.
Hank Fletcher is offline  
Old 9th June 2008, 03:34 AM   #37
Default

Quote:
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!
Hank Fletcher is offline  
Old 9th June 2008, 03:34 AM   #38
Default

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...
Attached Files
File Type: zip Hank.zip (10.7 KB, 8 views)
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Old 9th June 2008, 03:42 AM   #39
Default

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 by Hank Fletcher; 9th June 2008 at 03:44 AM.
Hank Fletcher is offline  
Old 9th June 2008, 03:47 AM   #40
Default

It sounds like you've got the wrong toolsuite setup, the wizard helps sort that out when you use it.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Old 9th June 2008, 03:49 AM   #41
Default

Quote:
...if not then follow the posters instructions.
Whoops, I guess I didn't read the fine (and sideways) print carefully enough. Still, is there a typo with the extra config in the 16f88 example? Also, with respect to the "list" error, it's never been obvious to me until today how picky MPLAB was about indentation.
Hank Fletcher is offline  
Old 9th June 2008, 03:53 AM   #42
Default

No, wait, I was wrong about any superfluous "config." It's in the program I'm running now, and it's doing fine.

?! I must have missed something. I see the list is where it ought to be with respect to the rest of the code in Bill's poster, I must have copied it wrong somewhere, or I just didn't appreciate the significance of indenting the entire program.
Hank Fletcher is offline  
Old 9th June 2008, 03:55 AM   #43
Default

Code:
list p=16F88
include <p16F88.inc>
__CONFIG _CONFIG1, 0x2F34
Do you mean the _CONFIG1 ? It's supposed to be there, the 16F88 has more than one CONFIG group. Some 18F PICs have 8!
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Old 9th June 2008, 03:55 AM   #44
Default

Is the 16f88 running at 8MHz in Bill's program? How can I know that?
Hank Fletcher is offline  
Old 9th June 2008, 03:56 AM   #45
Default

Quote:
Do you mean the _CONFIG1 ?
Yeah, I did, but clearly that was my noobiness mistake.
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:58 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker