![]() | ![]() | ![]() |
| | |||||||
| 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) |
| Experienced Member | Here's working code that was designed for the Unicorn in LCD mode (it also works with Oshonsofts 18F & LCD simulator) It will be part of the Unicorn assembly manual. PS anyone have any decent asm formatters for posting? ![]() Code: list p=18F4550
include <p18F4550.inc>
CONFIG FOSC = INTOSC_HS, WDT = OFF, LVP = OFF, PBADEN = OFF
#define LCD_E LATE,2
#define LCD_RS LATE,0
#define LCD_RW LATE,1
#define LCD_BL LATB,3
delay equ 0
temp equ 1
org 0x000
movlw HIGH LCD_CC ; high byte
movwf TBLPTRH ; pointer to table high order byte
setf ADCON1 ; all I/O digital
bcf TRISB, 3 ; LCD backlight control
clrf TRISD ; LCD data output
clrf PORTE ; LCD control
clrf TRISE
clrf LATE ; zero output on E
movlw 0x02 ; use internal osc
movwf OSCCON ; 31.25KHz internal clock
; LCD soft reset (ignores/enables busy flag polling)
movlw .3 ; repeat sending 0x38 to reset LCD
movwf temp ; loop counter
_init3 movlw .131 ; 50ms delay
movwf delay ; enter with delay in ms via W
decfsz delay
bra $-2
bsf LCD_E ; LCD enable bit high
movlw 0x38 ; send 0x38 four times
movwf LATD ; LCD = 0x38 (8 bit mode x 2 line)
bcf LCD_E ; latches on High to Low transition
decfsz temp
bra _init3 ; repeat 3 times
bsf LCD_BL ; turn on backlight
; load special charaters into LCD RAM using LCD busy flag
movlw b'01000000' ; set LCD CG address to 00
rcall LCD_Ins ; relative call
clrf temp
movlw LOW 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
; clear & enable LCD DRAM, no visible cursor
movlw 0x0C ; display on, cursor off
rcall LCD_Ins
; display top 16 characters
movlw 0x01 ; clear display, home cursor
rcall LCD_Ins
movlw .16
movwf temp
movlw LOW Text_ ; low byte pointer
movwf TBLPTRL ; point to first line of text
_top tblrd*+ ; get in-line string character
movf TABLAT,W ; last character
rcall LCD_Chr
decfsz temp
bra _top
; display bottom 16 characters
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
bra $ ; endless loop done
; 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 LATD ; put data on LCD port
bcf LCD_E ; latch byte to LCD
bcf LCD_RS
setf 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
return
; text to display
org 0x0800
Text_ 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
END Last edited by blueroomelectronics; 2nd December 2007 at 07:35 PM. |
| | |
| | (permalink) |
| Experienced Member | Do you still have Just BASIC installed on your system? If so, I'll send you a "formatter" program I wrote that inputs an ASM file or a C file and outputs it to a console window with space characters in place of the tab characters. Just select and copy text from the console window and paste it between code tags in your posts. Here's "before" and "after" examples; Code: ;******************************************************************
;* *
;* ScanPad, 4x4 Keypad Mike McLaren, K8LH, Nov'07 *
;* *
;* RB3 RB2 RB1 RB0 <> requires PORTB weak pull-ups *
;* RB4 [0] [1] [2] [3] <> returns Z=0 for a "new" key only *
;* RB5 [4] [5] [6] [7] <> returns Z=1 when no keys pressed *
;* RB6 [8] [9] [A] [b] or if same key is still pressed *
;* RB7 [C] [D] [E] [F] <> isochronous (77 cycles) *
;* *
;* the Keylat key state latch contains pressed key value 80..8F *
;* or 0 (no key pressed). clear Keylat after getting a new key *
;* from ScanPad for "repeat key" operation (see example). *
;* *
;* 26 words, 77 instruction cycles (isochronous) *
;* *
ScanPad
movlw TRISB ; address of TRISB in bank 1 |B0
movwf FSR ; setup indirect access |B0
movlw b'11110111' ; setup column 0 (RB3) as output |B0
movwf INDF ; pseudo "movwf TRISB" |B0
clrf Column ; set keypad column offset = 0 |B0
movlw 0 ; clear W |B0
setc ; must shift 1 bits into TRISB |B0 Code: ;******************************************************************
;* *
;* ScanPad, 4x4 Keypad Mike McLaren, K8LH, Nov'07 *
;* *
;* RB3 RB2 RB1 RB0 <> requires PORTB weak pull-ups *
;* RB4 [0] [1] [2] [3] <> returns Z=0 for a "new" key only *
;* RB5 [4] [5] [6] [7] <> returns Z=1 when no keys pressed *
;* RB6 [8] [9] [A] [b] or if same key is still pressed *
;* RB7 [C] [D] [E] [F] <> isochronous (77 cycles) *
;* *
;* the Keylat key state latch contains pressed key value 80..8F *
;* or 0 (no key pressed). clear Keylat after getting a new key *
;* from ScanPad for "repeat key" operation (see example). *
;* *
;* 26 words, 77 instruction cycles (isochronous) *
;* *
ScanPad
movlw TRISB ; address of TRISB in bank 1 |B0
movwf FSR ; setup indirect access |B0
movlw b'11110111' ; setup column 0 (RB3) as output |B0
movwf INDF ; pseudo "movwf TRISB" |B0
clrf Column ; set keypad column offset = 0 |B0
movlw 0 ; clear W |B0
setc ; must shift 1 bits into TRISB |B0 Last edited by Mike, K8LH; 2nd December 2007 at 08:54 PM. |
| | |
| | (permalink) |
| Experienced Member | Here's the "Forum Code-Tag-Fix" program that I mentioned in the previous post for those who may be interested. It's written in Just BASIC, a free BASIC interpreter... Code: '
' Forum Code-Tag-Fix v1.1 by Mike McLaren, K8LH
'
' replaces <tab> characters with spaces (tabs = 8). adds
' an additional space character to lines beginning with a
' space for Microchip Forum. does not alter source file.
'
' Instructions
'
' 1 - select your source file from the File Dialog
' 2 - select output text displayed in console window
' 3 - copy to clipboard using <ctrl-C> or <edit> <copy>
' 4 - paste between code tags in your Forum post
'
' JustBASIC v1.01
'
tabs = 8 ' 8 (assembly) or 4 (C)
postmode = 0 ' 1, replace tabs, add leading space
' 0, replace tabs only
filedialog "Source File?", "*.asm", fileName$
if fileName$ <> "" then
open fileName$ for input as #f
while eof(#f) > -1
line input #f, aLine$ : hpos=1
if postmode then
if (left$(aLine$,1)=" ") then print " ";
if (left$(aLine$,1)=chr$(9)) then print " ";
end if
for x = 1 to len(aLine$)
if (mid$(aLine$,x,1)<>chr$(9)) then
print mid$(aLine$,x,1); : hpos=hpos+1
else
while hpos MOD tabs <> 0
print " "; : hpos=hpos+1
wend
print " "; : hpos=hpos+1
end if
next x
print
wend
close #f
end if
end Last edited by Mike, K8LH; 2nd December 2007 at 08:55 PM. |
| | |
| | (permalink) | |
| Experienced Member | Quote:
__________________ ========================= Futz's Microcontrollers & Robotics ========================= | |
| | |
| | (permalink) |
| Experienced Member | Thanks Mike, I still have JustBASIC. I think I'll just open an ebay store. |
| | |
| | (permalink) | |
| Experienced Member | Quote:
Lefty
__________________ Measurement changes behavior | |
| | |
| | (permalink) |
| Experienced Member | Edit, I tried to upload a code tidier but I couldn't get the setup to work. Will try again later. Mike. Last edited by Pommie; 3rd December 2007 at 07:39 AM. |
| | |
| | (permalink) |
| New Member | Hi Bill, I have a unicorn kit with me which I use with the inchworm+. Both the kits are working fine together. I got myself an LCD recently and wanted to interface with the unicorn kit. I compiled the asm from this thread and tested the LCD. Only the backlight comes on and nothing got displayed on the LCD. The LCD spec is here; http://www.hantronix.com/down/char-comm.pdf How should I go about tracing the problem? Thanks! Regards, Thiruselvam
__________________ ThiSel -------------------- Codito Ergo Sum |
| | |
| | (permalink) |
| Experienced Member | If it helps, here are pictures showing how mine is connected. Mike. Edit, that data sheet hasn't got the pinout. I do have one display where the connector is at the bottom. It might be wise to use a battery and resistor to find the backlight. Last edited by Pommie; 6th July 2008 at 04:13 PM. |
| | |
| | (permalink) |
| Experienced Member | If you get the backlight that's a good start, make sure it's in the right way around as the + & gnd pins are mirrored so an upsidedown LCD will still light the backlight. Pin 1 on the LCD should have a #1 near. Also you need the small jumper installed (J1) for your LCD, a GLCD you take off the jumper. Lastly try to adjust the contrast so you see a row of dark squares on the first display row. |
| | |
| | (permalink) |
| New Member | Hi Mike, pommie, The pinout is here: http://www.hantronix.com/down/20416ls.pdf It's supposed to be compatible with the Hitachi HD44780. Thanks!
__________________ ThiSel -------------------- Codito Ergo Sum |
| | |
| | (permalink) |
| Experienced Member | That pinout is the same as mine and so you should place it the same. Have you checked the jumper as mentioned by Bill. Mike. |
| | |
| | (permalink) |
| Experienced Member | That's a standard 20x4 LCD, you should adjust contrast till you see some dark squares on lines 1&2. You do need the jumper on J1. ![]() Last edited by blueroomelectronics; 19th February 2008 at 04:18 PM. |
| | |
| | (permalink) |
| New Member | I got it working! I think it was because of the jumper and the contrast pot. Pot has to be fully turned clockwise. Thanks guys!
__________________ ThiSel -------------------- Codito Ergo Sum |
| | |
| | (permalink) |
| Experienced Member | Works also for me What was tricky is the fact that when reading from the program memory on PIC16F887 it is necessary to insert 2 NOPs after setting the RD bit in EECON1 otherwise it does not work mysteriously but when debugging (single-stepping through the code) it does work correctly ... Petr |
| | |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| Thread | Thread Starter | Forum | Replies | Latest |
| HD44780 lcd help | jay543_uk | Micro Controllers | 12 | 8th November 2007 03:26 PM |
| PIC16F628A LCD problems. | HerbertMunch | Micro Controllers | 17 | 2nd October 2007 09:19 AM |
| LCD Troubles | Kyle-s4h | Micro Controllers | 13 | 11th September 2007 12:30 PM |