1
Общ форум / Proteus - проблем с LCD
« -: Май 01, 2012, 05:46:54 pm »
CarBeta5 благодаря много за помощта.
От тук може да видиш всички публикации на този потребител.
;------------- Начална инициализация на LCD модула --------------
Init_LCD
call Wait1 ; Изчакай 16ms
movlw B'00110000'
movwf PORTB
bsf E
bcf E
call Wait2 ; Изчакай 5ms
movlw B'00100000'
movwf PORTB
bsf E
bcf E
movlw B'00101000'
call Send_Command
movlw Disp_Off
call Send_Command
movlw Disp_On
call Send_Command
movlw Entry_Inc
call Send_Command
return
;------------- Изпращане на команда към LCD дисплея -------------
Send_Command
movwf LCD_Temp
call Check_BF
movf LCD_Temp,w
movwf PORTB
bcf RW
bcf RS
bsf E
bcf E
nop
nop
nop
nop
return
;------------- Изпращане на команда към LCD дисплея -------------
Send_Command
movwf LCD_Temp
call Check_BF
movf LCD_Temp,w
andlw H'F0'
movwf PORTB
bcf RW
bcf RS
bsf E
bcf E
swapf LCD_Temp,w
andlw H'F0'
movwf PORTB
bsf E
bcf E
nop
nop
nop
nop
return
list p=16f870
title "LCD Test"
#include <p16f870.inc>
__config _CPD_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _LVP_OFF & _CPD_OFF
;*************** Дефиниране на константи и променливи ***********
w EQU 0
f EQU 1
Disp_On EQU H'0C'
Disp_Off EQU H'08'
Entry_Inc EQU H'06'
CBLOCK H'20'
Counter
LCD_Temp
BF_Temp
ENDC
;************** Дефиниране на входно-изходни изводи *************
#define RS PORTC,0
#define RW PORTC,1
#define E PORTC,2
;****************************************************************
; Потребителска програма
;****************************************************************
ORG H'0000' ; Вектор на НУ
goto Start
ORG H'0004' ; Вектор на прекъсване
goto Int_Service
;****************************************************************
; Начало на програмата
;****************************************************************
Start bcf STATUS,RP1
bsf STATUS,RP0
movlw B'10000101' ; вътрешен такт за TMR0
movwf OPTION_REG ; такт 1:64
bcf STATUS,RP1
bcf STATUS,RP0
clrf PORTA
clrf PORTB
clrf PORTC
bcf STATUS,RP1
bsf STATUS,RP0
movlw H'06'
movwf ADCON1
clrf TRISA ; RA0-RA5 - изходи
clrf TRISB ; RB0-RB7 - изходи
clrf TRISC ; RC0-RC7 - изходи
bcf STATUS,RP1
bcf STATUS,RP0
goto main
;****************************************************************
; Използвани подпрограми
;****************************************************************
;------------- Програма за обслужване на прекъсванията ----------
Int_Service
retfie
;------------- Начална инициализация на LCD модула --------------
Init_LCD
call Wait1 ; Изчакай 16ms
movlw B'00110000'
movwf PORTB
bsf E
bcf E
call Wait2 ; Изчакай 5ms
movlw B'00111000'
movwf PORTB
bsf E
bcf E
movlw Disp_Off
call Send_Command
movlw Disp_On
call Send_Command
movlw Entry_Inc
call Send_Command
return
;------------- Изпращане на команда към LCD дисплея -------------
Send_Command
movwf LCD_Temp
call Check_BF
movf LCD_Temp,w
movwf PORTB
bcf RW
bcf RS
bsf E
bcf E
return
;----------------- Изпращане на кода на символа -----------------
Send_Char
movwf LCD_Temp
call Check_BF
movf LCD_Temp,w
movwf PORTB
bcf RW
bsf RS
bsf E
bcf E
return
;------------------- Проверка на флаг "Зает" --------------------
Check_BF
bcf STATUS,RP1
bsf STATUS,RP0
movlw H'FF'
movwf TRISB
bcf STATUS,RP1
bcf STATUS,RP0
bcf RS
bsf RW
bsf E
bcf E
movf PORTB,w
movwf BF_Temp
btfsc BF_Temp,7
goto Check_BF
bcf RW
bcf STATUS,RP1
bsf STATUS,RP0
clrf TRISB
bcf STATUS,RP1
bcf STATUS,RP0
return
;----------------- Подпрограми за времезадръжка -----------------
Wait1 clrf TMR0 ; Времезадръжка 16ms
bcf INTCON,T0IF
Loop1 btfss INTCON,T0IF
goto Loop1
return
Wait2 movlw D'176' ; Времезадръжка 5ms
movwf TMR0
bcf INTCON,T0IF
Loop2 btfss INTCON,T0IF
goto Loop2
return
Wait3 movlw D'128' ; Времезадръжка 2s
movwf Counter
clrf TMR0
Again3 bcf INTCON,T0IF
Loop3 btfss INTCON,T0IF
goto Loop3
decfsz Counter,f
goto Again3
return
;****************************************************************
; Главна програма
;****************************************************************
main call Init_LCD
Send_Message
movlw H'80'
call Send_Command
movlw 'L'
call Send_Char
movlw 'C'
call Send_Char
movlw 'D'
call Send_Char
Second_Line
movlw H'C0'
call Send_Command
movlw 'T'
call Send_Char
movlw 'E'
call Send_Char
movlw 'S'
call Send_Char
movlw 'T'
call Send_Char
Stop_Send
nop
goto Stop_Send
END
list p=16f872
title "LCD Test"
#include <p16f872.inc>
__config _CPD_ON & _WDT_OFF & _PWRTE_ON & _XT_OSC
;*************** Дефиниране на константи и променливи ***********
w EQU 0
f EQU 1
Disp_On EQU H'0C'
Disp_Off EQU H'08'
Entry_Inc EQU H'06'
CBLOCK H'20'
Counter
LCD_Temp
BF_Temp
ENDC
;************** Дефиниране на входно-изходни изводи *************
#define RS PORTC,0
#define RW PORTC,1
#define E PORTC,2
;****************************************************************
; Потребителска програма
;****************************************************************
ORG H'0000' ; Вектор на НУ
goto Start
ORG H'0004' ; Вектор на прекъсване
goto Int_Service
;****************************************************************
; Начало на програмата
;****************************************************************
Start bcf STATUS,RP1
bsf STATUS,RP0
movlw B'00000101' ; pull-up, вътрешен такт за TMR0
movwf OPTION_REG ; такт 1:64
bcf STATUS,RP0
clrf PORTA
clrf PORTB
clrf PORTC
bsf STATUS,RP0
clrf TRISA ; RA0-RA5 - изходи
clrf TRISB ; RB0-RB7 - изходи
clrf TRISC ; RC0-RC7 - изходи
bcf STATUS,RP0
goto main
;****************************************************************
; Използвани подпрограми
;****************************************************************
;------------- Програма за обслужване на прекъсванията ----------
Int_Service
return
;------------- Начална инициализация на LCD модула --------------
Init_LCD
call Wait1 ; Изчакай 16ms
movlw B'00110000'
movwf PORTB
bsf E
bcf E
call Wait2 ; Изчакай 5ms
movlw B'00111000'
movwf PORTB
bsf E
bcf E
movlw Disp_Off
call Send_Command
movlw Disp_On
call Send_Command
movlw Entry_Inc
call Send_Command
return
;------------- Изпращане на команда към LCD дисплея -------------
Send_Command
movwf LCD_Temp
call Check_BF
movf LCD_Temp,w
movwf PORTB
bcf RW
bcf RS
bsf E
bcf E
return
;----------------- Изпращане на кода на символа -----------------
Send_Char
movwf LCD_Temp
call Check_BF
movf LCD_Temp,w
movwf PORTB
bcf RW
bsf RS
bsf E
bcf E
return
;------------------- Проверка на флаг "Зает" --------------------
Check_BF
bsf STATUS,RP0
movlw H'FF'
movwf TRISB
bcf STATUS,RP0
bcf RS
bsf RW
bsf E
bcf E
movf PORTB,w
movwf BF_Temp
btfsc BF_Temp,7
goto Check_BF
bcf RW
bsf STATUS,RP0
clrf TRISB
bcf STATUS,RP0
return
;----------------- Подпрограми за времезадръжка -----------------
Wait1 clrf TMR0 ; Времезадръжка 16ms
bcf INTCON,T0IF
Loop1 btfss INTCON,T0IF
goto Loop1
return
Wait2 movlw D'176' ; Времезадръжка 5ms
movwf TMR0
bcf INTCON,T0IF
Loop2 btfss INTCON,T0IF
goto Loop2
return
Wait3 movlw D'128' ; Времезадръжка 2s
movwf Counter
clrf TMR0
Again3 bcf INTCON,T0IF
Loop3 btfss INTCON,T0IF
goto Loop3
decfsz Counter,f
goto Again3
return
;****************************************************************
; Главна програма
;****************************************************************
main call Init_LCD
movlw H'84'
call Send_Command
movlw 'L'
call Send_Char
movlw 'C'
call Send_Char
movlw 'D'
call Send_Char
movlw H'C0'
call Send_Command
movlw 'T'
call Send_Char
movlw 'E'
call Send_Char
movlw 'S'
call Send_Char
movlw 'T'
call Send_Char
call Wait3 ; Изчакай 2s
goto main
END