LCD a PIC

Ing. Hynek Sladký sladky
Středa Březen 17 11:41:57 CET 2004


Dobry den,

>Uz dva dny.Nevi prosim nekdo co delam spatne nebo zda je na
>tehle veci nejaky figl?

snad vam pomuze nasledujici rutina. Je to pripojeni LCD k PIC16F84 po 4bit
sbernici. V casti 'reset' se provadi inicializace displeje. Taktez se
provadi kontrola BUSY statusu displeje. Pouzivam to jiz dlouho v nekolika
zarizenich a bez problemu...

Hynek Sladky.


 list p=16c84, r=dec
;
#include 16c84.inc ;nacteni definic pro PIC16C84
;----------------------
;------ Power-On-Reset nastaveni registru
POR_tA equ 00000000b
POR_tB equ 00001111b
inp_tB equ 11111111b
POR_opt equ 10000011b ;16us cycle
;------ Pracovni konstanty
;------ Obsazeni Hardware
;definice pripojeni displeje
#define Busy portb, 7
#define RS porta, 0
#define RW porta, 1
#define E porta, 3
;------ pracovni registry
char equ free+0
str_pos equ free+1
temp equ free+2
;======================
;------ Reset procesoru
 org 0000h
 goto reset
;
;------ textove zpravy
Strings
 addlw 0-STRING
 addwf pcl, F
STRING dt "AHOJ SVETE!", 0
;======================
;------ prace s 4bitovym displejem
;------ zapsani Hi nibble
;inp char
;out -
OutByte_1
 bcf RW
 movlw 00Fh
 andwf portb, F
 movf char, W
 andlw 0F0h
 iorwf portb, F
 goto $+1
 bsf E
 goto $+1
 bcf E
 return
;------ zapsani Lo nibble
;inp char
;out -
OutByte_2
 bcf RW
 movlw 00Fh
 andwf portb, F
 swapf char, W
 andlw 0F0h
 iorwf portb, F
 goto $+1
 bsf E
 goto $+1
 bcf E
 return
;------ cekani na uvolneni displeje po operaci
;inp -
;out C
WaitBusy
 bcf RS
 bsf RW
 bcf C
 movlw inp_tB
 tris portb
WaitBusy1
 bsf E
 nop
 btfss Busy
 bsf C
 bcf E
 nop
 bsf E
 nop
 bcf E
 btfss C
 goto WaitBusy1
WaitBusy0
 movlw POR_tB
 tris portb
 return
;------ vypis textoveho retezce od adresy W
;inp W
;out -
Print
 movwf   str_pos
Print1
 movf str_pos, W
 call Strings
 movwf char
 movf char, F
 btfsc Z
 return
;
 call PrintChar+1
 incf str_pos, F
 goto Print1
;------ vypis znaku
;inp W
;out -
PrintChar
 movwf char
 call WaitBusy
 bsf RS
 call OutByte_1
 call OutByte_2
 return
;------ provedeni prikazu displeje
;inp W
;out -
PrintCMD
 movwf char
 call WaitBusy
 bcf RS
 call OutByte_1
 call OutByte_2
 return
;------ vypis hexadecimalniho kodu (8bit)
;inp W
;out -
PrintHex
 movwf str_pos
 swapf str_pos, W
 andlw 0Fh
 addlw '0'
 movwf char
 movlw ':'
 subwf char, W
 movlw 7
 btfsc C
 addwf char, F
 call WaitBusy
 bsf RS
 call OutByte_1
 call OutByte_2
 movf str_pos, W
PrintHex1
 andlw 0Fh
 addlw '0'
 movwf char
 movlw ':'
 subwf char, W
 movlw 7
 btfsc C
 addwf char, F
 call WaitBusy
 bsf RS
 call OutByte_1
 call OutByte_2
 return
;------ cekani 1ms
;inp W
;out -
Wait1ms
 movwf   char
 movlw 249
 movwf str_pos
 nop
 decfsz str_pos, F
 goto $-2
 decfsz char, F
 goto $-6
 return
;------ cekani 10ms (max 2,5s)
;inp W
;out -
Wait10ms
 movwf temp
 movlw 10
 call Wait1ms
 decfsz temp, F
 goto $-3
 return
;======================
;------ nastaveni registru a displeje
reset
 movlw   POR_opt
 option
 clrf porta
 clrf portb
 movlw POR_tA
 tris porta
 movlw POR_tB
 tris portb
 movlw 100
 call    Wait10ms
 movlw 030h
 movwf char
 call OutByte_1
 movlw 10
 call Wait1ms
 movlw 030h
 movwf char
 call OutByte_1
 movlw 1
 call Wait1ms
 movlw 030h
 call OutByte_1
 call WaitBusy
 movlw 020h
 movwf char
 call OutByte_1
;inicializace displeje 4bit
 movlw 028h
 call PrintCMD
 movlw 00Ch
 call PrintCMD
 movlw 006h
 call PrintCMD
 movlw 040h
 call PrintCMD
 movlw CharGen
 call Print
 movlw 001h
 call PrintCMD
 movlw STRING
 call Print
 movlw 0C0h
 call PrintCMD
 movlw '?'
 call PrintChar
KONEC
 goto KONEC

 end







Další informace o konferenci Hw-list