Files

136 lines
3.9 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include"lcd.h"
/*******************************************************************************
* �� �� �� : Lcd1602_Delay1ms
* �������� : ��ʱ��������ʱ1ms
* �� �� : c
* �� �� : ��
* ˵ �� : �ú�������12MHZ�����£�12��Ƶ��Ƭ������ʱ��
*******************************************************************************/
void Lcd1602_Delay1ms(uint c) //��� 0us
{
uchar a,b;
for (; c>0; c--)
{
for (b=199;b>0;b--)
{
for(a=1;a>0;a--);
}
}
}
/*******************************************************************************
* �� �� �� : LcdWriteCom
* �������� : ��LCDд��һ���ֽڵ�����
* �� �� : com
* �� �� : ��
*******************************************************************************/
#ifndef LCD1602_4PINS //��û�ж������LCD1602_4PINSʱ
void LcdWriteCom(uchar com) //�����
{
LCD1602_E = 0; //ʹ��
LCD1602_RS = 0; //ѡ��������
LCD1602_RW = 0; //ѡ��д��
LCD1602_DATAPINS = com; //��������
Lcd1602_Delay1ms(1); //�ȴ������ȶ�
LCD1602_E = 1; //д��ʱ��
Lcd1602_Delay1ms(5); //����ʱ��
LCD1602_E = 0;
}
#else
void LcdWriteCom(uchar com)
{
LCD1602_E = 0;
LCD1602_RS = 0;
LCD1602_RW = 0;
LCD1602_DATAPINS = com;
Lcd1602_Delay1ms(1);
LCD1602_E = 1;
Lcd1602_Delay1ms(1);
LCD1602_E = 0;
Lcd1602_Delay1ms(1);
LCD1602_DATAPINS = com << 4;
Lcd1602_Delay1ms(1);
LCD1602_E = 1;
Lcd1602_Delay1ms(1);
LCD1602_E = 0;
}
#endif
/*******************************************************************************
* �� �� �� : LcdWriteData
* �������� : ��LCDд��һ���ֽڵ�����
* �� �� : dat
* �� �� : ��
*******************************************************************************/
#ifndef LCD1602_4PINS
void LcdWriteData(uchar dat) //�����
{
LCD1602_E = 0; //ʹ������
LCD1602_RS = 1; //ѡ����������
LCD1602_RW = 0; //ѡ��д��
LCD1602_DATAPINS = dat; //�����
Lcd1602_Delay1ms(1);
LCD1602_E = 1; //д��ʱ��
Lcd1602_Delay1ms(5); //����ʱ��
LCD1602_E = 0;
}
#else
void LcdWriteData(uchar dat)
{
LCD1602_E = 0;
LCD1602_RS = 1;
LCD1602_RW = 0;
LCD1602_DATAPINS = dat;
Lcd1602_Delay1ms(1);
LCD1602_E = 1;
Lcd1602_Delay1ms(1);
LCD1602_E = 0;
Lcd1602_Delay1ms(1);
LCD1602_DATAPINS = dat << 4;
Lcd1602_Delay1ms(1);
LCD1602_E = 1;
Lcd1602_Delay1ms(1);
LCD1602_E = 0;
}
#endif
/*******************************************************************************
* �� �� �� : LcdInit()
* �������� : ��ʼ��LCD��
* �� �� : ��
* �� �� : ��
*******************************************************************************/
#ifndef LCD1602_4PINS
void LcdInit() //LCD��ʼ���ӳ���
{
LcdWriteCom(0x38); //����ʾ
LcdWriteCom(0x0c); //����ʾ����ʾ���
LcdWriteCom(0x06); //дһ��ָ���1
LcdWriteCom(0x01); //����
LcdWriteCom(0x80); //��������ָ�����
}
#else
void LcdInit() //LCD��ʼ���ӳ���
{
LcdWriteCom(0x32); //��8λ����תΪ4λ����
LcdWriteCom(0x28); //����λ���µij�ʼ��
LcdWriteCom(0x0c); //����ʾ����ʾ���
LcdWriteCom(0x06); //дһ��ָ���1
LcdWriteCom(0x01); //����
LcdWriteCom(0x80); //��������ָ�����
}
#endif