Har kikat igenom de där pdf:arna, riktigt bra faktist.
Fick mig att förstå en hel del om själva initieringen...
Ska ta ett kort på min labbplatta och lägga upp då det känns som att det är där som det är något galet, iom att koden är tagen ur olika exempel osv. Måste bara ladda batterier till kameran....
Kan längden på kabeln mellan E och RA0 spela någon roll?
Lägger in hela min kod ifall det är någon galen inställning eller nåogt liknande som jag gjort...
Kod: Markera allt
;****************************************************
; Pic LCD Driver
; LCD: HD44780 based
; Processor: 16F628A
; Creator: Nicklas Haraldsson
; Date: 2006-09-18
;
; Training program to interface with HD44780 LCDs
;
; Wiring:
; LCD PIC
; RS (6) RA2(1)
; R/W (7) RA1(18)
; E (8) RA0(17)
; DB4(13) RB0(6)
; DB5(14) RB1(7)
; DB6(15) RB2(8)
; DB7(16) RB3(9)
;
; Switches wired to PORTA
;
;*****************************************************
list p=16F628A
#include <p16F628A.inc>
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_OFF & _INTOSC_OSC_NOCLKOUT & _MCLRE_ON & _LVP_OFF
;*****************
; Ram Definitions
;*****************
CBLOCK 0x20
hiByte
loByte
LCDByte
counter_outer
counter_inner
nibToSend
d1
ENDC
lcdRS equ 2 ;RS on RA0
lcdRW equ 1 ;RW on RA1
lcdE equ 0 ;E on RA2
;PortB used for data ports
;*****************
;Code begins here
;*****************
org 0x0000
clrf PORTA
clrf PORTB
movlw 0x07 ; Disable comparators to enable
movwf CMCON ; pins for I/O
bsf STATUS,RP0 ;RAM Page 1
clrf TRISA
clrf TRISB
movlw 0xfe
call DelayXX ;Wait for everything to start
movlw 0xfe
call DelayXX
movlw 0xfe
call DelayXX
movlw 0xfe
call DelayXX
Main bcf PORTA, lcdE
bcf PORTA, lcdRS ;Prepare LCD for commands
movlw b'0011' ; 8 Bit
movwf nibToSend ; Send
call SENDNIB
movlw 0xfe
call DelayXX
movlw b'0011' ; 8 Bit
movwf nibToSend ; Send
call SENDNIB
movlw 0xfe
call DelayXX
;
; Resten av initieringe ser lika dan ut. ....
;
;
Loop
goto Loop
;******************
;Sub routines
;******************
LCDBYTE ;Sends a byte to LCD i 4 BIT
;IN LCDByte OUT: hiByte, loByte
clrf hiByte ;Clear vars
clrf loByte
bcf STATUS,0 ;clear carry to avoid screwing bitshifting
rlf LCDByte, 1 ;Rotate LCDByte left puting LCDByte<7> in the STATUS,0 Carry bit
rlf hiByte ;Move carry to hiByte
rlf LCDByte, 1
rlf hiByte
rlf LCDByte, 1
rlf hiByte
rlf LCDByte, 1
rlf hiByte
movf LCDByte, 0 ;Load LCDByte into W
movwf loByte ;And inte loByte
swapf loByte, 1 ;Swap hi and lo nibble and put it back
movf hiByte, 0 ;Move hiByte into w
movwf nibToSend ;Put it in the outbox
call SENDNIB
movf loByte,0
movwf nibToSend
call SENDNIB
call SHORTDLY ;Wait until instructions are done
return
SENDNIB ;Sends a nibble
;In: nibToSend
clrf W
movf nibToSend, 0 ;Load nibble into W
movwf PORTB ;Send nibble
nop
nop
nop
nop
nop
nop
nop
bsf PORTA,lcdE ;Pulse the LCD Enable high
nop
movlw 0x01
call DelayXX
bcf PORTA,lcdE ;lower LCD enable
nop
nop
nop
nop
nop
nop
return
;******************
;Delay XX
;Usage:
; movlw 5 ;Bigger value delay longer (1...255)
; call DelayXX ;Delay 4+w
;
;******************
DelayXX
movwf counter_outer ;Store delay time
loop_outer
clrf counter_inner ;Prepare inner loop
loop_inner
decfsz counter_inner ;dec and loop 256 times
goto loop_inner ;1+2 inst x 256 (Delay period)
clrwdt ;Give the dog a bone
decfsz counter_outer ;Dec outer loop_outer
goto loop_outer ; 1+1+2 inst x value of counter_outer
;Total delay 4 * W + (3*256) * W
; Example W = 5
; (4*5) + (3*256) * 5 = 20 + (768 * 5) =
; 20 + 3840 = 3860 Instructioncycles
retlw 0 ;Return and clear w
SHORTDLY ;Around 50us
movlw 0x48
movwf d1
SHORTDLY_0
decfsz d1, f
goto SHORTDLY_0
;4 cycles including call
return
END