STM32的LCD1926412864经典程序Word格式文档下载.docx

上传人:b****3 文档编号:16614494 上传时间:2022-11-24 格式:DOCX 页数:14 大小:17.93KB
下载 相关 举报
STM32的LCD1926412864经典程序Word格式文档下载.docx_第1页
第1页 / 共14页
STM32的LCD1926412864经典程序Word格式文档下载.docx_第2页
第2页 / 共14页
STM32的LCD1926412864经典程序Word格式文档下载.docx_第3页
第3页 / 共14页
STM32的LCD1926412864经典程序Word格式文档下载.docx_第4页
第4页 / 共14页
STM32的LCD1926412864经典程序Word格式文档下载.docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

STM32的LCD1926412864经典程序Word格式文档下载.docx

《STM32的LCD1926412864经典程序Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《STM32的LCD1926412864经典程序Word格式文档下载.docx(14页珍藏版)》请在冰豆网上搜索。

STM32的LCD1926412864经典程序Word格式文档下载.docx

#defineLCD_RW_LGPIO_ResetBits(GPIOA,GPIO_Pin_1)

#defineLCD_E1_HGPIO_SetBits(GPIOA,GPIO_Pin_2)

#defineLCD_E1_LGPIO_ResetBits(GPIOA,GPIO_Pin_2)

#defineLCD_E2_HGPIO_SetBits(GPIOA,GPIO_Pin_3)

#defineLCD_E2_LGPIO_ResetBits(GPIOA,GPIO_Pin_3)

#defineLCD_PSB_HGPIO_SetBits(GPIOA,GPIO_Pin_4)

#defineLCD_PSB_LGPIO_ResetBits(GPIOA,GPIO_Pin_4)

#defineLCD_DATA_PORTGPIOD

#defineLCD_DATAGPIOD->

BSRR//BSRR高十六位是复位,低十六位是置位

voidLcm_Wr_Dat(u8wrdata,u8enable);

//写数据

voidLcm_Wr_Com(u8wrcommand,u8enable);

//写指令

voidLcm_Rd_Status(u8enable);

//读忙状态

voidLcm_Init(u8enable);

//液晶初始化

voidLcm_GotoXY(u8pos_X,u8pos_y);

//设定坐标

voidLcm_SETXY(u8pos_X,u8pos_y,u8enable);

voidLcm_Disp_Char(u8onechar,u8enable);

//显示单个字符

voidLcm_Disp_Char_setxy(u8x,u8y,u8ch,u8enable);

//定坐标显示单个字符

voidLcm_Disp_Str(u8*string,u8enable);

//显示字符串

voidLcm_Disp_Str_setxy(u8x,u8y,u8*strings,u8enable);

//定坐标显示字符串

voidDelay_ms(u32m);

//1ms延时

voidLcm_Delay(void);

/*functionall------函数定义-------------

以下函数包含19264液晶的串并行方式

----------------------------------------*/

#definePSB_SERIAL0

#ifdefPSB_SERIAL

//-------以下为串口函数--------serialtransmission------///

//-----------传送8bits数据----

voidSend_byte(u8bbyte,u8enable)

{

u8i;

for(i=0;

i<

8;

i++)

{

LCD_E1_L;

LCD_E2_L;

if(0x80&

bbyte)LCD_RW_H;

//SID=1;

elseLCD_RW_L;

if(!

enable)//CLK=01;

串行用下降沿

{

LCD_E1_H;

Lcm_Delay();

LCD_E1_L;

}

else

LCD_E2_H;

LCD_E2_L;

bbyte<

<

=1;

Lcm_Delay();

//?

}

}

//-----------写指令函数----

voidLcm_Wr_Com(u8wcomd,u8enable)

Lcm_Delay();

Send_byte(0xf8,enable);

//1111_1,RW(0),RS(0),0-----------指令

Send_byte(0xf0&

wcomd,enable);

//high4bits

Send_byte(0xf8&

(wcomd<

4),enable);

//low4bits

//-----------写数据函数----

voidLcm_Wr_Dat(u8wdata,u8enable)

Send_byte(0xfa,enable);

//1111_1,RW(0),RS

(1),0---------数据

wdata,enable);

(wdata<

#else

//-------以下为并口函数--------parallelTransmission-------///

//---------读忙函数----------------

voidLcm_Rd_Status(u8enable)

u16getd;

while

(1)

LCD_RS_L;

//命令

LCD_RW_H;

//读取

//LCD_DATA=0xFFFF0000;

//LCD_DATA=0xFF;

高16位为复位,即写入0使其不忙

GPIO_Write(LCD_DATA_PORT,0XFFFF);

//准备读取数据,写0x0000则与上相同

enable)

getd=GPIO_ReadInputData(LCD_DATA_PORT);

if((getd&

0x0080)==0)

break;

}

//-----写指令----------------

voidLcm_Wr_Com(u8wcomd,u8enable)

Lcm_Rd_Status(enable);

LCD_RW_L;

LCD_DATA=wcomd|(~wcomd<

16);

//

if(!

LCD_E1_H;

LCD_E1_L;

else

LCD_E2_H;

LCD_E2_L;

//Lcm_Delay();

//------写数据----------------

voidLcm_Wr_Dat(u8wdata,u8enable)

LCD_RS_H;

LCD_DATA=wdata|(~wdata<

}

#endif

//----选定坐标,全屏选择----------

voidLcm_GotoXY(u8pos_x,u8pos_y)

{

u8addr;

if((pos_x>

11)||(pos_y>

1))

return;

if(pos_y==0)

addr=0x80+pos_x;

elseif(pos_y==1)

addr=0x90+pos_x;

Lcm_Wr_Com(addr,0);

//设定DDRAM地址

Lcm_Wr_Com(addr,1);

//---选定坐标,分屏选择------------

voidLcm_SETXY(u8pos_x,u8pos_y,u8enable)

if(enable==0)

//----------初始化----------------

voidLcm_Init(u8enable)

#ifdefPSB_SERIAL

LCD_PSB_L;

//选择串口

#else

LCD_PSB_H;

//选择并口

#endif

Lcm_Wr_Com(0x30,enable);

Delay_ms

(2);

Lcm_Wr_Com(0x0c,enable);

//开显示及光标设置

Lcm_Wr_Com(0x01,enable);

//显示清屏

Delay_ms(3);

Lcm_Wr_Com(0x06,enable);

//显示光标移动设置

/*---------displayfunction----------

以下为各种显示函数

---------------------------------------*/

voidLcm_Disp_Char(u8onechar,u8enable)//显示单个字符

Lcm_Wr_Dat(onechar,enable);

voidLcm_Disp_Str(u8*strings,u8enable)//显示字符串

while(*strings!

='

\0'

Lcm_Wr_Dat(*strings++,enable);

Lcm_Wr_Dat('

enable);

voidLcm_Disp_Char_setxy(u8x,u8y,u8ch,u8enable)//指定坐标显示字符

Lcm_GotoXY(x,y);

Lcm_Wr_Dat(ch,enable);

voidLcm_Disp_Str_setxy(u8x,u8y,u8*strings,u8enable)//指定坐标显示字符串

while(*strings!

Lcm_Wr_Dat('

}

二、以下是STM32配置函数

voidRCC_Configuration(void);

voidGPIO_Configuration(void);

voidNVIC_Configuration(void);

voidWWDG_Configuration(void);

/*

********************************************************************************

**函数名称:

RCC_Configuration(void)

**函数功能:

时钟初始化

**输入:

**输出:

**返回:

*/

GPIO_InitTypeDefGPIO_InitStructure;

ErrorStatusHSEStartUpStatus;

voidRCC_Configuration(void)

/*RCCsystemreset(fordebugpurpose)*/

RCC_DeInit();

/*EnableHSE*/

RCC_HSEConfig(RCC_HSE_ON);

/*WaittillHSEisready*/

HSEStartUpStatus=RCC_WaitForHSEStartUp();

if(HSEStartUpStatus==SUCCESS)

/*HCLK=SYSCLK*/

RCC_HCLKConfig(RCC_SYSCLK_Div1);

/*PCLK2=HCLK*/

RCC_PCLK2Config(RCC_HCLK_Div1);

/*PCLK1=HCLK/2*/

RCC_PCLK1Config(RCC_HCLK_Div2);

/*Flash2waitstate*/

FLASH_SetLatency(FLASH_Latency_2);

/*EnablePrefetchBuffer*/

FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

/*PLLCLK=8MHz*9=72MHz*/

RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);

/*EnablePLL*/

RCC_PLLCmd(ENABLE);

/*WaittillPLLisready*/

while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY)==RESET)

/*SelectPLLassystemclocksource*/

RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

/*WaittillPLLisusedassystemclocksource*/

while(RCC_GetSYSCLKSource()!

=0x08)

}

GPIO_Configuration(void)

端口初始化

voidGPIO_Configuration(void)

//定义端口结构体

//将GPIOA端口使能有效

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|//GPIOA

GPIO_Pin_1|

GPIO_Pin_2|

GPIO_Pin_3|

GPIO_Pin_4|

GPIO_Pin_5|

GPIO_Pin_6|

GPIO_Pin_7|

GPIO_Pin_8|

GPIO_Pin_9|

GPIO_Pin_10|

GPIO_Pin_11|

GPIO_Pin_12;

GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;

//推挽输出

GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;

//最高输出速率50MHz

GPIO_Init(GPIOA,&

GPIO_InitStructure);

//选择A端口

NVIC_Configuration(void)

中断初始化

voidNVIC_Configuration(void)

NVIC_InitTypeDefNVIC_InitStructure;

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);

NVIC_InitStructure.NVIC_IRQChannel=WWDG_IRQChannel;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;

NVIC_Init(&

NVIC_InitStructure);

函数功能:

延时函数

/*---Delayfunction-----------------

延时函数定义

//------1ms延时------------

voidDelay_ms(u32m)

u32i;

for(;

m!

=0;

m--)

for(i=0;

i<

25000;

i++);

//clk=50MHz,25_000000分频得1s,25000分频得1ms

//---------液晶延时----------

voidLcm_Delay(void)

u8j,i=100;

while(i--)

for(j=0;

j<

100;

j++)

{;

/*************结束***************/

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 能源化工

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1