兼职项目 智能自行车
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.6 KiB

3 years ago
#include "lcd.h"
void Read_Busy() //æ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>bit7<EFBFBD><EFBFBD>0<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>У<EFBFBD>1<EFBFBD><EFBFBD>ֹ
{
unsigned char sta; //
LCD1602_DB = 0xff;
LCD1602_RS = 0;
LCD1602_RW = 1;
do
{
LCD1602_EN = 1;
sta = LCD1602_DB;
LCD1602_EN = 0; //ʹ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><EFBFBD>ͷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}while(sta & 0x80);
}
void Lcd1602_Write_Cmd(unsigned char cmd) //д<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
Read_Busy();
LCD1602_RS = 0;
LCD1602_RW = 0;
LCD1602_DB = cmd;
LCD1602_EN = 1;
LCD1602_EN = 0;
}
void Lcd1602_Write_Data(unsigned char dat) //д<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
Read_Busy();
LCD1602_RS = 1;
LCD1602_RW = 0;
LCD1602_DB = dat;
LCD1602_EN = 1;
LCD1602_EN = 0;
}
void LcdSetCursor(unsigned char x,unsigned char y) //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
{
unsigned char addr;
if(y == 0)
addr = 0x00 + x;
else
addr = 0x40 + x;
Lcd1602_Write_Cmd(addr|0x80);
}
//<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾһ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData)
{
Y &= 0x1;
X &= 0xF; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>X<EFBFBD><EFBFBD><EFBFBD>ܴ<EFBFBD><EFBFBD><EFBFBD>15<EFBFBD><EFBFBD>Y<EFBFBD><EFBFBD><EFBFBD>ܴ<EFBFBD><EFBFBD><EFBFBD>1
if (Y) X |= 0x40; //<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>ʾ<EFBFBD>ڶ<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>+0x40;
X |= 0x80; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Lcd1602_Write_Cmd(X); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Lcd1602_Write_Data(DData); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
void LcdShowStr(unsigned char x,unsigned char y,unsigned char *str) //<EFBFBD><EFBFBD>ʾ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
{
LcdSetCursor(x,y); //<EFBFBD><EFBFBD>ǰ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
while(*str != '\0')
{
Lcd1602_Write_Data(*str++);
}
}
void InitLcd1602() //1602<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>
{
Lcd1602_Write_Cmd(0x38); //<EFBFBD>򿪣<EFBFBD>5*8,8λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Lcd1602_Write_Cmd(0x0c);
Lcd1602_Write_Cmd(0x06);
Lcd1602_Write_Cmd(0x01); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}