/*Include---------------------------*/
#include"stm32f10x_lib.h" //°üº¬ËùÓеÄÍ·Îļþ
#include<stdio.h>
//----------------º¯ÊýÉùÃ÷--------------------
void Delay_MS(u16 dly)
{
u16 i,j;
for(i=0;i<dly;i++)
for(j=1000;j>0;j--);
}
void RCC_Configuration(void);
void GPIO_Configuration(void);
void USART3_Configuration(void);
void LCDDisplay(u8 x, u8 y, u8 *Data);
void LCDInit(void);
void LCDCursorPosition(u8 x, u8 y);
void LCDWriteData(u8 Data);
void LCDWiteCommand(u8 Command);
void LcdData(unsigned char Data);
/*******************************************************************************
* Function Name : main
* Description : Main program.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
int main(void)
{
// u8 i;
// u8 data1[]={0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca};
// u8 data[]={0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca};
// #ifdef DEBUG
// debug();
// #endif
// //------------³õʼ»¯------------
// RCC_Configuration();
// GPIO_Configuration();
// USART3_Configuration();
// while(1)
// {
// for(i=0;i<5;i++)
// {
// USART_SendData(USART3, data[i]);
// Delay_MS(2000);
// }
// }
RCC_Configuration();
GPIO_Configuration();
GPIO_SetBits(GPIOB, GPIO_Pin_11);
//----------------PB8.9.10.11
//¸ßÊÇÊý¾ÝÊäÈëµÍÊÇÖ¸Áî
//¸ßÊǶÁÈ¡ µÍÊÇдÈë
//´ÓµÍµ½¸ßµÄÌø±ä
//¸ßÊDz¢ÐÐ µÍÊÇ´®ÐÐ
LCDInit();
while (1)
{
// Delay_MS(20);
// LCDInit();
// Delay_MS(20);
// for(i=0;i<5;i++)
// {
// }
LCDDisplay(0, 1, "¹þ¹þÄãÃÃ");
LCDDisplay(1, 2, "ÖÕÓڳɹ¦ÁË");
LCDDisplay(2, 0, "¸Ð¾õÔÙÒ²²»°®ÁË");
LCDDisplay(3, 2, "ÄÌÄ̵Ä");
//
}
}
/*******************************************************************************
* Function Name : Delay_Ms
* Description : delay 1 ms.
* Input : dly (ms)
* Output : None
* Return : None
*******************************************************************************/
/*******************************************************************************
* Function Name : RCC_Configuration
* Description : Configures the different system clocks.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void RCC_Configuration(void)
{
//----------ʹÓÃÍⲿRC¾§Õñ-----------
RCC_DeInit(); //³õʼ»¯ÎªÈ±Ê¡Öµ
RCC_HSEConfig(RCC_HSE_ON); //ʹÄÜÍⲿµÄ¸ßËÙʱÖÓ
while(RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET); //µÈ´ýÍⲿ¸ßËÙʱÖÓʹÄܾÍÐ÷
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); //Enable Prefetch Buffer
FLASH_SetLatency(FLASH_Latency_2); //Flash 2 wait state
RCC_HCLKConfig(RCC_SYSCLK_Div1); //HCLK = SYSCLK
RCC_PCLK2Config(RCC_HCLK_Div1); //PCLK2 = HCLK
RCC_PCLK1Config(RCC_HCLK_Div2); //PCLK1 = HCLK/2
RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9); //PLLCLK = 8MHZ * 9 =72MHZ
RCC_PLLCmd(ENABLE); //Enable PLLCLK
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); //Wait till PLLCLK is ready
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); //Select PLL as system clock
while(RCC_GetSYSCLKSource()!=0x08); //Wait till PLL is used as system clock source
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_GPIOB,ENABLE );
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO ,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;//指令和数据输出管脚
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP ;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;//指令和数据管脚
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP ;
GPIO_Init(GPIOB,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;//读写管脚
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP ;
GPIO_Init(GPIOB,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;//使能管脚
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP ;
GPIO_Init(GPIOB,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;//用于12864的串并控制接12864的15脚
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP ;
GPIO_Init(GPIOB,&GPIO_InitStructure);
}
void LCDWiteCommand(u8 Command)
{
u8 LCDTemp = 0;
GPIO_ResetBits(GPIOB,GPIO_Pin_8);
GPIO_ResetBits(GPIOB,GPIO_Pin_9);
GPIO_SetBits(GPIOB,GPIO_Pin_10);
Delay_MS(10);
LCDTemp = LCDTemp | Command;
GPIO_Write(GPIOA, LCDTemp);
Delay_MS(10);
GPIO_ResetBits(GPIOB,GPIO_Pin_10);
Delay_MS(10);
}
void LCDWriteData(u8 Data)
{
u8 LCDTemp = 0;
GPIO_SetBits(GPIOB,GPIO_Pin_8);
GPIO_ResetBits(GPIOB,GPIO_Pin_9);
GPIO_SetBits(GPIOB,GPIO_Pin_10);
Delay_MS(10);
LCDTemp = LCDTemp | Data;
GPIO_Write(GPIOA, LCDTemp);
Delay_MS(10);
GPIO_ResetBits(GPIOB,GPIO_Pin_10);
Delay_MS(10);
}
void LCDCursorPosition(u8 x, u8 y)
{
u8 Position;
if (x==0)
{
x=0x80;
}
else if (x==1)
{
x=0x90;
}
else if (x==2)
{
x=0x88;
}
else if (x==3)
{
x=0x98;
}
Position = x + y;
LCDWiteCommand(Position);
}
void LCDInit(void)
{
LCDWiteCommand(0x30);
Delay_MS(50);
LCDWiteCommand(0x0c);
Delay_MS(50);
LCDWiteCommand(0x01);
Delay_MS(50);
LCDWiteCommand(0x06);
Delay_MS(50);
}
void LCDDisplay(u8 x, u8 y, u8 *Data)
{
LCDCursorPosition(x,y);
Delay_MS(50);
while(*Data != '\0')
{
LCDWriteData(*Data);
Data++;
Delay_MS(5);
}
}
|
|