中级会员
 
- 积分
- 252
- 金钱
- 252
- 注册时间
- 2015-5-26
- 在线时间
- 31 小时
|
5金钱
/***********************************************************************
文件名称:QC12864.c
功 能:
编写时间:
编 写 人:
注 意:
***********************************************************************/
#include "stm32f10x.h"
//#include "SCI.H"
#include <includes.h>
//**********************************************************
//连线表: RS-> D8,R/W-> D9,E-> D10,PSB-> D11,/RET-> D12,(DB0~DB7-> E8~PE15)
//**********************************************************
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#define uchar unsigned char
#define uint unsigned int
/***********************************************************************
函数名称:QC12864_Configuration(void)
功 能:完成QC12864的配置
输入参数:
输出参数:
编写时间:
编 写 人:
注 意:
***********************************************************************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure; //定义结构
/* Enable the GPIO_KEY Clock */
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOE , ENABLE); //使能端口时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //输出速度
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //模式选择 推挽输出
GPIO_Init(GPIOE, &GPIO_InitStructure); //设置IO
//GPIO_Write(GPIOE ,0xffff);
//GPIO_InitTypeDef GPIO_InitStructure; //定义结构
/* Enable the GPIO_KEY Clock */
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOD , ENABLE); //使能端口时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //输出速度
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //模式选择 推挽输出
GPIO_Init(GPIOD, &GPIO_InitStructure); //设置IO
//GPIO_Write(GPIOD ,0xffff);
}
//延时函数:
void delays(unsigned char x);
void delays(unsigned char x)
{
while(x--);
}
//读忙状态
void rdbf();
void rdbf()
{
u16 RData;
u16 ReadValue_Bus=0x0080;
while(1)
{
loop: GPIO_ResetBits(GPIOD,GPIO_Pin_8); //RS=0
GPIO_SetBits(GPIOD,GPIO_Pin_9); //RW=1;
GPIO_ResetBits(GPIOD,GPIO_Pin_10); //E=0;
GPIO_SetBits(GPIOE,GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15); //LCDdata=0xFF;
delays(10);
GPIO_SetBits(GPIOD,GPIO_Pin_10); //E=1;
RData=GPIO_ReadOutputData(GPIOE); //这句先入这,如若不行,便放有E=1,上面那一行
if((RData&ReadValue_Bus)==0)
break;
else
goto loop;
}
}
//写数据
void wr_data(uchar wrdata);
void wr_data(uchar wrdata)
{
rdbf();
GPIO_SetBits(GPIOD,GPIO_Pin_8); //RS=1;
GPIO_ResetBits(GPIOD,GPIO_Pin_9); //RW=0;
GPIO_SetBits(GPIOD,GPIO_Pin_10); //E=1;
//LCDdata=wrdata;
if(wrdata&0x80)
GPIO_SetBits(GPIOE,GPIO_Pin_15); //
else
GPIO_ResetBits(GPIOE, GPIO_Pin_15);
if(wrdata&0x40)
GPIO_SetBits(GPIOE,GPIO_Pin_14);
else
GPIO_ResetBits(GPIOE, GPIO_Pin_14);
if(wrdata&0x20)
GPIO_SetBits(GPIOE,GPIO_Pin_13);
else
GPIO_ResetBits(GPIOE, GPIO_Pin_13);
if(wrdata&0x10)
GPIO_SetBits(GPIOE,GPIO_Pin_12);
else
GPIO_ResetBits(GPIOE, GPIO_Pin_12);
if(wrdata&0x08)
GPIO_SetBits(GPIOE,GPIO_Pin_11);
else
GPIO_ResetBits(GPIOE, GPIO_Pin_11);
if(wrdata&0x04)
GPIO_SetBits(GPIOE,GPIO_Pin_10);
else
GPIO_ResetBits(GPIOE, GPIO_Pin_10);
if(wrdata&0x02)
GPIO_SetBits(GPIOE,GPIO_Pin_9);
else
GPIO_ResetBits(GPIOE, GPIO_Pin_9);
if(wrdata&0x01)
GPIO_SetBits(GPIOE,GPIO_Pin_8);
else
GPIO_ResetBits(GPIOE, GPIO_Pin_8);
GPIO_ResetBits(GPIOD,GPIO_Pin_10); //E=0;
}
//写指令
void wr_cmd(uchar cmd,uchar busys);
void wr_cmd(uchar cmd,uchar busys)
{
if(busys)
rdbf(); //当BF=0时,模块内部方可接收新的指令
GPIO_ResetBits(GPIOD,GPIO_Pin_8); //RS=0;
GPIO_ResetBits(GPIOD,GPIO_Pin_9); //RW=0;
GPIO_SetBits(GPIOD,GPIO_Pin_10); //E=1;
//LCDdata=cmd;
if(cmd&0x80)
GPIO_SetBits(GPIOE,GPIO_Pin_15);
else
GPIO_ResetBits(GPIOE, GPIO_Pin_15);
if(cmd&0x40)
GPIO_SetBits(GPIOE,GPIO_Pin_14);
else
GPIO_ResetBits(GPIOE, GPIO_Pin_14);
if(cmd&0x20)
GPIO_SetBits(GPIOE,GPIO_Pin_13);
else
GPIO_ResetBits(GPIOE, GPIO_Pin_13);
if(cmd&0x10)
GPIO_SetBits(GPIOE,GPIO_Pin_12);
else
GPIO_ResetBits(GPIOE, GPIO_Pin_12);
if(cmd&0x08)
GPIO_SetBits(GPIOE,GPIO_Pin_11);
else
GPIO_ResetBits(GPIOE, GPIO_Pin_11);
if(cmd&0x04)
GPIO_SetBits(GPIOE,GPIO_Pin_10);
else
GPIO_ResetBits(GPIOE, GPIO_Pin_10);
if(cmd&0x02)
GPIO_SetBits(GPIOE,GPIO_Pin_9);
else
GPIO_ResetBits(GPIOE, GPIO_Pin_9);
if(cmd&0x01)
GPIO_SetBits(GPIOE,GPIO_Pin_8);
else
GPIO_ResetBits(GPIOE, GPIO_Pin_8);
GPIO_ResetBits(GPIOD,GPIO_Pin_10); //E=0;
}
//确定行、列号,并显示数据
void display(uchar x,uchar y,uchar *seg);
void display(uchar x,uchar y,uchar *seg) //x为行号,y为列号
{
uchar i;
uint t=0;
switch(x) //确定行号
{
case 1: i=0x80; break; //第一行
case 2: i=0x90; break; //第二行
case 3: i=0x88; break; //第三行
case 4: i=0x98; break; //第四行
default : break;
}
i=x+y;
wr_cmd(i,1); //确定列号
while(seg[t]!='\0')
{
wr_data(seg[t]); //写入需要显示字符的显示码
t++;
}
}
//Lcd写数据初始化
void lcd_init(void)
{
delays(5000000);
GPIO_SetBits(GPIOD,GPIO_Pin_12); //RST=1; 复位脚
GPIO_ResetBits(GPIOD,GPIO_Pin_12); //RST=0; 低电平复位
GPIO_SetBits(GPIOD,GPIO_Pin_12); //RST=1;
wr_cmd(0x30,0);
delays(50000);
wr_cmd(0x30,0); //2次功能模式设置,不用判忙(基本指令)
delays(50000);
wr_cmd(0x0c,1); //整体显示,光标及其设置不显示
delays(50000);
wr_cmd(0x01,1); //清屏
delays(50000);
delays(50000);
wr_cmd(0x06,1); //光标右移
delays(50000);
}
//读数据
uchar read_data(void);
uchar read_data(void)
{
u8 RData;
u16 RData_32b;
GPIO_SetBits(GPIOE,GPIO_Pin_8); //LCDdata=0xff;
GPIO_SetBits(GPIOE,GPIO_Pin_9);
GPIO_SetBits(GPIOE,GPIO_Pin_10);
GPIO_SetBits(GPIOE,GPIO_Pin_11);
GPIO_SetBits(GPIOE,GPIO_Pin_12);
GPIO_SetBits(GPIOE,GPIO_Pin_13);
GPIO_SetBits(GPIOE,GPIO_Pin_14);
GPIO_SetBits(GPIOE,GPIO_Pin_15);
rdbf();
GPIO_SetBits(GPIOD,GPIO_Pin_8); //RS=1;
GPIO_SetBits(GPIOD,GPIO_Pin_9); //RW=1;
GPIO_ResetBits(GPIOD,GPIO_Pin_10); //E=0;
GPIO_SetBits(GPIOD,GPIO_Pin_10); //E=1;
RData_32b=GPIO_ReadOutputData(GPIOE);
RData=(u8)(RData_32b&0x00FF);
return RData;
}
//GDRAM初始化
void clr_GDRAM(void) //行列扫描
{
uchar x,y;
for(y=0;y<64;y++)
for(x=0;x<16;x++)
{
wr_cmd(0x34,1);
wr_cmd(y+0x80,1); //行地址
wr_cmd(x+0x80,1); //列地址
wr_cmd(0x30,1);
wr_data(0x00);
wr_data(0x00);
}
}
/**************************************************************************************
*主函数说明
*显示数据(每行最多显示8个汉字,或16个字符)
**************************************************************************************/
void qc12864_dis(void)
{
uchar string_1[]="你好";
uchar string_2[]="0123456789";
lcd_init();
display(1,1,string_1);
display(3,1,string_2);
}
|
|