![]() |
![]() |
![]() |
|
|
|||||||
| 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) |
|
Sure post the code, the NOPs sound like a RWM problem.
|
|
|
|
|
|
|
(permalink) |
|
Hi Bill,
actually the problem with NOPs is described in the datasheet. As you can see I have modified your source code, this is the last version and the one that actually works I am designing a frequency counter and I'd like to use PIC16F886 and 16x2 LCD display so Unicorn with PIC16F887 seems as a good starting point to me. Petr Code:
;UNICORN LCD test, jumper on J1VEB, 8 bit mode with full handshaking
list p=16F887
include <p16F887.inc>
__CONFIG _CONFIG1, _HS_OSC & _WDT_OFF & _LVP_OFF & _DEBUG_ON
; CONFIG FOSC = INTOSC_HS, WDT = OFF, LVP = OFF, PBADEN = OFF
errorlevel -302,-305
#define LCD_E PORTE,2
#define LCD_RS PORTE,0
#define LCD_RW PORTE,1
#define LCD_BL PORTB,3
#define LED_N PORTC,1
cblock 0x20
msdelay:2
delay
temp
endc
org 0
banksel ANSEL ; select BANK 3
clrf ANSEL
clrf ANSELH
movlw 0x80 ; prepare to read FLASH
movwf EECON1
bcf STATUS,RP0 ; select BANK 3 -> BANK 2
movlw HIGH LCD_CC
movwf EEADRH
banksel TRISB ; select BANK 1
bcf TRISB,3 ; LCD backlight control
clrf TRISD ; LCD data output
clrf TRISE ; LCD control outputs
bcf TRISC,1
clrf PSTRCON
bcf STATUS,RP0 ; select BANK 0
clrf PORTE ; LCD E, RS, RW
bsf LED_N
; LCD soft reset (ignores/enables busy flag polling)
movlw .4 ; repeat sending 0x38 to reset LCD
movwf temp ; loop counter
init3: movlw .50 ; delay > 50 ms
movwf delay ; enter with delay in ms via W
dec01: call mswait ; wait 1 ms
decfsz delay ; decrement delay and skip when zero
goto dec01 ; branch backwards one instruction
bsf LCD_E ; LCD enable bit high
nop
nop
nop
nop
movlw 0x38 ; send 0x38 four times
movwf PORTD ; LCD = 0x38 (8 bit mode x 2 line)
nop
nop
nop
nop
nop
nop
bcf LCD_E ; latches on High to Low transition
decfsz temp
goto init3 ; repeat 3 times
bsf LCD_BL ; turn on backlight
call mswait
; load special charaters into LCD RAM using LCD busy flag
movlw b'01000000' ; set LCD CG address to 00
call LCD_Ins ; relative call
clrf temp
movlw LOW LCD_CC ; pointer to custom character table
bsf STATUS,RP1 ; BANK0 -> BANK2
movwf EEADR
nextcc: call rdflash
call LCD_Chr ; send the character into LCD RAM
incf temp
btfss temp, 6 ; 64 bytes total
goto nextcc
; clear & enable LCD DRAM, no visible cursor
movlw 0x0C ; display on, cursor off
call LCD_Ins
; display top 16 characters
movlw 0x01 ; clear display, home cursor
call LCD_Ins
movlw .16
movwf temp
bsf STATUS,RP1 ; BANK0 -> BANK2
movlw LOW Text_ ; low byte pointer
movwf EEADR
top: call rdflash
call LCD_Chr
decfsz temp
goto top
; display bottom 16 characters
movlw 0xC0 ; set cursor to second line
call LCD_Ins ; LCD instruction mode
movlw .16
movwf temp
bottom: call rdflash
call LCD_Chr ; LCD character mode
decfsz temp
goto bottom
nop
nop
bcf LED_N
goto $ ; endless loop done
; wait approx 1 ms
mswait movlw 4
movwf msdelay+1
msd movlw .250
movwf msdelay
msdl nop
decfsz msdelay
goto msdl
decfsz msdelay+1
goto msd
return
; read one byte from program flash, increment EEADDR
rdflash: bsf STATUS,RP0 ; BANK3
bsf STATUS,RP1 ; BANK3
bsf EECON1,EEPGD
bsf EECON1,RD ; 2 NOPs MUST (!) follow after reading program FLASH
nop
nop
bcf STATUS,RP0 ; BANK3 -> BANK2
incf EEADR
movf EEDAT,W
bcf STATUS,RP1 ; BANK2 -> BANK0
return
; LCD entry routines watches busy flag
LCD_Chr bsf LCD_RS ; enable character mode
LCD_Ins bsf STATUS,RP0 ; -> BANK1
clrf TRISD ; make PORTD an output
bcf STATUS,RP0 ; -> BANK0
movwf PORTD ; put data on LCD port
bcf LCD_RW
nop
bsf LCD_E
nop
nop
nop
nop
bcf LCD_E ; latch byte to LCD
nop
bcf LCD_RS
bsf STATUS,RP0 ; -> BANK1
movlw 0xff
movwf TRISD ; make LCD port input
bcf STATUS,RP0 ; -> BANK0
bsf LCD_RW ; enter read mode
bsf LCD_E ; enable LCD
BusyF btfsc PORTD,7 ; wait for bit 7 to be pulled low
goto BusyF
bcf LCD_E
bcf LCD_RW ; return to instruction mode
return
; text to display (Table with two bytes per word)
org 0x0400
Text_ dt "blueroom ",.0,.1
dt "electronics ",.2,.3
; *** 2x2 blueroomelectronics logo (house)
LCD_CC dt .128,.128,.129,.131,.135,.143,.159,.159
dt .128,.128,.128,.144,.152,.156,.158,.130
dt .159,.159,.159,.145,.145,.145,.159,.128
dt .130,.130,.158,.130,.130,.130,.158,.128
END
|
|
|
|
|
|
|
(permalink) |
|
I have created a module or program errrrrrrrrrr maybe i'll just call it a file over the last couple of days since receiving my Unicorn & 2 line LCD display.
I wrote this with the MPLAB C18 C compiler. Thanks to a lot of the conversation & examples i found here + other places i was able to get enough of the callable routines put together that I can now get on with working on my little application. I used the Junebug between MPLAB and the UNICORN. There's a lot of documentation in the "C" source file - almost everything i found & learned i put into either the comments or in the #define MACROS. 20 years ago when i made a living as a "C" programmer we weren't allowed to put literals in our code - if it's a good habit - then good habits are hard to break! I've got a compile conditional near the top of the file that can be changed and the entire thing recompiled for either 4 bit or 8 bit data access. As a final test before posting it i tried transferring each of the hex files to the Unicorn via PicKit2 instead of MPLAB - and noticed that my delay's during the 'demo' are quite long. Maybe someone knows of a way i can put logic in my code to know whether or not i'm running under MPLAB? The .zip file contains the C source file plus two .hex files - one was compiled for 4 bit and the other for 8 bit. I spent most of my time getting the 'soft character' loading thing to work - DOH - i was trying to send the bitmaps via the control port instead of the data port! This is my first PIC program - so you may have to cut me some slack! If you see anything in my source code that needs to be tweaked please let me know - i'm learning! I have a couple of questions that i can't find answers to - if there are any of you that might be kind enough to help me with: 1) On the UNICORN I can read switches 1 & 2 reliably - switch 3 is flaky and switch 4 i can't read at all. I removed the CPU and checked the switch with an ohm meter - it's not the switch. I noticed there are not any pullups on Switch 3 or 4 which puzzles me - can anyone shed any light on this? I would like to use all four switches if possible. 2) I need to monitor some 12v (DC) signals - is it okay to connect the UNICORN inputs directly to 12v DC signals or is there some more 'electronic glue' required? (I'm a quart or two low in the EE department :P). 3) Anyone have any pointers on switch de-bouncing? What works, what doesn't? 4) Anyone have any good examples of working interrupt code in "C" that's triggered from switch closure AND that's triggered from one of the input pins changing state? It's 3:15am - i think i better go to bed! Amazing how time flies when you are having fun! Thanks & thanks for all the help so far! David / W9GF w9gf@arrl.net |
|
|
|
|
|
|
(permalink) |
|
Ahh is this the thread? I'll look at it, you have to enable weak pullups on port B for the pushbuttons to function. I'll look at the code shortly.
|
|
|
|
|
|
|
(permalink) |
|
ha - okay - as the "Father of the Unicorn" - it may bring a tear to your eye!
|
|
|
|
|
|
|
(permalink) |
|
Yes, thank you Bill for the Unicorn - it really helps me with my design of the frequency counter with LCD display. I have now finally a first skeleton of the software for the PIC that can actually work, I just need to run a fest tests ...
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 |