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.

Configuration Registers Mplab/Junebug

Status
Not open for further replies.

binzer

Member
I have a problem where I can run programs with the Mplab/Junebug combo but the Junebug tutor will not standalone. I know it's not the Junebug and is most likely not setting the correct config registers. If I set them in Mplab will that carry out to the pic when I program it? Is there a good tutorial on the config bits/bytes somewhere. I have done a bit of reading but have not gotten back to trying some of the things out. I did print out the 18F1320.inc file which has some info ( a bit confusing ) but did not find how to set the different clock speeds when using the internal rc osc. Thanks.:confused:
 
Turn DIP SW 1,2,3 off and the tutor is completely separated from the programmer.

As for the config settings my favorite defaults for MPASM are.
Code:
    list    p=18F1320
    include   <p18F1320.inc>
    CONFIG    OSC=INTIO2,WDT=OFF,LVP=OFF
That's a typical header and will select the internal oscillator (it defaults to 31.25kHz)

Code:
       movlw   0x62            ; 4MHz OSC
       movwf   OSCCON
And this will get it going at 4MHz, if you want 8MHz use 0x72

Perhaps I'll add this stuff to the Junebug manual.

PS remind me to run it through Pommies PIC code formatter next time :)
 
Last edited:
Ok, I added that to my little play program.
I compiled via Mplab in release mode, hit start and it runs.

If I switch off 1,2,3 then it still runs.

Power off, with switch 1,2,3 off, connect the power, this should run the program, correct??
I just can't get this to work, what am I doing wrong??

I will post the code here once I figure out how.

Thanks, Mike
 
Power off, with switch 1,2,3 off, connect the power, this should run the program, correct??
I just can't get this to work, what am I doing wrong??


Hi Mike,

To get your program to run stand alone you have to select the junebug as programmer - not debugger. When selected as a debugger it downloads the debug exec even if you select the release setting. It appears to be a bug in MPLAB.

Mike.
 
test code

Code:
; Blue2 Project

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

	LIST P=18F1320, F=INHX32 ;directive to define processor and file format

	#include <P18F1320.INC>	 ;processor specific variable definitions

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

;Configuration bits

;;   Oscillator Selection:

	 CONFIG OSC=INTIO2,LVP=OFF,WDT=OFF

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

;Variable definitions

;;

		cblock	0x01

		d1

		d2

		d3

		endc

;;

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

;Reset vector

RESET_VECTOR	CODE	0x0000

		goto	Main		;go to start of main code

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

;High priority interrupt vector

HI_INT_VECTOR	CODE	0x0008

		bra	HighInt		;go to high priority interrupt routine

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

;Low priority interrupt vector

LOW_INT_VECTOR	CODE	0x0018

		bra	LowInt		;go to low priority interrupt routine

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

;High priority interrupt routine

		CODE

HighInt:

;	*** high priority interrupt code goes here ***

		retfie	FAST

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

;Low priority interrupt routine

LowInt:

		retfie

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

;Start of main program

Main:

;

	clrf	LATB; clear output latch

	movlw	0x7f

	movwf	ADCON1; set port b for digital inputs

	bcf		INTCON2, RBPU ; turn on soft pullups

;

	movlw   0x02	;make sure osc is set            

    movwf   OSCCON

;

BURP:

	btfss	PORTB, RB0; check for button #1 pressed

	call BUTT1

	btfss	PORTB, RB2; check for button #2 pressed

	call BUTT2

	btfss	PORTB, RB5; check for button #3 pressed

	call BUTT3

	;

	goto BURP				

;

L1:

LED1 bcf TRISA,0 ; RA0 output

		bcf TRISA,6 ; RA6 output

		bsf TRISA,7 ; RA7 tristate (open)

		bsf LATA,0 ; RA6 High (5V)

		bcf LATA,6 ; RA7 Low (GND)

		call DubDelay

		return

L2:

LED2 bcf TRISA,0 ; RA0 output

		bcf TRISA,6 ; RA6 output

		bsf TRISA,7 ; RA7 tristate (open)

		bcf LATA,0 ; RA6 Low (GND)

		bsf LATA,6 ; RA7 High (5V)

		call DubDelay	

		return

L3:

LED3 bsf TRISA,0 ; RA0 tristate (open)

		bcf TRISA,6 ; RA6 output

		bcf TRISA,7 ; RA7 output

		bsf LATA,6 ; RA6 High (5V)

		bcf LATA,7 ; RA7 Low (GND)

		call DubDelay

		return

L4:

LED4 bsf TRISA,0 ; RA0 tristate (open)

		bcf TRISA,6 ; RA6 output

		bcf TRISA,7 ; RA7 output

		bcf LATA,6 ; RA6 Low (GND)

		bsf LATA,7 ; RA7 High (5V)

		call DubDelay	

		return

L5:

LED5 bcf TRISA,0 ; RA0 output

		bsf TRISA,6 ; RA6 tristate (open)

		bcf TRISA,7 ; RA7 output

		bcf LATA,0 ; RA0 Low (GND)

		bsf LATA,7 ; RA7 High (5V)

		call DubDelay

		return

L6:

LED6 bcf TRISA,0 ; RA0 output

		bsf TRISA,6 ; RA6 tristate (open)

		bcf TRISA,7 ; RA7 output

		bsf LATA,0 ; RA7 High (5V)

		bcf LATA,7 ; RA6 Low (GND)

		call DubDelay

		;

		return

		;bra LED1 ; repeat

		bra Main

;;		END

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

DubDelay

		movlw	0x50

		movwf	d1

		movlw	0x50

		movwf	d2

Del_1

		decfsz	d1, f

		goto $+4

		decfsz	d2, f

		goto Del_1

 		goto $+2

		nop

		return

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

;

BUTT1

	movlw	0x03

	movwf	d3

B11

	call L1

	call L2

	call L3

	call L4

	call L5

	call L6

	decfsz	d3, f

	goto B11

		bsf TRISA,0

		bsf TRISA,6

		bsf TRISA,7

	return

BUTT2

	movlw	0x03

	movwf	d3

B22

	call L1

	call L2

	call L3

	call L4

	call L5

	call L6

	call L5

	call L4

	call L3

	call L2

	decfsz	d3, f

	goto B22

		bsf TRISA,0

		bsf TRISA,6

		bsf TRISA,7

	return

BUTT3

	movlw	0x03

	movwf	d3

B33

	call L3

	call L4

	decfsz	d3, f

	goto B33

		bsf TRISA,0

		bsf TRISA,6

		bsf TRISA,7

;

	movlw	0x03

	movwf	d3

B34

	call L2

	call L5

	decfsz	d3, f

	goto B34

		bsf TRISA,0

		bsf TRISA,6

		bsf TRISA,7

;

	movlw	0x03

	movwf	d3

B35

	call L1

	call L6

	decfsz	d3, f

	goto B35

		bsf TRISA,0

		bsf TRISA,6

		bsf TRISA,7

	return

	

		END
 

Attachments

  • LedTest2.asm
    4.2 KB · Views: 141
Why not something more like this:
Code:
; Blue2 Project
	LIST P=18F1320
	#include <P18F1320.INC>
	CONFIG OSC=INTIO2,LVP=OFF,WDT=OFF

	cblock	0x01
	d1,d2,d3
	endc

	org	0x0000
Main	clrf	LATB		;clear output latch
	movlw	0x7f
	movwf	ADCON1		;set port b for digital inputs
	bcf	INTCON2,RBPU	;turn on soft pullups
	movlw	0x02		;make sure osc is set            
	movwf	OSCCON
BURP	btfss	PORTB,RB0	;check for button #1 pressed
	call	BUTT1
	btfss	PORTB,RB2	;check for button #2 pressed
	call	BUTT2
	btfss	PORTB,RB5	;check for button #3 pressed
	call	BUTT3
	goto	BURP				
L1
LED1	bcf	TRISA,0		;RA0 output
	bcf	TRISA,6		;RA6 output
	bsf	TRISA,7		;RA7 tristate (open)
	bsf	LATA,0		;RA6 High (5V)
	bcf	LATA,6		;RA7 Low (GND)
	call	DubDelay
	return
L2
LED2	bcf	TRISA,0		;RA0 output
	bcf	TRISA,6		;RA6 output
	bsf	TRISA,7		;RA7 tristate (open)
	bcf	LATA,0		;RA6 Low (GND)
	bsf	LATA,6		;RA7 High (5V)
	call	DubDelay	
	return
L3
LED3	bsf	TRISA,0		;RA0 tristate (open)
	bcf	TRISA,6		;RA6 output
	bcf	TRISA,7		;RA7 output
	bsf	LATA,6		;RA6 High (5V)
	bcf	LATA,7		;RA7 Low (GND)
	call	DubDelay
	return
L4
LED4	bsf	TRISA,0		;RA0 tristate (open)
	bcf	TRISA,6		;RA6 output
	bcf	TRISA,7		;RA7 output
	bcf	LATA,6		;RA6 Low (GND)
	bsf	LATA,7		;RA7 High (5V)
	call	DubDelay	
	return
L5
LED5	bcf	TRISA,0		;RA0 output
	bsf	TRISA,6		;RA6 tristate (open)
	bcf	TRISA,7		;RA7 output
	bcf	LATA,0		;RA0 Low (GND)
	bsf	LATA,7		;RA7 High (5V)
	call	DubDelay
	return
L6
LED6	bcf	TRISA,0		;RA0 output
	bsf	TRISA,6		;RA6 tristate (open)
	bcf	TRISA,7		;RA7 output
	bsf	LATA,0		;RA7 High (5V)
	bcf	LATA,7		;RA6 Low (GND)
	call	DubDelay
	return
	;bra	LED1		;repeat
	bra	Main

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

DubDelay
	movlw	0x50
	movwf	d1
	movlw	0x50
	movwf	d2
Del_1	decfsz	d1, f
	goto	$+4
	decfsz	d2, f
	goto	Del_1
	goto	$+2
	nop
	return

BUTT1	movlw	0x03
	movwf	d3
B11	call	L1
	call	L2
	call	L3
	call	L4
	call	L5
	call	L6
	decfsz	d3, f
	goto	B11
	bsf	TRISA,0
	bsf	TRISA,6
	bsf	TRISA,7
	return

BUTT2	movlw	0x03
	movwf	d3
B22	call	L1
	call	L2
	call	L3
	call	L4
	call	L5
	call	L6
	call	L5
	call	L4
	call	L3
	call	L2
	decfsz	d3, f
	goto	B22
	bsf	TRISA,0
	bsf	TRISA,6
	bsf	TRISA,7
	return

BUTT3	movlw	0x03
	movwf	d3
B33	call	L3
	call	L4
	decfsz	d3, f
	goto	B33
	bsf	TRISA,0
	bsf	TRISA,6
	bsf	TRISA,7
	movlw	0x03
	movwf	d3
B34	call	L2
	call	L5
	decfsz	d3, f
	goto	B34
	bsf	TRISA,0
	bsf	TRISA,6
	bsf	TRISA,7
	movlw	0x03
	movwf	d3
B35	call	L1
	call	L6
	decfsz	d3, f
	goto	B35
	bsf	TRISA,0
	bsf	TRISA,6
	bsf	TRISA,7
	return

	end
Much more readable and easier to work with, IMHO. :) The more code you can see on screen at one time the better. Makes it easier to follow things.

The double labels are weird and unnecessary too, but perfectly legal. Colons are not necessary on labels in this assembler.
 
Last edited:
Why not something more like this:

Much more readable and easier to work with, IMHO. :)

I agree, sometimes less is more.:D

Binzer, did you see my earlier post? We posted at the same time and so you may have missed it.

Mike.
 
Actually it's not double spaced, not sure why it came out that way. It may not be efficient code, but I'm still getting back to it and learning by adding more stuff and doing things in different ways.

I did not see the post just after mine as I decided to crash, need a little sleep as I have work today also.
I'll go back and check me Mplab settings.

Thanks
 
Hi Mike,
To get your program to run stand alone you have to select the junebug as programmer - not debugger. When selected as a debugger it downloads the debug exec even if you select the release setting. It appears to be a bug in MPLAB.
Mike.

Great!! That was the problem. I wonder if it sets by itself when you select the programmer..

Thanks, Mike
 
I've added the header stuff to the manual, perhaps a debug / release note might be useful too.

How about the OSCON bits also??

;; Use the following to set Oscillator speed in your program
;
; movlw 0x?? ; where ? is from the following table
; movwf osccon;
;0x72=8mhz
;0x62=4mhz
;0x52=2mhz
;0x42=1mhz
;0x32=500khz
;0x22=250khz
;0x12=125khz
;0x02=31khz
;
;******************************************************************************
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top