|
下面是lcd1602四線的驅(qū)動程序,下載后不收亂碼 就是不顯示,求大聲指點
#include "lcd1602.h"
/******發(fā)送命令******/
void LCD1602_Cmd(uint8_t cmd)
{
delay_ms(2000);
EN_LOW;
RS_LOW; /* RS=0,寫入命令 */
delay_us(10);
GPIO_Write(Dx_PORT, (cmd&0xf0)); /* 接收高四位命令 */
EN_HIGH;
delay_ms(1);
EN_LOW;
GPIO_Write(Dx_PORT, (cmd&0xf0)<<4); /* 接收低四位命令 */
EN_HIGH;
delay_ms(1);
EN_LOW;
}
/******發(fā)送數(shù)據(jù)******/
void LCD1602_Data(uint8_t data)
{
delay_ms(200);
EN_LOW;
RS_HIGH; /* RS=1,寫入數(shù)據(jù) */
delay_us(10);
GPIO_Write(Dx_PORT, (data&0xf0)); /* 接收高四位數(shù)據(jù) */
EN_HIGH;
delay_ms(1);
EN_LOW;
delay_us(10);
GPIO_Write(Dx_PORT, (data&0xf0)<<4); /* 接收低四位數(shù)據(jù) */
EN_HIGH;
delay_ms(1);
EN_LOW;
}
/******LCD初始化******/
void LCD1602_Init(void)
{
delay_ms(200);
// LCD1602_Cmd(0x20);
// LCD1602_Cmd(0x32);
// delay_ms(5);
// LCD1602_Cmd(0x28); // 最后發(fā)0x28,進入4線模式,設(shè)置16*2顯示,115*7點陣,4位數(shù)據(jù)接口
// delay_ms(5);
// LCD1602_Cmd(0x28);
// delay_ms(5);
// EN_HIGH;
// LCD1602_Cmd(0x28);
// EN_LOW;
LCD1602_Cmd(0x30);
delay_ms(5);
LCD1602_Cmd(0x30);
delay_ms(5);
LCD1602_Cmd(0x30);
delay_ms(5);
LCD1602_Cmd(0x28);
LCD1602_Cmd(0x08);
LCD1602_Cmd(0x01); /* 清屏 */
LCD1602_Cmd(0x06);
LCD1602_Cmd(0x0f);
delay_ms(2);
//LCD1602_Cmd(0x06); /* 寫入數(shù)據(jù)光標右移,寫入新數(shù)據(jù)顯示屏不移動 */
//LCD1602_Cmd(0x0C); /* 開顯示,有光標,光標閃爍 */
}
/* 0x80和0xC0分別是兩行的開始地址,將字符的序號加上行的地
址作為命令發(fā)送給LCD1602會讓下一個字符輸出在指定的位置 */
/******發(fā)送地址******/
void LCD1602_SetCursor(uint8_t x, uint8_t y) // x:列坐標 y:行坐標
{
LCD1602_Cmd(x + (y ? LINE1:LINE0));
}
/******連續(xù)發(fā)送數(shù)據(jù)******/
void LCD1602_PrintStr(uint8_t x, uint8_t y, uint8_t *str)
{
LCD1602_SetCursor(x, y);
while(*str != '\0')
{
LCD1602_Data(*str++);
}
}
#ifndef __LCD1602_H
#define __LCD1602_H
/***********LCD1602 四線驅(qū)動***********/
#include "system.h"
#include "delay.h"
/***********Definition***********/
#define LINE0 0x80
#define LINE1 0xC0
#define Rx_PORT (GPIOD)//RS= PD6 RW=PD5 EN=PD4
#define RS_PIN (GPIO_PIN_6) /* PD6 */
//#define RW_PIN (GPIO_PIN_5) /* PD5 */ /* NOT USE(RW接地) */
#define EN_PIN (GPIO_PIN_4) /* PD4 */
#define Rx_FOUR_PINS (RS_PIN | EN_PIN)
//#define Rx_ALL_PINS (RS_PIN | RW_PIN | EN_PIN) /* NOT USE */
#define Dx_PORT (GPIOC)
//#define D0_PIN (GPIO_PIN_0) /* PC0 */ /* NOT USE */
//#define D1_PIN (GPIO_PIN_1) /* PC1 */ /* NOT USE */
//#define D2_PIN (GPIO_PIN_2) /* PC2 */ /* NOT USE */
//#define D3_PIN (GPIO_PIN_3) /* PC3 */ /* NOT USE */
#define D4_PIN (GPIO_PIN_4) /* PC4 */
#define D5_PIN (GPIO_PIN_5) /* PC5 */
#define D6_PIN (GPIO_PIN_6) /* PC6 */
#define D7_PIN (GPIO_PIN_7) /* PC7 */
#define Dx_FOUR_PINS (D4_PIN | D5_PIN | D6_PIN | D7_PIN)
//#define Dx_ALL_PINS (D0_PIN | D1_PIN | D2_PIN | D3_PIN | D4_PIN | \
D5_PIN | D6_PIN | D7_PIN) /* NOT USE */
#define RS_LOW GPIO_WriteLow (Rx_PORT, RS_PIN)
#define RS_HIGH GPIO_WriteHigh(Rx_PORT, RS_PIN)
#define EN_LOW GPIO_WriteLow (Rx_PORT, EN_PIN)
#define EN_HIGH GPIO_WriteHigh(Rx_PORT, EN_PIN)
#define Dx_CLR GPIO_Write(Dx_PORT, 0x00)
/***********Function***********/
void LCD1602_Cmd(uint8_t cmd);
void LCD1602_Data(uint8_t data);
void LCD1602_Init(void);
void LCD1602_SetCursor(uint8_t x, uint8_t y);
void LCD1602_PrintStr(uint8_t x, uint8_t y, uint8_t *str);
#endif /* __LCD1602_H */
|
|