兼职项目 智能自行车
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.

135 lines
3.4 KiB

#include"lcd.h"
3 years ago
/*******************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> : Lcd1602_Delay1ms
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> : <EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ1ms
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> : c
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> : <EFBFBD><EFBFBD>
* ˵ <EFBFBD><EFBFBD> : <EFBFBD>ú<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>12MHZ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>12<EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD>Ƭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
*******************************************************************************/
3 years ago
void Lcd1602_Delay1ms(uint c) //<EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0us
3 years ago
{
uchar a,b;
for (; c>0; c--)
{
for (b=199;b>0;b--)
{
for(a=1;a>0;a--);
}
}
3 years ago
}
/*******************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> : LcdWriteCom
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> : <EFBFBD><EFBFBD>LCDд<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ֽڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> : com
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> : <EFBFBD><EFBFBD>
*******************************************************************************/
#ifndef LCD1602_4PINS //<EFBFBD><EFBFBD>û<EFBFBD>ж<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>LCD1602_4PINSʱ
void LcdWriteCom(uchar com) //д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
3 years ago
{
LCD1602_E = 0; //ʹ<EFBFBD><EFBFBD>
LCD1602_RS = 0; //ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LCD1602_RW = 0; //ѡ<EFBFBD><EFBFBD>д<EFBFBD><EFBFBD>
LCD1602_DATAPINS = com; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Lcd1602_Delay1ms(1); //<EFBFBD>ȴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȶ<EFBFBD>
3 years ago
LCD1602_E = 1; //д<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
Lcd1602_Delay1ms(5); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
LCD1602_E = 0;
3 years ago
}
#else
void LcdWriteCom(uchar com) //д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
3 years ago
{
LCD1602_E = 0; //ʹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LCD1602_RS = 0; //ѡ<EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LCD1602_RW = 0; //ѡ<EFBFBD><EFBFBD>д<EFBFBD><EFBFBD>
3 years ago
LCD1602_DATAPINS = com; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǽӵ<EFBFBD>P0<EFBFBD>ڵĸ<EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><EFBFBD>͸<EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD>ø<EFBFBD>
Lcd1602_Delay1ms(1);
LCD1602_E = 1; //д<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
Lcd1602_Delay1ms(5);
LCD1602_E = 0;
// Lcd1602_Delay1ms(1);
LCD1602_DATAPINS = com << 4; //<EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD>λ
Lcd1602_Delay1ms(1);
LCD1602_E = 1; //д<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
Lcd1602_Delay1ms(5);
LCD1602_E = 0;
}
#endif
/*******************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> : LcdWriteData
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> : <EFBFBD><EFBFBD>LCDд<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ֽڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> : dat
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> : <EFBFBD><EFBFBD>
*******************************************************************************/
#ifndef LCD1602_4PINS
void LcdWriteData(uchar dat) //д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
3 years ago
{
LCD1602_E = 0; //ʹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LCD1602_RS = 1; //ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LCD1602_RW = 0; //ѡ<EFBFBD><EFBFBD>д<EFBFBD><EFBFBD>
LCD1602_DATAPINS = dat; //д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Lcd1602_Delay1ms(1);
LCD1602_E = 1; //д<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
Lcd1602_Delay1ms(5); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
LCD1602_E = 0;
3 years ago
}
#else
void LcdWriteData(uchar dat) //д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
LCD1602_E = 0; //ʹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LCD1602_RS = 1; //ѡ<EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LCD1602_RW = 0; //ѡ<EFBFBD><EFBFBD>д<EFBFBD><EFBFBD>
LCD1602_DATAPINS = dat; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǽӵ<EFBFBD>P0<EFBFBD>ڵĸ<EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><EFBFBD>͸<EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD>ø<EFBFBD>
Lcd1602_Delay1ms(1);
3 years ago
LCD1602_E = 1; //д<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
Lcd1602_Delay1ms(5);
LCD1602_E = 0;
3 years ago
LCD1602_DATAPINS = dat << 4; //д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ
Lcd1602_Delay1ms(1);
LCD1602_E = 1; //д<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
Lcd1602_Delay1ms(5);
LCD1602_E = 0;
}
#endif
/*******************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> : LcdInit()
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> : <EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>LCD<EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> : <EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> : <EFBFBD><EFBFBD>
*******************************************************************************/
#ifndef LCD1602_4PINS
void LcdInit() //LCD<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><EFBFBD><EFBFBD>
3 years ago
{
LcdWriteCom(0x38); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
LcdWriteCom(0x0c); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LcdWriteCom(0x06); //дһ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>1
LcdWriteCom(0x01); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LcdWriteCom(0x80); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
3 years ago
}
#else
void LcdInit() //LCD<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><EFBFBD><EFBFBD>
3 years ago
{
LcdWriteCom(0x32); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>תΪ4λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LcdWriteCom(0x28); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD>µij<EFBFBD>ʼ<EFBFBD><EFBFBD>
LcdWriteCom(0x0c); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LcdWriteCom(0x06); //дһ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>1
LcdWriteCom(0x01); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LcdWriteCom(0x80); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
3 years ago
}
#endif