|
|
|
|
#include"lcd.h"
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
|
* <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>
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Lcd1602_Delay1ms(uint c) //<EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0us
|
|
|
|
|
{
|
|
|
|
|
uchar a,b;
|
|
|
|
|
for (; c>0; c--)
|
|
|
|
|
{
|
|
|
|
|
for (b=199;b>0;b--)
|
|
|
|
|
{
|
|
|
|
|
for(a=1;a>0;a--);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
|
* <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>
|
|
|
|
|
{
|
|
|
|
|
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>
|
|
|
|
|
|
|
|
|
|
LCD1602_E = 1; //д<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
|
|
|
|
|
Lcd1602_Delay1ms(5); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
|
|
|
|
|
LCD1602_E = 0;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
void LcdWriteCom(uchar com) //д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
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>
|
|
|
|
|
|
|
|
|
|
LCD1602_DATAPINS = com; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>4λ<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>
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
#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>4λ<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_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>
|
|
|
|
|
{
|
|
|
|
|
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>
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
void LcdInit() //LCD<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
LcdWriteCom(0x32); //<EFBFBD><EFBFBD>8λ<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>
|
|
|
|
|
}
|
|
|
|
|
#endif
|