最近遇到的问题,液晶说什么也不显示,期望高手指点。程序如下: list p=16f873a ; list directive to define processor #include <p16f873a.inc> ; processor specific variable definitions ; __CONFIG _CP_OFF & _WDT_ON & _BODEN_ON & _PWRTE_ON & _XT_OSC ;------------------------------- ;RB1 --> SID ;RB0 --> SCL ;RC0 --> RS ;RC1 --> CS1 ;RA3 --> RESET ;------------------------------- ;***** VARIABLE DEFINITIONS CBLOCK 0X20 PR_COUNT PR_OUT PR_DATA LCD_D_CON1 LCD_D_CON2 DAT1 DAT2 D5_COUNT1 D5_COUNT2 ENDC ;********************************************************************** ORG 0X000 ; PROCESSOR RESET VECTOR NOP GOTO INITIAL ; GO TO BEGINNING OF PROGRAM
ORG 0X004 ; INTERRUPT VECTOR LOCATION RETFIE ; RETURN FROM INTERRUPT INITIAL ;初始化程序 ;-------------------------------- ;SPECIAL REG ;-------------------------------- CLRWDT BCF STATUS,RP0 CLRF PORTA CLRF PORTB CLRF PORTC MOVLW 0X80 ;10000000 MOVWF ADCON0 CLRF ADRESH ;873 MOVLW 0C0H ;11000000 MOVWF RCSTA BSF STATUS,RP0 CLRF TRISA CLRF TRISB ;RB0-RB7,总线 MOVLW 0X80 ;1000,0000 MOVWF TRISC MOVLW 0X02 ; MOVWF ADCON1 CLRF ADRESL ;873 MOVLW 0X0D ;0000 1110 MOVWF OPTION_REG ;------------------------------- BCF STATUS,RP0 CALL LCD_INITIAL ;------------------------------- ;上电 ;------------------------------- BSF STATUS,RP0 BSF PCON,1 ;POWER-ON BSF PCON,0 ;BOD ;--------------------------------- ; MAIN PROGRAM ;--------------------------------- MAIN CLRWDT BCF STATUS,RP0 MOVLW 0B0H ;初始页地址 MOVWF PR_DATA CALL LCD_PR1 MOVLW 10H ;初始列地址高8位 MOVWF PR_DATA CALL LCD_PR1 MOVLW 0H ;初始列地址低8位 MOVWF PR_DATA CALL LCD_PR1
MOVLW 0A5H ;全显 MOVWF PR_DATA CALL LCD_PR1 CALL LCD_DELAY1 CALL LCD_DELAY1 CALL LCD_DELAY1 GOTO $ GOTO MAIN ;--------------------------------- ; -SUBPROGRAM- 液晶初始化 LCD_INITIAL ;--------------------------------- BCF STATUS,RP0 BCF PORTA,3 ;硬件复位 CALL LCD_DELAY1 BSF PORTA,3 MOVLW 0E2H ;软件复位 MOVWF PR_DATA CALL LCD_PR1 CALL LCD_DELAY1 MOVLW 0A2H ;LCD BIAS=1/9 MOVWF PR_DATA CALL LCD_PR1 MOVLW 0A0H ;列地址移动方向:ADC=0 MOVWF PR_DATA CALL LCD_PR1 MOVLW 0C8H ;行扫描方向:SHL=1 MOVWF PR_DATA CALL LCD_PR1 CALL LCD_DELAY1 MOVLW 02FH ;电源控制模式:vc,vr,vf=111 MOVWF PR_DATA CALL LCD_PR1 CALL LCD_DELAY1 MOVLW 26H ;内部调整电阻比:R2,R1,R0=111 MOVWF PR_DATA CALL LCD_PR1 CALL LCD_DELAY1 MOVLW 81H ;对比度寄存器模式 MOVWF PR_DATA CALL LCD_PR1 MOVLW 20H ;对比度寄存器值 MOVWF PR_DATA CALL LCD_PR1 MOVLW 40H ;起始行 MOVWF PR_DATA CALL LCD_PR1 MOVLW 0E0H ;写入数据时列地址自动加1,读不变 MOVWF PR_DATA CALL LCD_PR1 MOVLW 0AFH ;开显示 MOVWF PR_DATA CALL LCD_PR1 RETURN ;--------------------------------- ; -SUBPROGRAM- 写入控制命令 LCD_PR1 ;--------------------------------- BCF STATUS,RP0 MOVLW 8H MOVWF PR_COUNT BCF PORTC,1 ;选芯片 BCF PORTC,0 ;选命令寄存器 MOVF PR_DATA,W ;将要发送的数据送入发送寄存器PR_OUT MOVWF PR_OUT LCD_I_WRITE1 BCF PORTB,0 ;SCL=0 BTFSS PR_OUT,7 ;判断发送寄存器最高位值,输出到SID BCF PORTB,1 BTFSC PR_OUT,7 BSF PORTB,1 NOP NOP BSF PORTB,0 ;SCL=1 NOP NOP DECFSZ PR_COUNT,F ;判断循环次数 GOTO LCD_I_WRITE2 ;不为0跳转至LCD_I_WRITE2 BSF PORTC,1 ;为0,恢复芯片并返回 RETURN LCD_I_WRITE2 RLF PR_OUT,F ;左移一位 GOTO LCD_I_WRITE1 RETURN ;--------------------------------- ; -SUBPROGRAM- 写入显示数据 LCD_PR2 ;--------------------------------- MOVLW 8H MOVWF PR_COUNT BSF PORTC,0 ;选数据寄存器 BCF PORTC,1 MOVF PR_DATA,W MOVWF PR_OUT LCD_D_WRITE1 BCF PORTB,0 BTFSS PR_OUT,7 BCF PORTB,1 BTFSC PR_OUT,7 BSF PORTB,1 NOP NOP BSF PORTB,0 NOP NOP DECFSZ PR_COUNT,F GOTO LCD_D_WRITE2 BSF PORTC,1 RETURN LCD_D_WRITE2 RLF PR_OUT,F GOTO LCD_D_WRITE1 RETURN ;--------------------------------- ; -SUBPROGRAM- 400us 4M晶振,延时400us LCD_DELAY1 ;--------------------------------- BCF STATUS,RP0 MOVLW 17H MOVWF LCD_D_CON1 LCD_DLOOP1 CLRWDT DECFSZ LCD_D_CON1,1 GOTO LCD_DLOOP1 NOP NOP RETURN ;--------------------------------- ; -SUBPROGRAM- 0.64S 4M晶振,延时约0.64s LCD_DELAY2 ;--------------------------------- BCF STATUS,RP0 MOVLW 80H MOVWF LCD_D_CON2 LDLOOP DECFSZ LCD_D_CON2 GOTO $+2 RETURN CALL DELAY_5MS GOTO LDLOOP RETURN ;--------------------------------- ; -SUBPROGRAM- 5MS 4M晶振,延时5ms DELAY_5MS ;--------------------------------- BCF STATUS,RP0 MOVLW 0FH MOVWF D5_COUNT1 D5_LOOP2 MOVLW 6DH MOVWF D5_COUNT2 D5_LOOP1 DECFSZ D_COUNT1,1 GOTO D5_LOOP1 DECFSZ D_COUNT2,1 GOTO D5_LOOP2 RETURN ;--------------------------------- END 小弟先谢过了。 |
|