本人使用的STM32F0编写的LCM12864k的程序 求大家指点

2019-07-16 09:26发布

12864用的是北京青云的LCM12864K,PA0对复位引脚,PA1对应CS1,PA2对应A0,PB1对应SI,PB0对应SCL控制时钟,采用串口方式
#include <STM32f0xx.h>
GPIO_InitTypeDef        GPIO_InitStructure;


void Delay(__IO uint32_t nCount)
{
  for(; nCount != 0; nCount--);
}


/*****************************************************
*函数名:GPIO_Config()                   *输出结果:无
*函数描述:设置GPIO端口的功能           *返回值:无
*输入参数:无
********************************************************/
void GPIO_Config()//IO端口的初始化
{
        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
  //打开AHP总线上的GPIOC的时钟       
       
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1;
  //选择GPIOC的8、9端口
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
// 设置端口为输出模式
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  //把GPIOC的8、9端口设置为推挽模式
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
//GPIO初始化
       
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
  //选择GPIOC的8、9端口
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
// 设置端口为输出模式
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  //把GPIOC的8、9端口设置为推挽模式
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
//GPIO初始化
}
void Sendbyte(__IO uint32_t dat)//发送位数据
{
        __IO uint32_t i;
        for(i=0;i<8;i++)
                {
                        if(dat&0x80)        //赋值一位数据
                                GPIO_SetBits(GPIOB, GPIO_Pin_1);//SI=1
                        else
                                GPIO_ResetBits(GPIOB, GPIO_Pin_1);//SI=0
                        Delay(0x3f);
                        GPIO_SetBits(GPIOB, GPIO_Pin_0);//SCL置高
                                Delay(0x3f);
      GPIO_ResetBits(GPIOB, GPIO_Pin_0);//SCL置低
                                Delay(0x3f);
      GPIO_SetBits(GPIOB, GPIO_Pin_0);//SCL置高                               
                        dat=dat<<1;                //左移一位数据,继续向SI赋值数据
                }
}
void write_com(__IO uint32_t com)//控制命令
{       
  GPIO_SetBits(GPIOB, GPIO_Pin_0);                                               
        GPIO_ResetBits(GPIOA, GPIO_Pin_1);        //CS1=0
        GPIO_ResetBits(GPIOA, GPIO_Pin_2);        //A0=0
        Sendbyte(com&0xf0);                        //送高四位指令
        Sendbyte((com&0x0f)<<4);        //送低四位指令
        GPIO_SetBits(GPIOA, GPIO_Pin_1);        //CS1=1                                       
}

void write_date(__IO uint32_t date)
{       
  GPIO_SetBits(GPIOB, GPIO_Pin_0);                                               
        GPIO_ResetBits(GPIOA, GPIO_Pin_1);        //CS1=0
        GPIO_SetBits(GPIOA, GPIO_Pin_2);        //A0=1
        Sendbyte(date&0xf0);                        //送高四位指令
        Sendbyte((date&0x0f)<<4);        //送低四位指令
        GPIO_SetBits(GPIOA, GPIO_Pin_1);        //CS1=1
}
void clear()
{
  uint32_t i,page;
        for(page=0;page<8;page++)
        {
                write_com(0xb0|page);
                write_com(0x10);
                write_com(0x01);
                for(i=0;i<128;i++)
                        write_date(0x00);
               
   }
}
void Init()
{
        GPIO_SetBits(GPIOA, GPIO_Pin_0);        //RES=1
        Delay(0x3f);
        GPIO_ResetBits(GPIOA, GPIO_Pin_0);        //RES=0
        Delay(0x3f);
        GPIO_ResetBits(GPIOA, GPIO_Pin_0);       
  write_com(0xe2);//复位
        write_com(0x2f);//工作状态设置
        write_com(0x81);
        write_com(0x31);
        write_com(0xa2);
        write_com(0xa0);
        write_com(0xc0);
        write_com(0x40);
        write_com(0xaf);
        //write_com(0xa5);
}
int main(void)
{
  __IO uint32_t i,page;
   GPIO_Config();
         Init();
        clear();
        while(1)
                {
                       
                                for(page=0;page<8;page++)
        {
                write_com(0xb0|page);
                write_com(0x10);
                write_com(0x01);
                for(i=0;i<128;i++)
                        write_date(0xFF);
               
   }
               
    }

}


友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
2条回答
946663963
1楼-- · 2019-07-16 12:02
 精彩回答 2  元偷偷看……
愤怒的企鹅
2楼-- · 2019-07-16 13:24
清屏可以写一个命令清的,不知道你这款有没,我之前用的就有

一周热门 更多>