ademcekic
Üye
- Katılım
- 30 Tem 2007
- Mesajlar
- 62
- Puanları
- 1
- Yaş
- 40
Merhaba arkadaşlar. Pic öğrenmeye çalışıyorum. Bayağı bir yol katettim fakat bir türlü LCD den görüntü alamadım.
89c52 kullanarak aynı LCD den görüntü alabiliyorum. Aşağıya 89c52 ile ekrana yazı yazdırdığım resmi ekledim. Ve hemen altında da asm kodu var.
;*****************************************************
EN EQU P3.0 ; The pin of LCD enable to the port of P3.0
RW EQU P3.1 ; The pin of LCD R/W to the port of P3.1
RS EQU P3.2 ; The pin of LCD RS to the port of P3.2
LCDDATA EQU P1 ; Databus of LCD to the port of P1
BUTON EQU R7
;*******************************************************************************
ORG 0 ; Starting address of program
INIT_MAIN:
MOV SP,#30H ; Starting address of stack pointer
MOV P0,#255 ; P0 = input
MOV R0,#3 ; Repeats the LCD initialization 3 times at the beginning
MOV P1,#0 ; P1 = output
MOV P3,#0 ; P3 = output
MOV P2,#255
MOV P3,#15 ; LCD illumination on, P3.4 = P3.5 = P3.6 = 0 = output
;*******************************************************************************
INIT_LCD: ; Performing LCD's initialization adjustments
MOV A,#38h ; Function set, (20h), 8 bit databus (10h),
ACALL SENDCOMMAND ; Two lines display (08h)
MOV A,#0Ch ; Display and cursor control command, LCD on
ACALL SENDCOMMAND ; Cursor off
MOV A,#06h ; Entry mode, shifts cursor's position to the right
ACALL SENDCOMMAND ; for one character after each data automatically
DJNZ R0,INIT_LCD
;*******************************************************************************
CLEAR_LCD: ; This subroutine clears the data RAM and display
CLR RS
SETB EN
MOV LCDDATA,#01h
CLR EN
ACALL WAIT_LCD
;*******************************************************************************
MOV A,#85H ; 9AH, the address of 1rd line and 6th character,
ACALL SENDCOMMAND ; is sent to the LCD as a command
MOV A,#'H' ; Writes "HELLO" on display
ACALL WRITE_TEXT ; starting from 1rd line and 6th character
MOV A,#'E'
ACALL WRITE_TEXT
MOV A,#'L'
ACALL WRITE_TEXT
MOV A,#'L'
ACALL WRITE_TEXT
MOV A,#'O'
ACALL WRITE_TEXT
MAIN:
AJMP MAIN
RET
;*******************************************************************************
SENDCOMMAND: ; The subroutine to send command to microcontroller
CLR RS
SETB EN
MOV LCDDATA, A
CLR EN
ACALL WAIT_LCD
RET
;*******************************************************************************
WRITE_TEXT:
SETB RS ; The subroutine to send text to the LCD
SETB EN
MOV LCDDATA,A
CLR EN
ACALL WAIT_LCD
RET
;*******************************************************************************
WAIT_LCD:
CLR EN
CLR RS
SETB RW ; Read command
MOV LCDDATA,#0FFh ; Prepare all the buses for input
SETB EN
MOV A,LCDDATA ; Read the value
JB ACC.7,WAIT_LCD ; If bit 7 is still high, then the LCD is still busy
CLR EN ; Otherwise terminate the command
CLR RW
RET
;*******************************************************************************
END
;******************************************************************
Fakat 16F877 ile başaramadım. Pic i taktığımda aşağıdaki ekrandan başka bir şey gelmiyor ekrana. ASM kodu da aşağıda. Nerede hata yaptığımı anlamadım. Yardımınızı bekliyorum.
;************************************************************
; LCD ÇALIŞTIRILAMADI. 13.03.2011 13:03
list p=16F877
include "p16F877.inc"
__config H'3F31' ;PWRT on, diğerleri kapalı,
;Osilatör XT ve 4Mhz
;****************************************************************
cblock 0x20
R0
R1
R2
endc
#define LCDDATA PORTD
#define LCDCONTROL PORTC
#define RS 5 ;LCD RS pini RC4'e bağlı.
#define RW 6 ;LCD RW pini RC6'ya bağlı.
#define EN 7 ;LCD E pini RC5'e bağlı.
;*************************************************************************
org 0 ; Start at flash address 0
CALL INIT_MAIN
CALL INIT_LCD
CALL CLEAR_LCD
CALL HELLO_YAZ
MAIN:
GOTO MAIN
;*************************************************************************
INIT_MAIN:
bsf STATUS,RP0 ; Select Registers at Bank 1
movlw b'00000000' ; Set port to OUTPUT
movwf TRISC ; PORTC = LCD KONTROL UÇLARI
MOVWF TRISD
bcf STATUS,RP0
MOVLW D'3'
MOVWF R0 ; Repeats the LCD initialization 3 times at the beginning
RETURN
;*************************************************************************
INIT_LCD: ; Performing LCD’s initialization adjustments
MOVLW H'38' ; Function set, (20h), 8 bit databus (10h),
CALL SENDCOMMAND ; Two lines display (08h)
MOVLW H'0C' ; Display and cursor control command, LCD on
CALL SENDCOMMAND ; Cursor off
MOVLW H'06' ; Entry mode, shifts cursor’s position to the right
CALL SENDCOMMAND ; for one character after each data automatically
DECFSZ R0,F
GOTO INIT_LCD
BCF PORTB,7
RETURN
;*************************************************************************
CLEAR_LCD: ; This subroutine clears the data RAM and display
BCF LCDCONTROL,RS
BSF LCDCONTROL,EN
MOVLW D'1'
MOVWF LCDDATA
BCF LCDCONTROL,EN
CALL WAIT_LCD
RETURN
;*************************************************************************
HELLO_YAZ:
MOVLW A'H' ; the address of FİRST line and FİRST character,
CALL SENDCOMMAND ; is sent to the LCD as a command
MOVLW A'E' ; Writes “WELCOME” on display
CALL WRITE_TEXT ; starting from 3rd line and 6th character
MOVLW A'L'
CALL WRITE_TEXT
MOVLW A'L'
CALL WRITE_TEXT
MOVLW A'O'
CALL WRITE_TEXT
RETURN
;*************************************************************************
SENDCOMMAND:
BCF LCDCONTROL,RS ; The subroutine to send command to microcontroller
BSF LCDCONTROL,EN
MOVWF LCDDATA
BCF LCDCONTROL,EN
CALL WAIT_LCD
RETURN
;*************************************************************************
WRITE_TEXT:
BSF LCDCONTROL,RS ; The subroutine to send text to the LCD
BSF LCDCONTROL,EN
MOVWF LCDDATA
BCF LCDCONTROL,EN
CALL WAIT_LCD
RETURN
;*************************************************************************
WAIT_LCD:
BCF LCDCONTROL,EN
BCF LCDCONTROL,RS
BSF LCDCONTROL,RW ; Read command
bsf STATUS,RP0 ; Select Registers at Bank 1
MOVLW B'11111111' ; Prepare all the buses for input
MOVWF TRISD ;
bcf STATUS,RP0
BTFSC LCDDATA,7 ; If bit 7 is still high, then the LCD is still busy
GOTO WAIT_LCD
BCF LCDCONTROL,EN ; Otherwise terminate the command
BCF LCDCONTROL,RW
bsf STATUS,RP0 ; Select Registers at Bank 1
MOVLW D'0' ; Prepare all the buses for output
MOVWF TRISD ; Read the value
bcf STATUS,RP0
RETURN
;*************************************************************************
END
;***************************************************************
89c52 kullanarak aynı LCD den görüntü alabiliyorum. Aşağıya 89c52 ile ekrana yazı yazdırdığım resmi ekledim. Ve hemen altında da asm kodu var.
;*****************************************************
EN EQU P3.0 ; The pin of LCD enable to the port of P3.0
RW EQU P3.1 ; The pin of LCD R/W to the port of P3.1
RS EQU P3.2 ; The pin of LCD RS to the port of P3.2
LCDDATA EQU P1 ; Databus of LCD to the port of P1
BUTON EQU R7
;*******************************************************************************
ORG 0 ; Starting address of program
INIT_MAIN:
MOV SP,#30H ; Starting address of stack pointer
MOV P0,#255 ; P0 = input
MOV R0,#3 ; Repeats the LCD initialization 3 times at the beginning
MOV P1,#0 ; P1 = output
MOV P3,#0 ; P3 = output
MOV P2,#255
MOV P3,#15 ; LCD illumination on, P3.4 = P3.5 = P3.6 = 0 = output
;*******************************************************************************
INIT_LCD: ; Performing LCD's initialization adjustments
MOV A,#38h ; Function set, (20h), 8 bit databus (10h),
ACALL SENDCOMMAND ; Two lines display (08h)
MOV A,#0Ch ; Display and cursor control command, LCD on
ACALL SENDCOMMAND ; Cursor off
MOV A,#06h ; Entry mode, shifts cursor's position to the right
ACALL SENDCOMMAND ; for one character after each data automatically
DJNZ R0,INIT_LCD
;*******************************************************************************
CLEAR_LCD: ; This subroutine clears the data RAM and display
CLR RS
SETB EN
MOV LCDDATA,#01h
CLR EN
ACALL WAIT_LCD
;*******************************************************************************
MOV A,#85H ; 9AH, the address of 1rd line and 6th character,
ACALL SENDCOMMAND ; is sent to the LCD as a command
MOV A,#'H' ; Writes "HELLO" on display
ACALL WRITE_TEXT ; starting from 1rd line and 6th character
MOV A,#'E'
ACALL WRITE_TEXT
MOV A,#'L'
ACALL WRITE_TEXT
MOV A,#'L'
ACALL WRITE_TEXT
MOV A,#'O'
ACALL WRITE_TEXT
MAIN:
AJMP MAIN
RET
;*******************************************************************************
SENDCOMMAND: ; The subroutine to send command to microcontroller
CLR RS
SETB EN
MOV LCDDATA, A
CLR EN
ACALL WAIT_LCD
RET
;*******************************************************************************
WRITE_TEXT:
SETB RS ; The subroutine to send text to the LCD
SETB EN
MOV LCDDATA,A
CLR EN
ACALL WAIT_LCD
RET
;*******************************************************************************
WAIT_LCD:
CLR EN
CLR RS
SETB RW ; Read command
MOV LCDDATA,#0FFh ; Prepare all the buses for input
SETB EN
MOV A,LCDDATA ; Read the value
JB ACC.7,WAIT_LCD ; If bit 7 is still high, then the LCD is still busy
CLR EN ; Otherwise terminate the command
CLR RW
RET
;*******************************************************************************
END
;******************************************************************
Fakat 16F877 ile başaramadım. Pic i taktığımda aşağıdaki ekrandan başka bir şey gelmiyor ekrana. ASM kodu da aşağıda. Nerede hata yaptığımı anlamadım. Yardımınızı bekliyorum.
;************************************************************
; LCD ÇALIŞTIRILAMADI. 13.03.2011 13:03
list p=16F877
include "p16F877.inc"
__config H'3F31' ;PWRT on, diğerleri kapalı,
;Osilatör XT ve 4Mhz
;****************************************************************
cblock 0x20
R0
R1
R2
endc
#define LCDDATA PORTD
#define LCDCONTROL PORTC
#define RS 5 ;LCD RS pini RC4'e bağlı.
#define RW 6 ;LCD RW pini RC6'ya bağlı.
#define EN 7 ;LCD E pini RC5'e bağlı.
;*************************************************************************
org 0 ; Start at flash address 0
CALL INIT_MAIN
CALL INIT_LCD
CALL CLEAR_LCD
CALL HELLO_YAZ
MAIN:
GOTO MAIN
;*************************************************************************
INIT_MAIN:
bsf STATUS,RP0 ; Select Registers at Bank 1
movlw b'00000000' ; Set port to OUTPUT
movwf TRISC ; PORTC = LCD KONTROL UÇLARI
MOVWF TRISD
bcf STATUS,RP0
MOVLW D'3'
MOVWF R0 ; Repeats the LCD initialization 3 times at the beginning
RETURN
;*************************************************************************
INIT_LCD: ; Performing LCD’s initialization adjustments
MOVLW H'38' ; Function set, (20h), 8 bit databus (10h),
CALL SENDCOMMAND ; Two lines display (08h)
MOVLW H'0C' ; Display and cursor control command, LCD on
CALL SENDCOMMAND ; Cursor off
MOVLW H'06' ; Entry mode, shifts cursor’s position to the right
CALL SENDCOMMAND ; for one character after each data automatically
DECFSZ R0,F
GOTO INIT_LCD
BCF PORTB,7
RETURN
;*************************************************************************
CLEAR_LCD: ; This subroutine clears the data RAM and display
BCF LCDCONTROL,RS
BSF LCDCONTROL,EN
MOVLW D'1'
MOVWF LCDDATA
BCF LCDCONTROL,EN
CALL WAIT_LCD
RETURN
;*************************************************************************
HELLO_YAZ:
MOVLW A'H' ; the address of FİRST line and FİRST character,
CALL SENDCOMMAND ; is sent to the LCD as a command
MOVLW A'E' ; Writes “WELCOME” on display
CALL WRITE_TEXT ; starting from 3rd line and 6th character
MOVLW A'L'
CALL WRITE_TEXT
MOVLW A'L'
CALL WRITE_TEXT
MOVLW A'O'
CALL WRITE_TEXT
RETURN
;*************************************************************************
SENDCOMMAND:
BCF LCDCONTROL,RS ; The subroutine to send command to microcontroller
BSF LCDCONTROL,EN
MOVWF LCDDATA
BCF LCDCONTROL,EN
CALL WAIT_LCD
RETURN
;*************************************************************************
WRITE_TEXT:
BSF LCDCONTROL,RS ; The subroutine to send text to the LCD
BSF LCDCONTROL,EN
MOVWF LCDDATA
BCF LCDCONTROL,EN
CALL WAIT_LCD
RETURN
;*************************************************************************
WAIT_LCD:
BCF LCDCONTROL,EN
BCF LCDCONTROL,RS
BSF LCDCONTROL,RW ; Read command
bsf STATUS,RP0 ; Select Registers at Bank 1
MOVLW B'11111111' ; Prepare all the buses for input
MOVWF TRISD ;
bcf STATUS,RP0
BTFSC LCDDATA,7 ; If bit 7 is still high, then the LCD is still busy
GOTO WAIT_LCD
BCF LCDCONTROL,EN ; Otherwise terminate the command
BCF LCDCONTROL,RW
bsf STATUS,RP0 ; Select Registers at Bank 1
MOVLW D'0' ; Prepare all the buses for output
MOVWF TRISD ; Read the value
bcf STATUS,RP0
RETURN
;*************************************************************************
END
;***************************************************************