首页 > 其他分享 >STM32串行通信驱动LCD12864(使用5V电源,驱动信号用5VFT的引脚(3.3V MCU))

STM32串行通信驱动LCD12864(使用5V电源,驱动信号用5VFT的引脚(3.3V MCU))

时间:2024-04-05 21:34:38浏览次数:29  
标签:0xC0 5VFT 引脚 0x00 0x03 GPIO 0xFF 驱动 0x0C

#include "spi.h"
 

void SPI_GPIO_Init(void)
{
    //hardware make PSB low to enable serial communication
    GPIO_InitTypeDef   GPIO_InitStruct;

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);

    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10;
    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_Init(GPIOB, &GPIO_InitStruct);

    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_11;
    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_Init(GPIOB, &GPIO_InitStruct);

    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_12;
    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;

    
    GPIO_Init(GPIOB, &GPIO_InitStruct);
}

void SPI_SID_IN(void)
{
    GPIO_InitTypeDef   GPIO_InitStruct;

    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU;
    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_12;
    

    GPIO_Init(GPIOB, &GPIO_InitStruct);
}

void SPI_SID_OUT(void)
{
    GPIO_InitTypeDef   GPIO_InitStruct;

    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_12;
    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_Init(GPIOB, &GPIO_InitStruct);
}
void SPI_Start(void)
{
    SPI_SID_L;
    Delayus(10);
    SPI_CLK_L;
    Delayus(10);
    SPI_CS_L;
    Delayus(10);
    SPI_CS_H;
}
void SPI_Stop(void)
{
    SPI_CS_L;
    Delayus(10);
//    SPI_SID_H;
//    Delayus(10);
//    SPI_CLK_H;
}
void SPI_Write(unsigned char data)
{
    uint8_t i = 0;
    for(i = 0; i < 8; i ++)
    {
        if((data&0x80) == 0x80)                             
        {                                                  
            SPI_SID_H;                                     
        }                                                  
        else                                              
        {                                                  
            SPI_SID_L;                                      
        }                                                  
        Delayus(10);                                      
                                                          
        SPI_CLK_H;
        Delayus(10);
        

        SPI_CLK_L;
        data = data << 1;
        Delayus(10);
    }
    
     
}

unsigned char SPI_Read(void)
{
    uint8_t i = 0;
    unsigned char val = 0;
    SPI_SID_IN();
    for(i = 0; i < 8; i ++)                                                   
    {
        val = val << 1;                                              
        
        SPI_CLK_H;                                                  
        Delayus(10);
                                                                  
        if(GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_12))                             
        {                                                            
            val |= 0x01;                                           
        }                                                            
        else                                                        
        {                                                            
            val |= 0x00;                                      
        }                                                  
        Delayus(10);

        SPI_CLK_L;
        
        Delayus(10);
    }
    return val;

}
void SPI_WriteCmd(unsigned char cmd)//0xf8 write cmd;0xfa write data;
{
    unsigned char high4bit = 0, low4bit = 0;
    SPI_Start();
    high4bit = (cmd & 0xF0);
    low4bit = ((cmd << 4)&0xF0);
    SPI_Write(0xF8);
    SPI_Write(high4bit);
    SPI_Write(low4bit);


    SPI_Stop();


}

void SPI_WriteData(unsigned char data)
{
    unsigned char high4bit = 0, low4bit = 0;
    SPI_Start();
    high4bit = (data & 0xF0);
    low4bit = ((data << 4)&0xF0);
    SPI_Write(0xFA);
    SPI_Write(high4bit);
    SPI_Write(low4bit);

    SPI_Stop();

}

uint8_t SPI_ReadCmd(void)//0xfc read cmd;0xfe read data;
{
    unsigned char high4bit = 0, low4bit = 0, val = 0;
    SPI_Start();
    
    SPI_Write(0xFC);
    high4bit = SPI_Read();
    low4bit =  SPI_Read();

    SPI_Stop();

    val = (high4bit+(low4bit >> 4));

    
    return val;

}

uint8_t SPI_ReadData(void)
{
    unsigned char high4bit = 0, low4bit = 0, val = 0;
    SPI_Start();
    
    SPI_Write(0xFE);
    high4bit = SPI_Read();
    low4bit =  SPI_Read();

    SPI_Stop();

    val = (high4bit+(low4bit >> 4));

    
    return val;
}

void WriteStr(unsigned char *s)
{
    while(*s != '\0')
    {
        SPI_WriteData(*s);
        s ++;

    }
}

void LCD_PutGraphic(const unsigned char *img)
{ 
 int i,j;
//显示上半屏内容设置
   for(i=0;i<32;i++)            
    { 
      SPI_WriteCmd(0x80 + i); //SET  垂直地址 VERTICAL ADD
      SPI_WriteCmd(0x80);     //SET  水平地址 HORIZONTAL ADD
      for(j=0;j<16;j++)
       {
         SPI_WriteData(*img);
         img++;
       }
    }
//显示下半屏内容设置
   for(i=0;i<32;i++)            
    {
      SPI_WriteCmd(0x80 + i); //SET 垂直地址 VERTICAL ADD
      SPI_WriteCmd(0x88);     //SET 水平地址 HORIZONTAL ADD
      for(j=0;j<16;j++)
       {
         SPI_WriteData(*img);
         img++;
       }
    }  
           
}
#include "stm32f10x.h"

#include "delay.h"

#include "led.h"
#include "spi.h"

//12864是5V电源供电才行;数据时钟用3.3VMCU输出即可,用FT5V引脚

const unsigned char pic1[]=      // 图片代码
{
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x1F,0xFF,0x81,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x1F,0xFF,0x81,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x18,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x08,0x00,0x00,0x00,0x03,
0xC0,0x1F,0xFF,0x80,0x00,0x00,0x04,0x07,0x81,0xE0,0x10,0x10,0x03,0xC0,0x30,0x03,
0xC0,0x1F,0xFF,0x80,0x00,0x00,0x0C,0x0C,0xC3,0x30,0x08,0x20,0x0C,0xE0,0x70,0x03,
0xC0,0x18,0x01,0x87,0xFF,0xFE,0x3C,0x18,0x66,0x18,0x04,0x40,0x0C,0x60,0x70,0x03,
0xC0,0x1F,0xFF,0x87,0xFF,0xFE,0x0C,0x18,0x66,0x18,0x02,0x80,0x18,0x00,0xB0,0x03,
0xC0,0x1F,0xFF,0x80,0x06,0x00,0x0C,0x18,0x66,0x18,0x01,0x00,0x1B,0x81,0x30,0x03,
0xC0,0x01,0x98,0x00,0x06,0x00,0x0C,0x00,0xE3,0x30,0x02,0x80,0x1C,0xC1,0x30,0x03,
0xC0,0x19,0x99,0x80,0x66,0x60,0x0C,0x00,0xC1,0xE0,0x04,0x40,0x18,0x62,0x30,0x03,
0xC0,0x19,0x99,0x80,0x66,0x30,0x0C,0x01,0x83,0x30,0x08,0x20,0x18,0x66,0x30,0x03,
0xC0,0x0D,0x9B,0x00,0xC6,0x38,0x0C,0x03,0x06,0x18,0x10,0x10,0x18,0x67,0xFC,0x03,
0xC0,0x0D,0x9B,0x01,0xC6,0x1C,0x0C,0x06,0x06,0x18,0x20,0x08,0x18,0x60,0x30,0x03,
0xC0,0x01,0x98,0x03,0x86,0x0C,0x0C,0x0C,0x06,0x18,0x00,0x00,0x08,0x60,0x30,0x03,
0xC0,0x7F,0xFF,0xE3,0x06,0x00,0x0C,0x18,0x03,0x30,0x00,0x00,0x0C,0xC0,0x30,0x03,
0xC0,0x7F,0xFF,0xE0,0x1E,0x00,0x0C,0x1F,0xE1,0xE0,0x00,0x00,0x07,0x80,0x30,0x03,
0xC0,0x00,0x00,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x18,0x00,0x00,0x00,0x06,0x0C,0x03,
0xC3,0xFF,0xFC,0x3F,0xF0,0x80,0x0C,0x00,0x3F,0x18,0x01,0xFF,0xFE,0x06,0x0C,0x03,
0xC3,0xFF,0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3,0xFF,0xFC,0x70,0xDE,0x03,0x18,0xC6,0x30,0x06,0x01,0xFF,0xFE,0x0C,0x03,0x03,
0xC3,0xFF,0xFC,0x20,0x18,0x03,0x18,0xC6,0x30,0x06,0x01,0xFF,0xFE,0x18,0x03,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,

};
int main(void)
{
    Delay_Init();
    LED_GPIO_Init();
    SPI_GPIO_Init();
    
    Delayus(10000);
    SPI_WriteCmd(0x30);
    Delayus(1000);
    SPI_WriteCmd(0x30);
    Delayus(1000);
    SPI_WriteCmd(0x0c);
    Delayus(10000);
    SPI_WriteCmd(0x01);
    Delayus(10000);

    SPI_WriteCmd(0x06);
    Delayus(10000);

//    SPI_WriteCmd(0x80);
//    WriteStr("你好");

    SPI_WriteCmd(0x36);
    Delayus(10000);

    LCD_PutGraphic(pic1);
    while(1)
    {
                
    }
    
}

 

标签:0xC0,5VFT,引脚,0x00,0x03,GPIO,0xFF,驱动,0x0C
From: https://www.cnblogs.com/chillytao-suiyuan/p/18116237

相关文章

  • 嵌入式Linux驱动开发-第一个驱动程序hello
    前言,没事就碎碎念以前跟着正点原子的文档做过一两个简单驱动程序实验,但是总感觉思路不够清晰,后面看韦东山的视频,发现二者结合起来刚好合适,其中韦东山视频理论和框架讲的清楚,正点原子的更像是他们开发板的使用手册。一开始学习驱动,我感觉比较合适的路线是先简单过一遍裸机,跟着正......
  • 领域驱动设计集成与架构
    ​ 领域驱动设计(Domain-DrivenDesign,DDD)是一种软件开发方法论,旨在通过将项目中心放在核心业务领域和领域逻辑上来简化复杂软件项目的开发。这种方法论强调使用一种通用的语言(UbiquitousLanguage)在开发人员和业务专家之间进行沟通,以确保软件严密地与业务需求对齐。有关集成与......
  • 驱动对象和设备对象数据结构
    驱动对象:每个驱动程序都会有唯一的驱动对象与之对应,并且这个驱动对象是在驱动加载时被内核中的对象管理程序所创建的。驱动对象用DRIVER_OBJECT数据结构表示,它作为驱动的一个实例被内核中的I/O管理器负责加载,并且内核对一个驱动只加载一个实例。驱动程序需要在DriverEntry中......
  • linux驱动-17-input子系统
    1input子系统介绍按键、鼠标、键盘、触摸屏等都属于输入(input)设备,Linux内核为此专门做了一个叫做input子系统的框架来处理输入事件。input子系统分为input驱动层、input核心层、input事件处理层,最终给用户空间提供可访问的设备节点。驱动层:输入设备的具体驱动程序,......
  • VMware ESXi 6.7U3t macOS Unlocker & OEM BIOS 集成 Realtek 网卡驱动和 NVMe 驱动 (
    VMwareESXi6.7U3tmacOSUnlocker&OEMBIOS集成Realtek网卡驱动和NVMe驱动(集成驱动版)UIfix此版本解决的问题:VMwareHostClient无法将现有虚拟磁盘(VMDK)附加到虚拟机请访问原文链接:https://sysin.org/blog/vmware-esxi-6-sysin/,查看最新版。原创作品,转载请保......
  • 设备驱动-16-Linux 内核LED子系统
    1LED子系统介绍led子系统相关描述可在内核源码Documentation/leds/leds-class.txt了解。led子系统是一个简单的Linux子系统,在目录/sys/class/leds下展示该子系统设备,每个设备都有自己的属性:brightness:设置LED亮度,范围0~max_brightnessmax_brightness:最大亮度......
  • Linux内核中的通用PHY驱动
    一. 简介前面一篇文章说明了有线网络的网络硬件方案。常用到的一种方案是:内部集成了MAC网络外设的SOC芯片(处理器),外接一个PHY网络芯片。前面文章也学习了Linux内核中的PHY子系统,也是为(上面这种方案)PHY网络芯片提供的驱动框架。Linux内核内部提供了通用的PHY驱动。本文来学......
  • kali linux 解决无线驱动程序问题
    TroubleshootingwirelessdriverissuesinLinuxcanbeafrustratingexperienceifyoudon’tknowwhattolookfor。Thisarticleismeanttobeusedasageneralguidelinetobetterhelpyoufindtheinformationyouneedtosolveyourwirelessissues。C......
  • 芯片电源引脚旁应该加多大电容?
    芯片电源引脚旁应该加多大电容?在设计电路的时候,常常会在芯片的每个电源引脚就近的放一个100nF的贴片电容,这电容有什么作用呢?为什么是100nF。首先这个芯片电源引脚的100nF的电容一般我们称为旁路电容,也有叫去耦电容的,因为这颗电容的作用比较多,个人觉得叫旁路和去耦电容都没问题,......
  • 点阵LED数码管显示驱动IC VK16K33 A/B/C/BA/AA 驱动电流大 质量稳定 适用于计量插座,数
    VK16K33是一种带按键扫描接口的数码管或点阵LED驱动控制专用芯片,内部集成有数据锁存器、键盘扫描、LED驱动模块等电路。数据通过I2C通讯接口与MCU通信。SEG脚接LED阳极,GRID脚接LED阴极,可支持16SEGx8GRID的点阵LED显示面板。最大支持13×3的按键。内置上电复位电路,整体闪烁频率可......