|
#include "LCD1602.h"
#define RS_SET GPIO_SetBits(GPIOC,GPIO_Pin_9)
#define RS_CLR GPIO_ResetBits(GPIOC,GPIO_Pin_9)
#define RW_CLR GPIO_ResetBits(GPIOC,GPIO_Pin_13)
#define RW_SET GPIO_SetBits(GPIOC,GPIO_Pin_13)
#define EN_CLR GPIO_ResetBits(GPIOB,GPIO_Pin_8)
#define EN_SET GPIO_SetBits(GPIOB,GPIO_Pin_8)
#define GPIO_WriteLow(GPIOx,a) GPIOx->BSRR=(((uint32_t)(uint8_t)~(a))<<16)|((uint32_t)(uint8_t)(a)) //D′μí8λ
#define GPIO_WriteHigh(GPIOx,a) GPIOx->BSRR=(((uint8_t)(uint8_t)~(a))<<24)|(((uint32_t)(uint8_t)(a))<<8) //D′¸ß8λ
/*************** ÅäÖÃLEDóÃμ½μÄI/O¿ú *******************/
void LCD_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOB, ENABLE); // ê1ÄüPB¶Ë¿úê±Öó
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|
GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7| GPIO_Pin_9|GPIO_Pin_13;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
void delay_nus(unsigned long n)
{
unsigned long j;
while(n--)
{
j=7;
while(j--);
}
}
void DelayMs(unsigned int t)
{
while(t--)
delay_nus(1100);
}
void LCD_write_com(unsigned char com) //D′Ãüáî
{
DelayMs(5);
GPIO_WriteLow(GPIOC,com); //D′μí8λ
delay_nus(1);
EN_CLR;
delay_nus(1);
RS_CLR;
delay_nus(1);
RW_CLR;
delay_nus(1);
EN_SET;
delay_nus(1);
EN_CLR;
}
void LCD_write_data(unsigned char Data) //D′êy¾Y
{
DelayMs(5);
GPIO_WriteLow(GPIOC,Data); //D′μí8λ
delay_nus(1);
EN_CLR;
delay_nus(1);
RS_SET;
delay_nus(1);
RW_CLR;
delay_nus(1);
delay_nus(1);
EN_SET;
delay_nus(1);
EN_CLR;
delay_nus(1);
RS_CLR;
}
void LCD_write_char(unsigned char y,unsigned char x,unsigned char data) //D′èë×Ö·ûoˉêy £yy,xμú¼¸DDμú¼¸¸ö
{
if (y == 0)
{
LCD_write_com(0x80+x);
}
else
{
LCD_write_com(0xc0+x);
}
LCD_write_data(data);
delay_nus(50);
}
void LCD_write_string(unsigned char y,unsigned char x,unsigned char *s )
{
if (y == 0)
{
LCD_write_com(0x80+x);
}
else
{
LCD_write_com(0xc0+x);
}
while (*s)
{
LCD_write_data(*s);
s++;
delay_nus(500);
}
}
void LCD_Init(void)
{
LCD_GPIO_Config();
DelayMs(1);
LCD_write_com(0x38); //êy¾YÏßÎa8룬á½DDÏÔê¾£¬5X7μãÕó
delay_nus(1);
LCD_write_com(0x0c); //¿aÏÔê¾£¬óD1a±ê£¬1a±êéá˸
delay_nus(1);
LCD_write_com(0x06); //1a±êóòòÆ£¬2»òÆÆá
delay_nus(1);
LCD_write_com(0x01); //ÇåÆá
delay_nus(1);
// LCD_write_string(0,0, " 1.Set CC 3.Vdc");
// LCD_write_string(1,0, " 2.Set CP");
}
|
|