![]() | ![]() | ![]() |
| | #1 |
|
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 ========================= | |
| |
| | #2 |
|
Well you'll like the bigger PICs, the Unicorn PCB should be interesting as it's almost all I/O.
| |
| |
| | #3 | |
| Quote:
__________________ ========================= Futz's Microcontrollers & Robotics ========================= | ||
| |
| | #4 |
|
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 ========================= | |
| |
| | #5 |
|
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.
| |
| |
| | #6 |
|
Don't forget to make port B digital I forget that it has analog pins sometimes.
| |
| |
| | #7 |
|
I think I missed a trick when I ordered my JuneBug. I should have ordered the EasyLab at the same time.
| |
| |
| | #8 | |
| Quote:
__________________ ========================= Futz's Microcontrollers & Robotics ========================= Last edited by futz; 15th December 2007 at 09:13 AM. | ||
| |
| | #9 | |
| Quote:
__________________ ========================= Futz's Microcontrollers & Robotics ========================= | ||
| |
| | #10 |
|
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. | |
| |
| | #11 |
|
Hope I am not stealing the thread here by asking this, what is a "Target Board"?
| |
| |
| | #12 |
|
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.
| |
| |
| | #13 | ||
| Quote:
Quote:
| |||
| |
| | #14 | |
| Quote:
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 ========================= | ||
| |
| | #15 | |
| Quote:
| ||
| |
|
| 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 |