單片機(jī)匯編實(shí)驗(yàn)七:掃描鍵盤及液晶顯示實(shí)驗(yàn)
////////////////////////////////////
//初始化液晶屏程序段
INTE: CLR P1.1 //讀寫選擇端口清零
CLR P2.6 //關(guān)閉數(shù)碼管
CLR P2.7
MOV A,#0X38
CALL WRITE_COM
CALL DELAY
MOV A,#0X0E
CALL WRITE_COM
CALL DELAY
CALL DELAY
MOV A,#0X06
CALL WRITE_COM
CALL DELAY
CALL DELAY
MOV A,#0X01
CALL WRITE_COM
CALL DELAY
CALL DELAY
MOV A,#0X80
CALL WRITE_COM
CALL DELAY0
RET
//10ms延時(shí)函數(shù)
DELAY:MOV R7,#0FFH
DELY1:MOV R6,#02AH
DELY2:NOP
DJNZ R6,DELY2
DJNZ R7,DELY1
RET
//5ms延時(shí)函數(shù)
DELAY0:MOV R7,#0FEH
DELY10:MOV R6,#02FH
DELY20:NOP
DJNZ R6,DELY2
DJNZ R7,DELY1
RET
//寫命令函數(shù)
WRITE_COM:
MOV P0,A //暫定A為數(shù)據(jù)傳輸寄存器
CLR P1.0 //打開命令選擇端口
CLR P1.1 //打開寫選擇端口
CLR P2.5 //液晶使能端
CALL DELAY //10MS
SETB P2.5 //液晶使能端
CALL DELAY //10MS
CLR P2.5 //液晶使能端
RET
// 寫數(shù)據(jù)函數(shù)
WRITE_DATE:
MOV P0,A //暫定A為數(shù)據(jù)傳輸寄存器
SETB P1.0 //液晶數(shù)據(jù)/命令選擇端口
CLR P1.1 //讀寫選擇端口
CLR P2.5 //液晶使能端
CALL DELAY //10MS
SETB P2.5 //液晶使能端
CALL DELAY //10MS
CLR P2.5 //液晶使能端
RET
TABLE: DB 30H,31H,32H,33H,34H,35H,36H,37H,38H,39H,41H,42H,43H,44H,45H,46H,47H
END
評(píng)論