#include"stm32f10x_lib.h"
//定義LCD的RS,RW,EN=0時分別是 Set_RS,Set_RW,Set_EN
#define Set_RS (GPIO_SetBits(GPIOB,GPIO_Pin_0))
#define Set_RW (GPIO_SetBits(GPIOB,GPIO_Pin_1))
#define Set_EN (GPIO_SetBits(GPIOB,GPIO_Pin_2))
//定義RS,RW,EN=1時分別是CLR_RS,CLR_RW,CLR_EN
#define CLR_RS (GPIO_ResetBits(GPIOB,GPIO_Pin_0))
#define CLR_RW (GPIO_ResetBits(GPIOB,GPIO_Pin_1))
#define CLR_EN (GPIO_ResetBits(GPIOB,GPIO_Pin_2))
GPIO_InitTypeDef GPIO_InitStructure;
ErrorStatus HSEStartUpStatus;
void Delay(u32 count)
{ //定義無符號長整型變量count
for(;count!=0;count--);
}
unsigned char table[]="liushuai";
unsigned char table1[]="2009.12.21";
//寫指令
void Send_Com(unsigned char Send_Com)
{
u16 Temp;//定義短整型變量Temp,由于STM32F103C8的GPIOA恰好有16個IO口。
Delay(0xAFFFF);
CLR_RS;
Temp=GPIO_ReadOutputData(GPIOA);//讀回GPIOA發送寄存器的數據。
Temp&=0xff00;//將GPIOA的高8位保留,低8位清0.
Temp|=(u16)Send_Com;//將char型變量Send_Com強制轉換成short(短整型),其中高8位由0代替,低8位是Send_Com的值
GPIO_Write(GPIOA,Temp);
Delay(100);
Set_EN;
Delay(100);
CLR_EN;
}
//寫數據
void Send_Dat(unsigned char Send_Dat)
{
u16 Temp;//定義短整型變量Temp,由于STM32F103C8的GPIOA恰好有16個IO口。
Set_RS;
Temp=GPIO_ReadOutputData(GPIOA);//讀回發送寄存器內的數據
Temp&=0xff00;
Temp|=(u16)Send_Dat;
GPIO_Write(GPIOA,Temp);
Delay(100);
Set_EN;
Delay(500);
CLR_EN;
}
void init()
{
CLR_EN;
//Delay(0xAFFF);
Send_Com(0x38); //置初值//
Send_Com(0x0c);
Send_Com(0x06);
Send_Com(0x80);
}
void GPIO_Configuration(void)
{
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2;
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_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_Init(GPIOA,&GPIO_InitStructure);
}
void RCC_Configuration(void)
{
RCC_DeInit();
RCC_HSEConfig(RCC_HSE_ON);
HSEStartUpStatus= RCC_WaitForHSEStartUp();
if(HSEStartUpStatus==SUCCESS)
{
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK2Config(RCC_HCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div2);
FLASH_SetLatency(FLASH_Latency_2);
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);
RCC_PLLCmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY)==RESET)
{
}
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
while(RCC_GetSYSCLKSource()!=0x08)
{
}
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
RCC_APB2Periph_GPIOC , ENABLE);
}
}
int main(void)
{
#ifdef DEBUG
debug();
#endif
unsigned char num;
RCC_Configuration();
GPIO_Configuration();
init();
for(;;)
{
for(num=0;num<8;num++)
{
Send_Dat(table[num]);
Delay(2000000);
}
//while(1);
//Send_Com(0x01);
Delay(20000);
Send_Com(0x80+0x40);
for(num=0;num<10;num++)
{
Send_Dat(table1[num]);
Delay(2000000);
}
while(1);
}
}
|