微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > STM32F103V NOKIA5110液晶

STM32F103V NOKIA5110液晶

时间:11-18 来源:互联网 点击:

//SCE = 1;
GPIO_SetBits(GPIOD, NOKIA_SCE);
}

/*-----------------------------------------------------------------------
LCD_write_byte : 使用SPI接口写数据到LCD

输入参数:data :写入的数据;
command :写数据/命令选择;-------------------------*/
void LCD_write_Data(unsigned char ucWriteData)
{
unsigned char uci;

//SCE = 0;
//DC = 1;
GPIO_ResetBits(GPIOD, NOKIA_SCE);
GPIO_SetBits(GPIOD, NOKIA_DC);

for(uci=0;uci<8;uci++)
{
if(ucWriteData & 0x80)
{
//SDIN = 1;
GPIO_SetBits(GPIOD, NOKIA_SDIN);
}
else
{
//SDIN = 0;
GPIO_ResetBits(GPIOD, NOKIA_SDIN);
}
//SCLK = 0;
GPIO_ResetBits(GPIOD, NOKIA_SCLK);
ucWriteData = ucWriteData < 1;
//SCLK = 1;
GPIO_SetBits(GPIOD, NOKIA_SCLK);
}

//SCE = 1;
GPIO_SetBits(GPIOD, NOKIA_SCE);

}
/*-----------------------------------------------------------------------
LCD_set_XY : 设置LCD坐标函数

输入参数:X -83
Y :0-5----------------------------------------------*/
void LCD_set_XY(unsigned char X, unsigned char Y)
{
LCD_write_CMD(0x40 | (Y & 0X07));// column
LCD_write_CMD(0x80 | (X & 0X7F)); // row
}

void setadd(unsigned char a,unsigned char d)//设定地址
{
write_byte((a|0x80),0);
write_byte((d|0x40),0);
}
/*-----------------------------------------------------------------------
LCD_clear : LCD清屏函数

-----------------------------------------------------------------------*/
void LCD_Clear(void)
{
uint uii;

//LCD_write_CMD(0x0c);
//LCD_write_CMD(0x80);

LCD_set_XY(0,0);
for(uii=0; uii{
LCD_write_Data(0x00);
}

}

void LCD_Init(void)
{

// 产生一个让LCD复位的低电平脉冲
//RST = 0;
GPIO_ResetBits(GPIOD, NOKIA_RST);

delay_1us();
//RST = 1;
GPIO_SetBits(GPIOD, NOKIA_RST);
//SCE = 0;
//DC = 0;
GPIO_ResetBits(GPIOD, NOKIA_SCE);
GPIO_ResetBits(GPIOD, NOKIA_DC);

// 关闭LCD
delay_1us(); //延时必须加
// 使能LCD
delay_1us();

LCD_write_CMD(0x21);// 使用扩展命令设置LCD模式,PD=0,V=0,H=1
LCD_write_CMD(0xc0);// 设置偏置电压
LCD_write_CMD(0x06);// 温度校正
LCD_write_CMD(0x13);// 1:48

LCD_write_CMD(0x20);// 使用基本命令
LCD_write_CMD(0x0c);// 设定显示模式,正常显示

// LCD_write_CMD(Nokia5110_DispMode_Reverse);
// 关闭LCD

//SCE = 1;
GPIO_SetBits(GPIOD, NOKIA_SCE);
}

/*-----------------------------------------------------------------------
LCD_write_char : 显示英文字符

输入参数:c :显示的字符;
-----------------------------------------------------------------------*/
void LCD_write_char(unsigned char c)
{
unsigned char line;

c -= 32;

for (line=0; line<6; line++)
{
LCD_write_Data(FONT6x8[c][line]);
}
}

void write_byte(uchar dd,uchar a)//写一字节 0:指令 1:数据
{
char i;
//SCE=0;
//DC=a;
GPIO_ResetBits(GPIOD, NOKIA_SCE);
if(a==0)GPIO_ResetBits(GPIOD, NOKIA_DC);
if(a==1)GPIO_SetBits(GPIOD, NOKIA_DC);
for(i=0;i<8;i++)
{
if(dd&mask_table[i])
//SDIN=1;
GPIO_SetBits(GPIOD, NOKIA_SDIN);
else
//SDIN=0;
//SCLK=0;
//SCLK=1;
GPIO_ResetBits(GPIOD, NOKIA_SDIN);
GPIO_ResetBits(GPIOD, NOKIA_SCLK);
GPIO_SetBits(GPIOD, NOKIA_SCLK);

}
//DC=1;
//SCE=1;
//SDIN=1;
GPIO_SetBits(GPIOD, NOKIA_DC);
GPIO_SetBits(GPIOD, NOKIA_SCE);
GPIO_SetBits(GPIOD, NOKIA_SDIN);
}

/*-----------------------------------------------------------------------
LCD_write_english_String : 英文字符串显示函数

输入参数:*s :英文字符串指针;
X、Y : 显示字符串的位置,x 0-83 ,y 0-5

-----------------------------------------------------------------------*/
void LCD_write_english_string(unsigned char X,unsigned char Y,char *s)
{
LCD_set_XY(X,Y);
while (*s)
{
LCD_write_char(*s);
s++;
}
}
//****************************************************/
//显示12(宽)*12(高)点阵列汉字
void displayonechar1212(uchar row, uchar page,uchar dd) //row:列 page:页 dd:字符
{
uchar row_i,xx,num=0;
for(xx=0;xx<2;xx++)
{
setadd(row,page);// 列,页
for(row_i=num; row_inum=num+12;page++;
}
}

#endif

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top