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 13th December 2007, 04:48 AM   #1
Default Junebug PORTB header mod

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!"

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

Notes & prefabbed connector
Prefabbed connector
Bottom side
Glue gun
Bottom closeup
Top side
Top side closeup

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.

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 asm source 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.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is online now  
Old 13th December 2007, 05:13 AM   #2
Default

Well you'll like the bigger PICs, the Unicorn PCB should be interesting as it's almost all I/O.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Old 13th December 2007, 05:18 AM   #3
Default

Quote:
Originally Posted by blueroomelectronics
Well you'll like the bigger PICs, the Unicorn PCB should be interesting as it's almost all I/O.
I actually have quite a few bigger PICs. I just like messing around with the little ones.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is online now  
Old 14th December 2007, 09:20 AM   #4
Default

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!
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is online now  
Old 14th December 2007, 09:57 AM   #5
Default

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.
3v0 is offline  
Old 14th December 2007, 02:58 PM   #6
Default

Don't forget to make port B digital I forget that it has analog pins sometimes.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Old 14th December 2007, 04:40 PM   #7
Default

I think I missed a trick when I ordered my JuneBug. I should have ordered the EasyLab at the same time.
UTMonkey is offline  
Old 14th December 2007, 04:42 PM   #8
Default

Quote:
Originally Posted by 3v0
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.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 15th December 2007 at 09:13 AM.
futz is online now  
Old 14th December 2007, 04:42 PM   #9
Default

Quote:
Originally Posted by blueroomelectronics
Don't forget to make port B digital I forget that it has analog pins sometimes.
Done. It's all in ADCON1, right?
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is online now  
Old 14th December 2007, 04:44 PM   #10
Default

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.
http://www.blueroomelectronics.com/buynow.htm

Edit: yep ADCON1 does the trick, no comparators to worry about on the 18F1320.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Old 14th December 2007, 07:39 PM   #11
Default

Hope I am not stealing the thread here by asking this, what is a "Target Board"?
UTMonkey is offline  
Old 14th December 2007, 07:45 PM   #12
Default

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 is offline  
Old 14th December 2007, 08:16 PM   #13
Default

Quote:
Originally Posted by UTMonkey
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.

Quote:
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.

3v0 is offline  
Old 15th December 2007, 09:27 AM   #14
Default

Quote:
Originally Posted by futz
Tomorrow the VR1 and VR2, she gets displayed!
Ya! I happy with that.
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's Microcontrollers & Robotics
=========================
futz is online now  
Old 23rd December 2007, 09:52 PM   #15
Default

Quote:
Originally Posted by futz
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.
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 is offline  
Reply

Tags
header, junebug, mod, portb

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
Problem with LCD code? spondootre Micro Controllers 15 29th April 2008 10:15 AM
PIC PWM outputs? Andy1845c Micro Controllers 33 30th November 2007 04:06 AM
RB0 External Interrupt Problem Suraj143 Micro Controllers 6 30th August 2007 07:26 AM
DS1302 with PIC16f877 program RasCreationKing Micro Controllers 28 3rd May 2007 01:03 PM
Validating Code Without PIC burg Micro Controllers 4 22nd April 2007 05:14 PM



All times are GMT. The time now is 02:09 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker