打印

stm32,LCD12864程序,不显示,求解析

[复制链接]
222|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
向日葵的武士|  楼主 | 2019-11-23 20:02 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include "stm32f10x.h"
#include "_12864_Config.h"
//简单延时函数
/*void delayms(uint8_t t)
{
t=t*500;
while(t--);
}*/
//延时nus
void delay_nus(unsigned long n)
{
  unsigned long j;
  while(n--)
{ j=8;
  while(j--);
}  
}
//延时nms
void DelayMs(unsigned char t)
{
while(t--)
delay_nus(1000);
}
//12864端口配置
void _12864_config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOA, ENABLE);
//12864控制口
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_3 | GPIO_Pin_7 | GPIO_Pin_6 | GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//12864数据口
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_Init(GPIOB, &GPIO_InitStructure);
}
//***************写命令***************
void write_com(uint8_t com)
{
RS(0);
RW(0);
E(0);
GPIO_Write(GPIOB, 0xff00&(com<<8));
DelayMs(1);
E(1);
DelayMs(5);
E(0);

}
//**************写数据***************
void write_data(uint8_t data)
{
RS(1);
RW(0);
E(0);
GPIO_Write(GPIOB, 0xff00&(data<<8));
DelayMs(1);
E(1);
DelayMs(5);
E(0);
}
//*****************写字符*************
void write_char(uint8_t x,uint8_t y,uint8_t data)
{
if(x==1)
  write_com(0x80+y);
if(x==2)
  write_com(0x90+y);
if(x==3)
  write_com(0x88+y);
if(x==4)
  write_com(0x98+y);
  write_data(data);
}
//*************写字符串****************
void write_string(uint8_t x,uint8_t y,uint8_t *s)
{
if(x==1)
  write_com(0x80+y);
if(x==2)
  write_com(0x90+y);
if(x==3)
  write_com(0x88+y);
if(x==4)
  write_com(0x98+y);
while(*s!='\0')
{
  write_data(*s);
  s++;
}
}
//************12864初始化配置**************
void _12864_Init(void)
{
DelayMs(2);
GPIO_ResetBits(GPIOA,GPIO_Pin_6);//复位
DelayMs(300);
GPIO_SetBits(GPIOA,GPIO_Pin_6);
DelayMs(5);
GPIO_SetBits(GPIOA,GPIO_Pin_5);//PSB端

write_com(0x30);//8位数据,基本指令
DelayMs(5);
write_com(0x01);//清屏
DelayMs(5);
write_com(0x0E);//整体显示,开游标及位置
DelayMs(5);
}

使用特权

评论回复

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

432

主题

439

帖子

0

粉丝