stm32 12864 driver

Publisher:闪耀的星空Latest update time:2016-10-13 Source: elecfansKeywords:stm32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/********************************************************************
[File name] lcd12864.h
[Function description] lcd12864 header file
**********************************************************************/

#ifndef __LCD12864_H
#define __LCD12864_H

//****************************************************************
#include "stm32f10x_gpio.h"
#include "systick_delay.h"

//************************************************************************
//Pin definition

#define GPIO_LCD    GPIOE  
#define RCC_APB2Periph_GPIO_LCD    RCC_APB2Periph_GPIOE
//片选
#define LCD_CS_1    GPIO_LCD->BSRR = GPIO_Pin_8
#define LCD_CS_0    GPIO_LCD->BRR = GPIO_Pin_8
//数据
#define LCD_SID_1   GPIO_LCD->BSRR = GPIO_Pin_9
#define LCD_SID_0   GPIO_LCD->BRR = GPIO_Pin_9
//同步时钟
#define LCD_CLK_1   GPIO_LCD->BSRR = GPIO_Pin_10
#define LCD_CLK_0   GPIO_LCD->BRR = GPIO_Pin_10
//复位 低电平复位
#define LCD_RET_1   GPIO_LCD->BSRR = GPIO_Pin_11
#define LCD_RET_0   GPIO_LCD->BRR = GPIO_Pin_11

#define LCD_Write_Con_Cmd    (uc32)0xf8000000 // 1111 1000 0000 0000 0000 0000 0000 0000
#define LCD_Write_Dis_Data   (uc32)0xfa000000 // 1111 1010 0000 0000 0000 0000 0000 0000

//********************Function declaration****************************** **********
void LCD_Port_Config(void);
void LCD_Init(void);
void LCD_Write(u32 inst, u8 ddata);
void LCD_Dis_Str(u8 row, u8 col, u8 *str);
void LCD_Dis_Digital(u8 row, u8 col,u32 Dig_Data);
void LCD_Clear(void);
void LCD_Reset(void);
void LCD_Dis_Frame(void);
void LCD_Clear_GDRAM(void);
void LCD_Clear_Graphics(u8 row, u8 col, u8 row_Pixel, u8 col_Pixel);
void LCD_Dis_Graphics(u8 row, u8 col, u8 row_Pixel, u8 col_Pixel, u8 *Dis_Data);
/****************************** *************************************
         LCD module instruction set definition
************ *************************************************** *****
      0x01 // Clear display command
      0x06 // Set input mode
      0x0c // Set display control
      0x30 // Function setting (basic command)
      0x34 // Function setting (extended command)
      0x36 // Open drawing (extended command)
** ************************************************** *************/

#endif

/********************************************************************************
【File name】lcd12864.c
【Function description】lcd12864 driver
【Author】shifu
********************************************************************************/

/**************************************************************************/
#include "lcd12864.h"
#include "stm32f10x_lib.h"

/********************************************************************************
【Function description】I/O port function, direction setting
****************************************************************************/
void LCD_Port_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;

/* Enable port clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_LCD, ENABLE);

/* Configure the pins used for push-to-play output and the port speed to 50MHz*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed ​​= GPIO_Speed_50MHz;

GPIO_Init(GPIO_LCD, &GPIO_InitStructure);    
}

/****************************************************************************
【Function description】 LCD write byte function
Entry parameter inst=cmd/data: command/data flag (data: write display data cmd: write control instruction)
                         x: command/data byte
****************************************************************************/

void LCD_Write(u32 inst, u8 ddata)
{
u32 temp = inst;
u32 i,t;
temp |= ((u32)(ddata & (u8)0xf0) << 16) + ((u32)(ddata & (u8)0x0f) << 12);
LCD_CS_1; //Select 12864
//Pull down the CLK pin to prepare for a rising edge
LCD_CLK_0;   
//Serially transmit 24 binary bits
for(i=0;i<24;i++)                  
   {     
      if(temp & 0x80000000) LCD_SID_1;   
      else LCD_SID_0;
     
      //Pull up the CLK pin to generate a rising edge, and the highest bit is transmitted to the LCD module
      LCD_CLK_1;  
      t = 0x10; while(t--); //Delay LCD to read data
     
       //Pull down the CLK pin to prepare for a rising edge
      LCD_CLK_0;                    
    
      //Shift left one bit to prepare the next bit to be transmitted
      temp = temp<<1;
   }
LCD_CS_0; //Uncheck 12864
}

/****************************************************************************
【Function description】
   LCD string display function: void LCD_Dis_Str(u8 x, u8 y, u8 *str);
   Input parameter row: The row where the string starts to be displayed
             col: The column where the string starts to be displayed
             str: The character pointer pointing to the string to be displayed, the string ends with '\0'
Note: The encoding of CGRAM and Chinese fonts can only appear at the start position of adress counter
DDRAM 8*16 bytes space
Line1 80H 81H 82H 83H 84H 85H 86H 87H
Line2 90H 91H 92H 93H 94H 95H 96H 97H
Line3 88H 89H 8AH 8BH 8CH 8DH 8EH 8FH
Line4 98H 99H 9AH 9BH 9CH 9DH 9EH 9FH

Line5 A0H A1H A2H A3H A4H A5H A6H A7H
Line6 B0H B1H B2H B3H B4H B5H B6H B7H
Line7 A8H A9H AAH ABH ACH ADH AEH AFH
Line8 B8H B9H BAH BBH BCH BDH BEH BFH
********************************************************************************/
void LCD_Dis_Str(u8 row, u8 col, u8 *str)
{
    u8 addr, i = 0;
    //Prevent misoperation (debugging)
// if(row > 3) row = 3;
// if(col > 7) col = 7;
   
    //Determine the display buffer address according to the x,y coordinatesswitch
    (row)                                    
     {
        case 0: addr = 0x80 + col; break;
        case 1: addr = 0x90 + col; break;
        case 2: addr = 0x88 + col; break;
        case 3: addr = 0x98 + col; break;
     }
   
//Set the DDRAM address
LCD_Write(LCD_Write_Con_Cmd, addr);                                           

while(*str)
   {          
     //Next line: Write characters from the set DDRAM address and prepare a pointer to the next character
      LCD_Write(LCD_Write_Dis_Data, *str++);
      i++;
      if(i==2)
       {
         i = 0;
        
          //The DDRAM address will automatically increment every time two bytes are written to track the address changes of DDRAM so that the line can be adjusted
         addr++;
        
         //When addr=88H,90H,98H,a0H, it means that the DRAM address needs to be reassignedif
         ( (addr&0x07) == 0 )
          {
            switch(addr)
             {
                case 0x88: addr = 0x90; break;
                case 0x98: addr = 0x88; break;
                case 0x90: addr = 0x98; break;
                case 0xa0: addr = 0x80; break;
             }
            //Set the reassigned DDRAM address
            LCD_Write(LCD_Write_Con_Cmd, addr);                  
          }
       }
   }
}


/****************************************************************************
【Function description】 LCD clear screen
************************************************************************/
void LCD_Clear(void)
{
   LCD_Write(LCD_Write_Con_Cmd, 0x01);
   ST_Delay_Ms(5);
}

/****************************************************************************
【Function description】 LCD reset
************************************************************************/
void LCD_Reset(void)
{
   LCD_RET_0;
   ST_Delay_Ms(50);
   LCD_RET_1;
   ST_Delay_Ms(100);
}

/****************************************************************************
【Function description】 Initialize LCD subroutine
**********************************************************************/
void LCD_Init(void)  
{
   //Port configuration
   LCD_Port_Config();
  
   //LCD reset
   LCD_Reset();
  
   //Basic instruction set 8-bit data
   LCD_Write(LCD_Write_Con_Cmd,0x30);
   ST_Delay_Ms(1);
   //Basic instruction set 8-bit data
   LCD_Write(LCD_Write_Con_Cmd,0x30);
   ST_Delay_Ms(1);
  
   //Display on, cursor off, reverse off
   LCD_Write(LCD_Write_Con_Cmd,0x0C);
   ST_Delay_Ms(1);
    //Clear screen
   LCD_Clear();
  
   //DDRAM address counter (AC) plus 1
   LCD_Write(LCD_Write_Con_Cmd,0x06);
                        
}
/**********************************************************************************
【Function description】 Display decimal number
   entry parameter row: row
             col: column
      Dig_Data: displayed decimal number
**************************************************************************/
void LCD_Dis_Digital(u8 row, u8 col,u32 Dig_Data)
{
u8 dd[11];
u8 i,j=9;
u32 temp;
temp = Dig_Data;
dd[10]=0;
for(i=10;(i>j)&(i>0);i--)
   {
     dd[i-1] = temp%10 + '0';
     temp=temp/10;
     if(temp) j--;
   }
LCD_Dis_Str(row,col,&dd[i]);
}
/********************************************************************************
【Function description】 LCD display frame graphics mode
******************************************************************************/
void LCD_Dis_Frame(void)
{
u8 x,y;
//LCD clear drawing RAM
LCD_Clear_GDRAM();
LCD_Write(LCD_Write_Con_Cmd,0x34);
LCD_Write(LCD_Write_Con_Cmd,0x36);
for(x=0;x<9;x += 8)
   {
      for(y=0;y < 32;y++)
          {   
            //left vertical
            LCD_Write(LCD_Write_Con_Cmd, y+0x80);//row address
            LCD_Write(LCD_Write_Con_Cmd, x+0x80);//column address
            LCD_Write(LCD_Write_Dis_Data,0x80);
            LCD_Write(LCD_Write_Dis_Data,0x00 );
            //Right vertical
            LCD_Write(LCD_Write_Con_Cmd, y+0x80);//Row address
            LCD_Write(LCD_Write_Con_Cmd, x+0x87);//Column address
            LCD_Write(LCD_Write_Dis_Data,0x00);
            LCD_Write(LCD_Write_Dis_Data,0x01);       
         }
    }
for(y=0;y<2;y++ )
    {
       for(x=0;x<8;x++)
           {
            LCD_Write(LCD_Write_Con_Cmd, y*31+0x80);//row address
            LCD_Write(LCD_Write_Con_Cmd, x+0x80+8*y);//column address            
            LCD_Write(LCD_Write_Dis_Data,0xff);
            LCD_Write(LCD_Write_Dis_Data,0xff);
           }
     }
LCD_Write(LCD_Write_Con_Cmd,0x30);
}
/********************************************************************************
【Function description】 LCD clears all drawing RAM GDRAM 64*32 bytes space
              0 1 2****13 14 15
              1****************
              2****************
              *****************
              *
              *
              62
              63
****************************************************************************/
void LCD_Clear_GDRAM(void)
{
   u8 x,y;
   LCD_Write(LCD_Write_Con_Cmd,0x34);
   for(y=0;y<64;y++)
    {
      for(x=0;x<16;x++)
         {
            LCD_Write(LCD_Write_Con_Cmd, y+0x80);//row address
            LCD_Write(LCD_Write_Con_Cmd, x+0x80);//column address          
            LCD_Write(LCD_Write_Dis_Data,0x00);
            LCD_Write(LCD_Write_Dis_Data,0x00);
         }
     }
   LCD_Write(LCD_Write_Con_Cmd,0x30);
}
/**********************************************************************************
【Function Description】 Display custom graphics in the specified rows and columns (defined as 64X8 pixels)            
【Entry Parameters】 u8 row: row coordinate value range (0-63)
            u8 col: column coordinate value range (0-7)
      u8 row_Pixel: row pixel number value range (1-64)
      u8 col_Pixel: Column pixel number range (1-8)
      u8 *Dis_Data: display data pointer
[Note]: row coordinate plus row offset cannot exceed 63
                     column coordinate plus column offset cannot exceed 7
**************************************************************************/
void LCD_Dis_Graphics(u8 row, u8 col, u8 row_Pixel, u8 col_Pixel, u8 *Dis_Data)
{
u8 r,c,r_count,c_count;
//Open drawing mode
LCD_Write(LCD_Write_Con_Cmd,0x34);
LCD_Write(LCD_Write_Con_Cmd,0x36);
for(r_count = row; r_count < row + row_Pixel; r_count++)
   {
       if(r_count > 31) r = r_count - 32;
       else r = r_count;    
       for(c_count = col; c_count < col + col_Pixel; c_count++)
        {
             if(r_count > 31) c = c_count + 8;
             else c = c_count;
             LCD_Write(LCD_Write_Con_Cmd, r+0x80);//Row address
             LCD_Write(LCD_Write_Con_Cmd, c+0x80);//Column address        
             LCD_Write(LCD_Write_Dis_Data,*Dis_Data++);
             LCD_Write(LCD_Write_Dis_Data,*Dis_Data++) ;
            
      }
   }
LCD_Write(LCD_Write_Con_Cmd,0x30);
}
/***************************************************************************
【Function description】 Clear the custom graphics in the specified row and column (defined as 64X8 pixels)            
【Entry parameters】 u8 row: row coordinate value range (0-63)
            u8 col: column coordinate value range (0-7)
      u8 row_Pixel: row pixel number value range (1-64)
      u8 col_Pixel: column pixel number value range (1-8)
【Notes】 : The row coordinate plus the row offset cannot exceed 63,
                     the column coordinate plus the column offset cannot exceed 7
******************************************************************************/
void LCD_Clear_Graphics(u8 row, u8 col, u8 row_Pixel, u8 col_Pixel)
{
u8 r,c,r_count,c_count;
//Extended instruction
LCD_Write(LCD_Write_Con_Cmd,0x34);

for(r_count = row; r_count < row + row_Pixel; r_count++)
   {
       if(r_count > 31) r = r_count - 32;
       else              r = r_count;    
       for(c_count = col; c_count < col + col_Pixel; c_count++)
        {
             if(r_count > 31) c = c_count + 8;
             else              c = c_count;
             LCD_Write(LCD_Write_Con_Cmd, r+0x80);//行地址
             LCD_Write(LCD_Write_Con_Cmd, c+0x80);//列地址        
             LCD_Write(LCD_Write_Dis_Data,0x00);
             LCD_Write(LCD_Write_Dis_Data,0x00);
            
      }
   }
LCD_Write(LCD_Write_Con_Cmd,0x30);
}

Keywords:stm32 Reference address:stm32 12864 driver

Previous article:stm32: firmware library file description
Next article:STM32 output comparison error and solution

Recommended ReadingLatest update time:2024-11-15 17:03

Understanding of STM32 serial port
      In general, the serial port of STM32 microcontroller is easy to understand and programming is not complicated. Of course, I would rather hope that its interrupt system is as simple as that of 51 microcontroller.       For the receiving terminal, it is RXNE, which is generated only after the reception
[Microcontroller]
ADC sampling example based on DMA in STM32 MQ-2 smoke sensor
I recently learned about ADC sampling in STM32. Since I happened to have an MQ-2 smoke sensor, I could test it and experience the ADC sampling process. The following is an introduction to the MQ-2 smoke sensor. 1. Introduction to MQ-2 smoke sensor  The gas-sensitive material used in the MQ-2 gas sensor is tin diox
[Microcontroller]
ADC sampling example based on DMA in STM32 MQ-2 smoke sensor
Wireless fire detection and alarm system based on information fusion technology
    The application of fire has played an important role in the development of human civilization, and fire has always threatened human life and caused significant losses of life and property. Especially in recent years, with the rapid development of the national economy, the further improvement of urbanization, the in
[Microcontroller]
Wireless fire detection and alarm system based on information fusion technology
STM32 PWM channel configuration pins
I have always been confused about PWM until I saw this description, TIM1_ETR PA12 PE7  TIM1_CH1 PA8 PE9  TIM1_CH2 PA9 PE11  TIM1_CH3 PA10 PE13  TIM1_CH4 PA11 PE14  TIM1_BKIN PB12 PA6 PE15  TIM1_CH1N PB13 PA7 PE8  TIM1_CH2N PB14 PB0 PE10  TIM1_CH3N PB15 PB1 PE12  TIM2_CH1_ETR PA0 PA15 PA0 PA15  TIM2_CH2 PA1 PB3 PA1 PB
[Microcontroller]
The basic timer function of STM32 general timer realizes light flashing
/*MAIN.C*/ /* Includes ----------------------------------------------- ------------------*/ #include "stm32f10x.h" #include "misc.h"   /* Private function prototypes ------------------------------------------------ --*/ void RCC_Configuration(void); void NVIC_Configuration(void); void GPIO_Configuration(void)
[Microcontroller]
STM32 clock, external 16M setting
The general clock setting is an external 8M clock, but when it is set to an external 16M clock, the following configuration is required: (1) For the stm32f103xx chip, modify HSE_VALUE in the stm32f10x.h library at around line 119 to 16000000 (the default is 8000000), then set it in system_stm32f10x.c, around line 1054
[Microcontroller]
What is the specific meaning of I/O Level FT in the STM32 technical documentation?
Five volt tolerant means compatible with 5V signal voltage. According to the technical manual, the maximum voltage tolerated is VDD+4.0 = 3.3+4.0=7.3V
[Microcontroller]
What is the specific meaning of I/O Level FT in the STM32 technical documentation?
stm32 Bootloader Design (YModem Protocol)
I believe many people hope that they can upgrade the firmware without opening the cover, just like those of mobile phones. The bootload described below will achieve this function.          Some time ago, there was a project about Bootload design. So I studied it carefully. In the past, I used the official version of s
[Microcontroller]
stm32 Bootloader Design (YModem Protocol)
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号