001.
#include "stm32f10x.h"
002.
003.
004.
GPIO_InitTypeDef GPIO_InitStructure;
005.
#define RS_SET GPIO_SetBits(GPIOE, GPIO_Pin_2)
006.
#define RS_CLR GPIO_ResetBits(GPIOE, GPIO_Pin_2)
007.
008.
#define RW_SET GPIO_SetBits(GPIOE, GPIO_Pin_4)
009.
#define RW_CLR GPIO_ResetBits(GPIOE, GPIO_Pin_4)
010.
011.
012.
#define EN_SET GPIO_SetBits(GPIOE, GPIO_Pin_6)
013.
#define EN_CLR GPIO_ResetBits(GPIOE, GPIO_Pin_6)
014.
015.
016.
#define PSB_SET GPIO_SetBits(GPIOE, GPIO_Pin_3)
017.
#define PSB_CLR GPIO_ResetBits(GPIOE, GPIO_Pin_3)
018.
019.
020.
#define DATA_IO GPIOC->ODR
021.
022.
023.
void
RCC_Configuration(
void
);
024.
void
LCD12864_Config(
void
);
025.
void
Delay_nus(__IO uint32_t nCount);
026.
void
Delay_mus(__IO uint32_t nCount);
027.
uint8_t table[]=
"做我女朋友吧!"
;
028.
029.
030.
void
write_12864com(uint8_t com)
031.
{
032.
RW_CLR;
033.
RS_CLR;
034.
Delay_nus(500);
035.
DATA_IO=com;
036.
EN_SET;
037.
Delay_nus(1000);
038.
EN_CLR;
039.
Delay_nus(1000);
040.
}
041.
042.
043.
void
write_12864dat(uint8_t dat)
044.
{
045.
RW_CLR;
046.
RS_SET;
047.
Delay_nus(500);
048.
DATA_IO=dat;
049.
EN_SET;
050.
Delay_nus(1000);
051.
EN_CLR;
052.
Delay_nus(1000);
053.
}
054.
055.
056.
void
init12864lcd(
void
)
057.
{
058.
Delay_mus(500);
059.
write_12864com(0x30);
060.
Delay_nus(500);
061.
write_12864com(0x30);
062.
Delay_nus(500);
063.
write_12864com(0x0f);
064.
Delay_nus(500);
065.
write_12864com(0x01);
066.
Delay_nus(25);
067.
write_12864com(0x06);
068.
Delay_nus(2500);
069.
write_12864com(0x0c);
070.
Delay_nus(500);
071.
}
072.
073.
074.
void
display(
void
)
075.
{
076.
uint8_t i;
077.
write_12864com(0x80);
078.
for
(i=0;i<14;i++)
079.
{
080.
write_12864dat(table[i]);
081.
Delay_mus(50);
082.
}
083.
}
084.
085.
void
LCD12864_Config(
void
)
086.
{
087.
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE | RCC_APB2Periph_GPIOC , ENABLE);
088.
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_6;
089.
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
090.
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
091.
GPIO_Init(GPIOE, &GPIO_InitStructure);
092.
093.
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3
094.
|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
095.
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
096.
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
097.
GPIO_Init(GPIOC, &GPIO_InitStructure);
098.
}
099.
100.
101.
102.
int
main(
void
)
103.
{
104.
RCC_Configuration();
105.
LCD12864_Config();
106.
PSB_SET;
107.
init12864lcd();
108.
while
(1)
109.
{
110.
display();
111.
}
112.
}
113.
114.
115.
116.
void
RCC_Configuration(
void
)
117.
{
118.
SystemInit();
119.
}
120.
121.
122.
123.
void
Delay_nus(uint32_t nCount)
124.
{
125.
uint32_t j;
126.
while
(nCount--)
127.
{
128.
j=8;
129.
while
(j--);
130.
}
131.
}
132.
133.
134.
135.
void
Delay_mus(uint32_t nCount)
136.
{
137.
while
(nCount--)
138.
Delay_nus(1100);
139.
}