Cos'è ElectroYou | Login Iscriviti

ElectroYou - la comunità dei professionisti del mondo elettrico

LCD con 16F684

Raccolta di codici sorgenti

Moderatore: Foto UtentePaolino

0
voti

[1] LCD con 16F684

Messaggioda Foto Utentestepsan78 » 16 dic 2008, 17:40

Salve,

sono agli inizi con i PIC..e ho un problema. Non riesco a visualizzare una scritta su un display LCD a 2 righe. Il PIC che uso e' un 16F684. Vi allego lo schema elettrico e il programma (ho cercato di adattare un esempio di Zampilli per il 16F684).
Il problema è che non vedo niente sul display...

Grazie

Saluti

[img]<img%20src="http://immagini.p2pforum.it/out.php/i394986_LCD.JPG"%20alt=""%20/>[/img]

PROCESSOR 16F684
RADIX DEC
INCLUDE "P16F684.INC"

;Suppress MPASM warning message 302:
;"Register in operand not in bank 0. Ensure that bank bits are correct"

__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOD_OFF & _IESO_OFF & _FCMEN_OFF)
;LCD Control lines

LCD_RS equ 0 ;Register Select
LCD_E equ 1 ;Enable

;LCD data line bus

LCD_DB4 equ 2 ;LCD data line DB4
LCD_DB5 equ 3 ;LCD data line DB5
LCD_DB6 equ 4 ;LCD data line DB6
LCD_DB7 equ 5 ;LCD data line DB7

ORG 020H

tmpLcdRegister res 2
msDelayCounter res 2

;Reset Vector

ORG 00H
Start
bsf STATUS,RP0 ;Swap to register bank 1

movlw 00011111B ;Set PORTA lines
movwf TRISA

movlw 00000000B ;Set PORTC lines
movwf TRISC

; bcf PORTC,LCD_DB4 ;Set as output just the LCD's lines
; bcf PORTC,LCD_DB5
; bcf PORTC,LCD_DB6
; bcf PORTC,LCD_DB7
; bcf PORTC,LCD_E
;bcf PORTC,LCD_RS

bcf STATUS,RP0 ;Swap to register bank 0

;LCD inizialization

call LcdInit

;Locate LCD cursor on row 0, col 0

movlw 10H
call LcdLocate

;Shows "HELLO WORLD" string on LCD

movlw 'H'
call LcdSendData

movlw 'E'
call LcdSendData

movlw 'L'
call LcdSendData

movlw 'L'
call LcdSendData

movlw 'O'
call LcdSendData

movlw ' '
call LcdSendData

movlw 'W'
call LcdSendData

movlw 'O'
call LcdSendData

movlw 'R'
call LcdSendData

movlw 'L'
call LcdSendData

movlw 'D'
call LcdSendData

movlw ' '
call LcdSendData

movlw '!'
call LcdSendData

foreverLoop
goto foreverLoop

;**********************************************************************
; Delay subroutine
;
; W = Requested delay time in ms (clock = 4MHz)
;**********************************************************************

msDelay
movwf msDelayCounter+1
clrf msDelayCounter+0

; 1 ms (about) internal loop
msDelayLoop
nop
decfsz msDelayCounter+0,F
goto msDelayLoop
nop

decfsz msDelayCounter+1,F
goto msDelayLoop

return

;**********************************************************************
; Init LCD
; This subroutine must be called before each other lcd subroutine
;**********************************************************************

LcdInit
movlw 30 ;Wait 30 ms
call msDelay

;****************
; Reset sequence
;****************

bcf PORTC,LCD_RS ;Set LCD command mode

;Send a reset sequence to LCD

bsf PORTC,LCD_DB4
bsf PORTC,LCD_DB5
bcf PORTC,LCD_DB6
bcf PORTC,LCD_DB7

bsf PORTC,LCD_E ;Enables LCD
movlw 5 ;Wait 5 ms
call msDelay
bcf PORTC,LCD_E ;Disables LCD
movlw 1 ;Wait 1ms
call msDelay

bsf PORTC,LCD_E ;Enables LCD
movlw 1 ;Wait 1ms
call msDelay
bcf PORTC,LCD_E ;Disables LCD
movlw 1 ;Wait 1ms
call msDelay

bsf PORTC,LCD_E ;Enables E
movlw 1 ;Wait 1ms
call msDelay
bcf PORTC,LCD_E ;Disables E
movlw 1 ;Wait 1ms
call msDelay

bcf PORTC,LCD_DB4
bsf PORTC,LCD_DB5
bcf PORTC,LCD_DB6
bcf PORTC,LCD_DB7

bsf PORTC,LCD_E ;Enables LCD
movlw 1 ;Wait 1ms
call msDelay
bcf PORTC,LCD_E ;Disabled LCD
movlw 1 ;Wait 1ms
call msDelay

;Set 4 bit data bus length

movlw 28H;
call LcdSendCommand

;Entry mode set, increment, no shift

movlw 06H;
call LcdSendCommand

;Display ON, Curson ON, Blink OFF

movlw 0EH
call LcdSendCommand

;Clear display

call LcdClear

return


;**********************************************************************
; Clear LCD
;**********************************************************************

LcdClear
;Clear display

movlw 01H
call LcdSendCommand

movlw 2 ;Wait 2 ms
call msDelay

;DD RAM address set 1st digit

movlw 80H;
call LcdSendCommand

return

;**********************************************************************
; Locate cursor on LCD
; W = D7-D4 row, D3-D0 col
;**********************************************************************

LcdLocate
movwf tmpLcdRegister+0

movlw 80H
movwf tmpLcdRegister+1

movf tmpLcdRegister+0,W
andlw 0FH
iorwf tmpLcdRegister+1,F

btfsc tmpLcdRegister+0,4
bsf tmpLcdRegister+1,6

movf tmpLcdRegister+1,W
call LcdSendCommand

return


;**********************************************************************
; Send a data to LCD
;**********************************************************************

LcdSendData

bsf PORTC,LCD_RS
call LcdSendByte
return

;**********************************************************************
; Send a command to LCD
;**********************************************************************

LcdSendCommand
bcf PORTC,LCD_RS
call LcdSendByte
return

;**********************************************************************
; Send a byte to LCD by 4 bit data bus
;**********************************************************************

LcdSendByte
;Save value to send

movwf tmpLcdRegister

;Send highter four bits

bcf PORTC,LCD_DB4
bcf PORTC,LCD_DB5
bcf PORTC,LCD_DB6
bcf PORTC,LCD_DB7

btfsc tmpLcdRegister,4
bsf PORTC,LCD_DB4
btfsc tmpLcdRegister,5
bsf PORTC,LCD_DB5
btfsc tmpLcdRegister,6
bsf PORTC,LCD_DB6
btfsc tmpLcdRegister,7
bsf PORTC,LCD_DB7

bsf PORTC,LCD_E ;Enables LCD
movlw 1 ;Wait 1ms
call msDelay
bcf PORTC,LCD_E ;Disabled LCD
movlw 1 ;Wait 1ms
call msDelay

;Send lower four bits

bcf PORTC,LCD_DB4
bcf PORTC,LCD_DB5
bcf PORTC,LCD_DB6
bcf PORTC,LCD_DB7

btfsc tmpLcdRegister,0
bsf PORTC,LCD_DB4
btfsc tmpLcdRegister,1
bsf PORTC,LCD_DB5
btfsc tmpLcdRegister,2
bsf PORTC,LCD_DB6
btfsc tmpLcdRegister,3
bsf PORTC,LCD_DB7

bsf PORTC,LCD_E ;Enables LCD
movlw 1 ;Wait 1ms
call msDelay
bcf PORTC,LCD_E ;Disabled LCD
movlw 1 ;Wait 1ms
call msDelay

return

END
Avatar utente
Foto Utentestepsan78
0 3
 
Messaggi: 37
Iscritto il: 23 dic 2007, 13:05

0
voti

[2] Re: LCD con 16F684

Messaggioda Foto Utentestepsan78 » 16 dic 2008, 17:42

provo a visualizzare l'immagine..

Immagine
Avatar utente
Foto Utentestepsan78
0 3
 
Messaggi: 37
Iscritto il: 23 dic 2007, 13:05

0
voti

[3] Re: LCD con 16F684

Messaggioda Foto UtentePaolino » 16 dic 2008, 19:16

Hai provato a regolare il contrasto con il trimmer R2? Di solito il trimmer deve avere una resistenza da 5k o da 10k; da 2k mi sembra un po' pochino...

Regolando il contrasto dovresti aver modo di visualizzare qualcosa, anche solo dei quadrati "neri".

Ciao.

Paolo.
"Houston, Tranquillity Base here. The Eagle has landed." - Neil A.Armstrong

-------------------------------------------------------------

PIC Experience - http://www.picexperience.it
Avatar utente
Foto UtentePaolino
32,6k 8 12 13
G.Master EY
G.Master EY
 
Messaggi: 4226
Iscritto il: 20 gen 2006, 11:42
Località: Vigevano (PV)

0
voti

[4] Re: LCD con 16F684

Messaggioda Foto Utentestepsan78 » 16 dic 2008, 20:01

c'è un trimmer da 1K che nello schema non si vede il valore. Regolandolo, vedo una riga di quadrati neri, ma non la scritta "hello world" ...
Avatar utente
Foto Utentestepsan78
0 3
 
Messaggi: 37
Iscritto il: 23 dic 2007, 13:05

0
voti

[5] Re: LCD con 16F684

Messaggioda Foto UtentePaolino » 17 dic 2008, 9:36

Guardando il datasheet ho notato che nella configurazione delle porte del tuo codice manca una parte:

Codice: Seleziona tutto
PROCESSOR 16F684
RADIX DEC
INCLUDE "P16F684.INC"

;Suppress MPASM warning message 302:
;"Register in operand not in bank 0. Ensure that bank bits are correct"

__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOD_OFF & _IESO_OFF & _FCMEN_OFF)
;LCD Control lines

LCD_RS equ 0 ;Register Select
LCD_E equ 1 ;Enable

;LCD data line bus

LCD_DB4 equ 2 ;LCD data line DB4
LCD_DB5 equ 3 ;LCD data line DB5
LCD_DB6 equ 4 ;LCD data line DB6
LCD_DB7 equ 5 ;LCD data line DB7

ORG 020H

tmpLcdRegister res 2
msDelayCounter res 2

;Reset Vector

ORG 00H
Start

; Codice preso dal DATASHEET
; Disattivazione del comparatore
BCF STATUS,RP0 ;Bank 0
CLRF PORTA ;Init PORTA
MOVLW 07h ;Set RA<2:0> to
MOVWF CMCON0 ;digital I/O
BSF STATUS,RP0 ;Bank 1
CLRF ANSEL ;digital I/O
bsf STATUS,RP0 ;Swap to register bank 1

movlw 00011111B ;Set PORTA lines
movwf TRISA

; Disattivazione degli ingressi analogici
BANKSEL PORTC ;
CLRF PORTC ;Init PORTC
;MOVLW 07h ;Set RC<4,1:0> to
;MOVWF CMCON0 ;digital I/O
BANKSEL ANSEL ;
CLRF ANSEL ;digital I/O
MOVLW 00h ;IMPOSTAZIONE DI PORTC COME OUTPUT
MOVWF TRISC ;

BCF STATUS,RP0 ;Bank 0


Il dispositivo PIC16F684 ha gli ingressi analogici e il comparatore che vanno disattivati. Prova così e poi fammi sapere.
Ciao.

Paolo.
"Houston, Tranquillity Base here. The Eagle has landed." - Neil A.Armstrong

-------------------------------------------------------------

PIC Experience - http://www.picexperience.it
Avatar utente
Foto UtentePaolino
32,6k 8 12 13
G.Master EY
G.Master EY
 
Messaggi: 4226
Iscritto il: 20 gen 2006, 11:42
Località: Vigevano (PV)

0
voti

[6] Re: LCD con 16F684

Messaggioda Foto Utentestepsan78 » 17 dic 2008, 11:36

Funziona! adesso vedo finalmente la scritta. Grazie mille!!
Avatar utente
Foto Utentestepsan78
0 3
 
Messaggi: 37
Iscritto il: 23 dic 2007, 13:05


Torna a Firmware e programmazione

Chi c’è in linea

Visitano il forum: Nessuno e 9 ospiti