新手写了一个用1602液晶在第二行第一位显示字母A的程序,程序可以通过编译,但是液晶上部显示,不知道什么原因?求助解答,谢谢
LIST P=16F873a ; 告诉编译程序使用何种PIC单片机
INCLUDE "p16f873a.inc" ; 定义了特殊寄存器等内容的头文件
ERRORLEVEL -224
__CONFIG _PWRTE_ON & _XT_OSC & _WDT_OFF ; 配置字
databuf EQU 20H
i EQU 21H
j EQU 22H
combuf EQU 23H
buf EQU 24H
;====================
; 非精确延时函数
;====================
delay
MOVLW 32H
MOVWF i
D1
MOVLW 09H
MOVWF j
D2
DECFSZ j
GOTO D2
DECFSZ i
GOTO D1
RETLW 0
;====================
; 数据总线写入函数
;====================
write_bus
CLRF STATUS
MOVWF buf
BTFSS buf, 0 ; 数据总线的D0位连接于单片机的RA5引脚
GOTO L1
BSF PORTA, 05H
GOTO L2
L1
BCF PORTA, 05H
L2
BTFSS buf, 01H ;数据总线的D1位连接于单片机的RC0引脚
GOTO L3
BSF PORTC, 0
GOTO L4
L3
BCF PORTC, 0
L4
BTFSS buf, 02H ;数据总线的D2位连接于单片机的RB5引脚
GOTO L5
BSF PORTB, 05H
GOTO L6
L5
BCF PORTB, 05H
L6
BTFSS buf, 03H ;数据总线的D3位连接于单片机的RB4引脚
GOTO L7
BSF PORTB, 04H
GOTO L8
L7
BCF PORTB, 04H
L8
BTFSS buf, 04H ;数据总线的D4位连接于单片机的RB3引脚
GOTO L9
BSF PORTB, 03H
GOTO L10
L9
BCF PORTB, 03H
L10
BTFSS buf, 05H ;数据总线的D5位连接于单片机的RB2引脚
GOTO L11
BSF PORTB, 02H
GOTO L12
L11
BCF PORTB, 02H
L12
BTFSS buf, 06H ;数据总线的D6位连接于单片机的RB1引脚
GOTO L13
BSF PORTB, 01H
GOTO L14
L13
BCF PORTB, 01H
L14
BTFSS buf, 07H ;数据总线的D7位连接于单片机的RB0引脚
GOTO L15
BSF PORTB, 0
L15
BCF PORTB, 0
RETURN
;====================
; 1602忙检测函数
;====================
lcd_wait_busy
BSF STATUS, 0x5
BCF STATUS, 0x6
BSF TRISB, 0
BCF STATUS, 0x5
BCF PORTA, 0x3
BSF PORTA, 0x2
BSF PORTA, 0x1
L16
BTFSC PORTB, 0
GOTO L16
BCF PORTA, 0x1
BSF STATUS, 0x5
BCF TRISB, 0
BCF STATUS, 0x5
RETURN
;====================
; 1602写命令函数
;====================
lcd_write_com
CLRF STATUS
MOVWF combuf
BCF PORTA, 0x3
BCF PORTA, 0x2
MOVF combuf,W
CALL write_bus
BSF PORTA, 0x1
NOP
BCF PORTA, 0x1
RETURN
;=============================
; 1602写命令函数(带忙检测)
;=============================
lcd_write_com_busy
CLRF STATUS
CALL lcd_wait_busy
CALL lcd_write_com
;=============================
; 1602写数据函数(带忙检测)
;=============================
lcd_write_data
CLRF STATUS
CALL lcd_wait_busy
MOVWF databuf
BSF PORTA, 0x3
BCF PORTA, 0x2
MOVF databuf, W
CALL write_bus
BSF PORTA, 0x1
NOP
BCF PORTA, 0x1
RETURN
;=============================
; 1602初始化函数
;=============================
lcdreset
CALL delay
CALL delay
CALL delay
MOVLW 0x38
CALL lcd_write_com
CALL delay
MOVLW 0x38
CALL lcd_write_com
CALL delay
MOVLW 0x38
CALL lcd_write_com
MOVLW 0x38 ;显示模式设置 8位数据,双行,5*7字符点阵
CALL lcd_write_com_busy
MOVLW 0x8 ;显示开关控制 显示功能关,无光标
CALL lcd_write_com_busy
MOVLW 0x1 ;清屏指令
CALL lcd_write_com_busy
MOVLW 0x6 ;设置输入模式 写入新的数据后,光标右移,显示屏不移动
CALL lcd_write_com_busy
MOVLW 0xc ;显示开关控制 显示功能开,无光标
CALL lcd_write_com_busy
;=============================
; 初始化函数
;=============================
init
CLRWDT
MOVLW 0xe
BSF STATUS, 0x5
BCF STATUS, 0x6
MOVWF ADCON0 ;RA0为模拟量输入口,其他为数字量
MOVLW 0x80 ;关闭RB口电平变化功能
OPTION
MOVLW 0xd1 ;RA1,RA2,RA3,RA5置为输出,其他未用设置为输入
MOVWF TRISA
MOVLW 0xc0 ;RB0-RB5置为输出,其他为未用设置为输入
MOVWF TRISB
MOVLW 0xfe
MOVWF TRISC ;RC0为输出,其他未用设置为输入
BCF INTCON, 0x3 ;RB口电平变化中断禁止
BCF STATUS, 0x5
RETURN
;=========================
; 主函数
;=========================
main
CALL init
CALL lcdreset
MOVLW 0C0H
CALL lcd_write_com_busy
MOVLW 41H
CALL lcd_write_data
END此主题相关图片如下电路图.png:
此帖出自
小平头技术问答
一周热门 更多>