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.

Junebug PORTB header mod

Status
Not open for further replies.

futz

Active Member
After getting my LCD working on Junebug, I started thinking of ways to make it useful for something other than displaying the usual demo stuff. First thing I thought of was to display VR1 and VR2 values. Of course that's impossible because the LCD is using the RA1 and RA3 pins.

It became obvious that it would be best if the LCD could move to PortB. I went over the board and schematic and realized that to get all the PortB pins to the LCD would mean a rat's nest of wiring. PortB is scattered all over the Junebug board, and RB0, 2 and 5 aren't brought out to a connector at all.

So I thought to myself, "Self, wouldn't it be nice if PortB was pinned out all in one place? Hey! I think I'll do that!" :D

So I added a PortB connector, bringing all the easily useful PortB pins (0 - 6) to it. Here's some pics of the project:

**broken link removed**
**broken link removed**
**broken link removed**
**broken link removed**
**broken link removed**
**broken link removed**
**broken link removed**

The hot-melt glue over the connector is just for extra insurance. The connector was squished into hot-melt and was nice and strong already.

I made a minor mistake (thinking upside down) and built it with pin 0 on the left instead of where it should be, on the right. If I was to do it again I would fix that so the pin order corresponds to where the bits are in PORTB. Ah well, no big deal. Just plug it in upside down. :eek:

Another thing I should have done was put 5V and ground on the connector. By the time I thought of it I was half done. Next time...

Here's **broken link removed** for a quicky test program that just cycles thru the pins, turning each one on for 2 seconds and off for 2 seconds. Good for putting a meter on each pin to be sure you got it right. LED #1 lights when pin 0 is high.

One gotcha is that you have to solder to the correct pin on the switches. Looking at the bottom of the board, only the right pin is connected.

While using the header don't forget that the buttons will probably cause trouble if you push them while using the pins for something else. Your software and/or outboard hardware may not appreciate this.

I haven't connected up my LCD and rewritten my code yet. Maybe tomorrow night.
 
Hehehe! Just now finished modding my LCD code to run on PORTB. Had some trouble getting it to go at first. I was trying to iorwf the values into LATB, but that wouldn't work for some reason. Tried iorwf'ing into PORTB. That didn't work. Finally realized that there was actually no reason to preserve the other bits and just switched to movwf and away she went!

Tomorrow the VR1 and VR2, she gets displayed! :p
 
I think I missed a trick when I ordered my JuneBug. I should have ordered the EasyLab at the same time.
 
3v0 said:
You are to point where I would be adding a target board rather then make that many mods to the JuneBug. Not that you are wrong to do so.
Heh. I've always modded my computers, right from the first ones I had (TRS-80 Color Computer and Model III). Microcontroller boards are no different. :D
 
Last edited:
I'll have to get some stock of the BT-04 Cases, only places that sell them anywhere are the same places on my where to order page. They should be available on the Creatron Electronics eBay site soon.
I know the LAB-EASY fellow and I think the cases are pretty neat for prototyping, cheaper than the Hammond 1591-B case my other kits use.
**broken link removed**

Edit: yep ADCON1 does the trick, no comparators to worry about on the 18F1320.
 
Actually I have thought of another question, is there a connector that "clips" on top of the IC rather than having to solder connectors to the board.
 
UTMonkey said:
Hope I am not stealing the thread here by asking this, what is a "Target Board"?

In the world of logic analyizers/emulators and processor probes the target board is the board under test. Although we are using an ICD we still refer to the users board as the target.

Actually I have thought of another question, is there a connector that "clips" on top of the IC rather than having to solder connectors to the board.
There must be commerical clips for doing so. For dip chips you can make one by soldering wires to a DIP clip.

**broken link removed**
 
futz said:
Tomorrow the VR1 and VR2, she gets displayed! :p
Ya! I happy with that. :D
Code:
	list	p=18F1320
	include	<p18F1320.inc>
	CONFIG	OSC=INTIO2,WDT=OFF,MCLRE=ON,LVP=OFF

	cblock	0x00
		d1,d2,d3,dataout,temp,dec1,dec2,vr1,vr2
	endc

	org	0x0000
init	bsf	OSCCON,IRCF2	;set to 8MHz clock
	bsf	OSCCON,IRCF1
	bsf	OSCCON,IRCF0
	movlw	b'00001010'
	movwf	TRISA
	clrf	TRISB
	clrf	LATA
	clrf	LATB
	call	dl_40ms		;allow lcd to settle before init
	call	lcdinit		;init lcd
	movlw	b'01110101'	;init a/d
	movwf	ADCON1
	movlw	b'00011101'
	movwf	ADCON2

main	movlw	HIGH table1	;display table1
	movwf	TBLPTRH
	movlw	LOW table1
	movwf	TBLPTRL
oneloop	tblrd	*+
	movf	TABLAT,W
	xorlw	0x00		;zero?
	btfsc	STATUS,Z
	goto	print1		;yes, done
	movwf	dataout		;no, go again
	call	lcdchar
	goto	oneloop
print1	call	analog
	movf	vr1,W
	call	fixhex
	movff	dec1,dataout
	call	lcdchar
	movff	dec2,dataout
	call	lcdchar

	call	lcd_line2
linetwo	movlw	HIGH table2	;display table2
	movwf	TBLPTRH
	movlw	LOW table2
	movwf	TBLPTRL
twoloop	tblrd	*+
	movf	TABLAT,W
	xorlw	0x00		;zero?
	btfsc	STATUS,Z
	goto	print2		;yes, done
	movwf	dataout		;no, go again
	call	lcdchar
	goto	twoloop
print2	movf	vr2,W
	call	fixhex
	movff	dec1,dataout
	call	lcdchar
	movff	dec2,dataout
	call	lcdchar
	call	delay
	call	lcd_line1
	goto	main

table1	db	"VR1 - $",0x00
table2	db	"VR2 - $",0x00

analog	movlw	b'00000101'	;enable a/d - an1
	movwf	ADCON0
	bsf	ADCON0,GO	;go do a/d conversion
adloop	btfsc	ADCON0,DONE
	goto	adloop
	movff	ADRESH,vr1	;store in vr1
	movlw	b'00001101'	;enable a/d - an3
	movwf	ADCON0
	bsf	ADCON0,GO	;go do a/d conversion
adloop2	btfsc	ADCON0,DONE
	goto	adloop2
	movff	ADRESH,vr2	;store in vr2
	return

;*****************************************************************
; fixhex - subroutine takes byte passed in W - splits it into two
; ascii bytes representing hex digits and stores them in dec1/dec2
fhex	db	"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"
fixhex	movwf	temp		;store it for later
	movwf	dec1		;and put it in dec1 too
	movlw	0xf0		;mask out low nybble
	andwf	dec1
	swapf	dec1,F		;swap nybbles
	movlw	HIGH fhex	;set up table pointer
	movwf	TBLPTRH
	movlw	LOW fhex
	movwf	TBLPTRL
	movf	dec1,W
	addwf	TBLPTRL		;add offset
	btfsc	STATUS,C	;was there a carry?
	incf	TBLPTRH,F	;yes, increment table pointer MSB
	tblrd	*			;read the byte
	movff	TABLAT,dec1	;store it in dec1
fixhx2	movlw	0x0f		;mask out high nybble
	andwf	temp,F
	movlw	HIGH fhex	;set up table pointer
	movwf	TBLPTRH
	movlw	LOW fhex
	movwf	TBLPTRL
	movf	temp,W
	addwf	TBLPTRL		;add offset
	btfsc	STATUS,C	;was there a carry?
	incf	TBLPTRH,F	;yes, increment table pointer MSB
	tblrd	*		;read the byte
	movff	TABLAT,dec2
	return

lcd_line1
	movlw	0x80
	movwf	dataout
	call	lcdcmd
	return

lcd_line2
	movlw	0xc0
	movwf	dataout
	call	lcdcmd
	return

lcdcmd	swapf	dataout,W	;swap nybbles and transfer to w
	andlw	0x0f		;mask out high nybble
	movwf	temp		;rotate left 2 bits for B2-B5
	rlncf	temp,F
	rlncf	temp,W
	movwf	LATB		;move to PORTB
	call	e_togg		;latch the data
	movf	dataout,W	;get byte in w again
	andlw	0x0f		;and mask out high nybble
	movwf	temp		;rotate data into position
	rlncf	temp,F
	rlncf	temp,W
	movwf	LATB		;move to PORTB
	call	e_togg		;latch the data
	call	dl_50us
	return

lcdchar	swapf	dataout,W	;swap nybbles and transfer to w
	andlw	0x0f		;mask out high nybble
	movwf	temp		;rotate data into position
	rlncf	temp,F
	rlncf	temp,W
	movwf	LATB		;move to PORTB
	bsf	LATB,0		;set RS high
	call	e_togg		;latch the data
	movf	dataout,w	;get byte in w again
	andlw	0x0f		;and mask out high nybble
	movwf	temp		;rotate data into position
	rlncf	temp,F
	rlncf	temp,W
	movwf	LATB		;move to PORTB
	bsf	LATB,0		;RS high
	call	e_togg		;latch the data
	call	dl_50us
	return

e_togg	bsf	LATB,1		;toggle E to latch data
	nop			;delay 450ns minimum
	nop
	nop
	bcf	LATB,1
	return

lcdinit	movlw	b'00001100'	;send 03 nybble
	movwf	LATB
	call	e_togg
	call	dl_05ms		;wait 5ms
	movlw	b'00001100'	;send 3 second time
	movwf	LATB
	call	e_togg
	call	dl_160us	;wait 160us
	movlw	b'00001100'	;send 3 third time
	movwf	LATB
	call	e_togg
	call	dl_160us	;wait 160us
	movlw	b'00001000'	;enable 4-bit mode ($02 nybble)
	movwf	LATB
	call	e_togg
	call	dl_50us		;wait 50us
	movlw	0x28		;set 4-bit mode and 2-lines
	movwf	dataout
	call	lcdcmd
	call	dl_50us		;wait 50us
	movlw	0x10		;cursor move & shift left
	movwf	dataout
	call	lcdcmd
	call	dl_50us		;wait 50us
	movlw	0x06		;entry mode = increment
	movwf	dataout
	call	lcdcmd
	call	dl_50us		;wait 50us
	movlw	0x0d		;display on, cursor on, blink on
	movwf	dataout
	call	lcdcmd
	call	dl_50us		;wait 50us
	movlw	0x01		;clear display
	movwf	dataout
	call	lcdcmd
	call	dl_05ms		;wait 5ms
	return

dl_40ms	movlw	0x7e		;40ms delay
	movwf	d1
	movlw	0x3f
	movwf	d2
dl40_0	decfsz	d1,F
	goto	$+6
	decfsz	d2,F
	goto	dl40_0
	nop
	return

dl_05ms	movlw	0xce		;5ms delay
	movwf	d1
	movlw	0x08
	movwf	d2
dl05_0	decfsz	d1,F
	goto	$+6
	decfsz	d2,F
	goto	dl05_0
	return

dl_160us			;160us delay
	movlw	0x69
	movwf	d1
dl160_0	decfsz	d1,F
	goto	dl160_0
	return

dl_50us	movlw	0x1f		;50us delay
	movwf	d1
dl50_0	decfsz	d1,F
	goto	dl50_0
	return

delay	movlw	0x5e		;.15 second delay
	movwf	d1
	movlw	0xeb
	movwf	d2
delay_0	decfsz	d1,F
	goto	$+6
	decfsz	d2,F
	goto	delay_0
	return

	end
 
futz said:
Heh. I've always modded my computers, right from the first ones I had (TRS-80 Color Computer and Model III). Microcontroller boards are no different. :D

Unless I am routing power I use wire wrap wire for mods. The small diameter makes it easy to manage and it looks better. Much of the rework on commerical boards use it.
 
3v0 said:
Unless I am routing power I use wire wrap wire for mods. The small diameter makes it easy to manage and it looks better. Much of the rework on commerical boards use it.
Ya. That would be the best way to do it probably. I don't have any, so I used what I have. :)

Being in construction (plumbing & heating), I often pick up scrap phone wire from jobsites. I have several dozen lifetimes supply of 22 or 24 gauge (whatever it is) copper wire. The insulation is too melty to make good jumpers (thus the heat shrink insulation), but it makes good breadboard wires.
 
Ok you all knew this was coming ... Thing is my own version of the portB mod but its a all pin mod. No junebug soldering. Simple to make. I havent made it in reality but i did it in 3d Studio Max. I hope you enjoy it!

Board Layout: (basic layout, you can guess how this works really)
Top Board and Bottom Board just make one bigger than the other and make the bottom 1 without the outer holes. So its only 2 rows on board 2:

**broken link removed**

Some shots of it:

Front:
**broken link removed**

Side:
**broken link removed**

Top:
**broken link removed**

Angle:
**broken link removed**
 
of course there are only 18 pins for junebug 18f1320 but this might be useful for other things also so ill leave it as a 2 x10 (20pin) Also i ordered a few sets of single row pin headers they should be here tuesday. When i make it ill take some pictures of course.
 
Have you considered simplifying the design a bit by using a machined pin socket with longer solder tail pins? This might allow for a single PCB in your adapter design.

Mike

**broken link removed**
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top