![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
..........
Last edited by Kyle-s4h; 6th January 2008 at 01:50 PM. |
|
|
|
|
|
|
(permalink) |
|
Thank you for buying the kits, PORTB pullups can be enabled on the 18F4550 by
Code:
bcf INTCON2,NOT_RBPU Whew, though I missed one... I'll try to post sample keypad code for the 4 pushbuttons and 4x4 keypad. Notice using the I2C option will preclude the use some pushbuttons. The 10K pullups are required for the I2C mode only; but they work fine with the pushbuttons too and RBPU will still function on the pins that need pullups. In the Unicorn manual (yes I'm working on it, I just released an updated Firefly manual today) you should remove U3 when working with the keypad (and don't press buttons when testing I2C or you could try to toggle in I2C data if you desire with the keypad...) PS not documented was the thin traces under U3 (24xxx), They can be cut if you want to use a DS1307 RTC (holes for 32KHz crystal and small battery provided on the PCB) This makes it similar to the much more expensive University of Toronto PIC demo board. ![]() This code is not ready for release but it works and will do the store demo on a 16x2 LCD mounted on Unicorn (install jumper on J1 for LCD contrast) It can also be tried on the OshonSoft simulator as in the screen capture above. Code:
list p=18F4550
include <p18F4550.inc>
CONFIG FOSC = INTOSC_HS, WDT = OFF, LVP = OFF, DEBUG = ON
CONFIG PBADEN = OFF, PLLDIV = 5
#define LCD_E LATE,2
#define LCD_RS LATE,0
#define LCD_RW LATE,1
#define LCD_BL LATB,3
#define LCD_DAT LATD
cblock 0 ; ram starts at 0x000
delay
temp
endc
org 0x000
nop
bra Init
; *** pad each entry to 16 characters db " <16> "
Text_ db .4,.5," Creatron Inc"
db .6,.7," 16x2 LCD "
db "blueroom ",.0,.1
db "electronics ",.2,.3
; *** 2x2 blueroomelectronics logo (house)
LCD_CC db .128,.128,.129,.131,.135,.143,.159,.159
db .128,.128,.128,.144,.152,.156,.158,.130
db .159,.159,.159,.145,.145,.145,.159,.128
db .130,.130,.158,.130,.130,.130,.158,.128
; *** 2x2 creatron logo (c)
db .128,.128,.135,.143,.156,.153,.154,.154
db .128,.128,.158,.159,.130,.152,.132,.128
db .154,.154,.153,.156,.143,.135,.128,.128
db .128,.132,.152,.130,.159,.158,.128,.128
Init clrf TBLPTRH ; table in first 256 bytes memory
movlw 0x0A
movwf ADCON1
movlw b'11110111'
movwf TRISB
clrf TRISD ; LCD Data output
clrf PORTE ; LCD Control
clrf TRISE
clrf LATE ; zero output on E
movlw b'00000010' ; use internal osc
movwf OSCCON ; 32KHz internal clock
;wait 15ms before using LCD
movlw .4 ; repeat sending 0x38 to reset LCD
movwf temp ; loop counter
_init3 movlw .50 ; 50ms delay
rcall dly1ms ;
bsf LCD_E ; LCD enable bit high
movlw 0x38 ; send 0x38 four times
movwf LCD_DAT ; LCD = 0x38 (8 bit mode x 2 line)
bcf LCD_E ; latches on High to Low transition
decfsz temp
bra _init3 ; repeat 3 times
; load special charaters into LCD RAM
movlw b'01000000' ; set LCD CG address to 00
rcall LCD_Ins ; relative call
clrf temp
movlw LCD_CC ; pointer to custom charater table
movwf TBLPTRL
_nextcc tblrd*+ ; get in-line string character
movf TABLAT,W ; last character
rcall LCD_Chr ; send the character into LCD RAM
incf temp
btfss temp, 6 ; 64 bytes total
bra _nextcc
Restart movlw Text_
movwf TBLPTRL ; point to first line of text
rcall Clr_LCD
movlw .9
movwf temp
_wait movlw .250
rcall dly1ms
decfsz temp
bra _wait
rcall Clr_LCD
movlw .9
movwf temp
_wait1 movlw .250
rcall dly1ms
decfsz temp
bra _wait1
bra Restart ; loop forever, if fail WDT restart
Clr_LCD movlw 0x01 ; clear display
rcall LCD_Ins
movlw 0x0C ; display on, cursor off
rcall LCD_Ins
bsf LCD_BL ; turn on backlight
movlw .16
movwf temp
_top tblrd*+ ; get in-line string character
movf TABLAT,W ; last character
rcall LCD_Chr
decfsz temp
bra _top
movlw 0xC0 ; set cursor to second line
rcall LCD_Ins
movlw .16
movwf temp
_bot tblrd*+ ; get in-line string character
movf TABLAT,W ; last character
rcall LCD_Chr
decfsz temp
bra _bot
return
; LCD entry routines watches busy flag
LCD_Chr bsf LCD_RS ; enable Charater mode
LCD_Ins bsf LCD_E
clrf TRISD ; make PORTD an output
movwf LCD_DAT ; put data on LCD port
bcf LCD_E ; latch byte to LCD
movlw 0xFF
bcf LCD_RS
movwf TRISD ; make LCD port input
bsf LCD_RW ; enter read mode
bsf LCD_E ; enable LCD
_BusyFl btfsc PORTD,7 ; wait for bit 7 to be pulled low
bra _BusyFl
bcf LCD_RW ; return to Instruction mode
clrwdt ; if no LCD program will lock up
return
dly1ms movwf delay ; enter with delay in ms via W
_loop1 bra $+2
bra $+2
clrwdt
decfsz delay
bra _loop1
return
END
Last edited by blueroomelectronics; 5th June 2007 at 04:07 PM. |
|
|
|
|
|
|
(permalink) |
|
Yep that's how the DS1307 connects, if you're not concerened with battery backup you can just put a 2.5V zener from +5 to the DS1307 battery pin. This will make it think it has a battery.
Q1 was an oops, I got lucky in it's only something used in the experimenter mode. I love the 18F series, the table stuff is really handy much better than retlw routines. Although the "tblrd*+" looks so strange. I've got some basic GLCD routines but nothing fancy, I'd love to do Conways game of life with it. The routines look similar to LCD routines but you get a hardware reset. |
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| help understanding this hbridge design.... | jaydag71 | Electronic Projects Design/Ideas/Reviews | 2 | 5th June 2007 10:37 PM |
| Further Understanding Datasheet Information | raphaelriv | General Electronics Chat | 2 | 16th May 2007 06:15 PM |
| Need help understanding formula | meriad | Math and Physics | 8 | 21st March 2007 09:37 AM |
| Understanding the 7805, et al | tab a | General Electronics Chat | 2 | 29th January 2007 07:24 PM |
| Understanding Ground | lawOf3 | General Electronics Chat | 2 | 19th September 2003 01:27 AM |