/*************************************** **************************************** ***********
* File name: 12864.c
* Copyright:
* Module name: 12864 LCD serial working mode driver driven by st7920
* CPU: stm32f103rct6 clock speed: 72 m
* Author:
* Creation date:
* Function Overview:
* ---------------------------------------- Modification history ------------------------------------------
* Current version: modifier: modification date:
* Modification description:
**************************************** **************************************** **********/
# Include "cmdlib \ stm32f10x. H"
# Include "Hal. H"
# Define sid_h gpioc-> bsrr = gpio_pin_11
# Define sid_l gpioc-> BRR = gpio_pin_11
# Define cs_h gpioc-> bsrr = gpio_pin_12
# Define cs_l gpioc-> BRR = gpio_pin_12
# Define sclk_h gpioc-> bsrr = gpio_pin_10
# Define sclk_l gpioc-> BRR = gpio_pin_10
# Define X1 0x80
# Define X2 0x88
# Define Y 0x80
# Define comm 0
# Define dat 1
U8 const num_ LCD [] = {"0123456789 :.-"};
/*************************************** **************************************** ***********
* Function name: LCD _init
* Function Description: Initialize the LCD.
* Parameter: Parameter Name: input/output? Type description
*
* Return value:
* Author:
* Creation date:
* Global variables:
* Global static variables:
* Local static variables:
* ---------------------------------------- Modification history ------------------------------------------
* Current version: modifier: modification date:
* Modification description:
**************************************** **************************************** **********/
Void lcds_config (void)
{
// Spi_inittypedef spi_initstructure;
Gpio_inittypedef gpio_initstructure;
/* PC4-A0 */
// Gpio_setbits (gpioc, gpio_pin_12); // the preset value is high.
Gpio_initstructure.gpio_pin = 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 (gpioc, & gpio_initstructure );
}
/*************************************** **************************************** ***********
* Function name: delaynms
* Function Description: latency
* Parameter: Parameter Name: input/output? Type description
*
* Return value:
* Author:
* Creation date: 2006-12-19
* Global variables:
* Global static variables:
* Local static variables:
* ---------------------------------------- Modification history ------------------------------------------
* Current version: modifier: modification date:
* Modification description:
**************************************** **************************************** **********/
Void delaynms (2010di)
{
2010da, dB;
For (da = 0; da <di; da ++)
For (DB = 0; DB <10; DB ++ );
}
/*************************************** **************************************** ***********
* Function name: LCD _init
* Function Description: Initialize the LCD.
* Parameter: Parameter Name: input/output? Type description
*
* Return value:
* Author:
* Creation date:
* Global variables:
* Global static variables:
* Local static variables:
* ---------------------------------------- Modification history ------------------------------------------
* Current version: modifier: modification date:
* Modification description:
**************************************** **************************************** **********/
Void LCD _init (void)
{
Delaynms (50); // start wait, wait until LCM is in the working status
Cs_h;
Write_char (0, 0x30); // 8-bit interface, basic instruction set
Write_char (0, 0x0c); // The cursor is closed, and the cursor is closed.
Write_char (x 01); // clear the screen and return the address counter of ddram to zero.
}
/*************************************** **************************************** ***********
* Function name: write_char
* Function Description: write commands or data.
* Parameter: Parameter Name: input/output? Type description
*
* Return value:
* Author:
* Creation date: 2006-12-19
* Global variables:
* Global static variables:
* Local static variables:
* ---------------------------------------- Modification history ------------------------------------------
* Current version: modifier: modification date:
* Modification description:
**************************************** **************************************** **********/
Void write_char (u8 start, u8 dData)
{
U8 start_data, hdata, ldata;
If (START = 0)
Start_data = 0xf8; // write command
Else
Start_data = 0xfa; // write data
Hdata = dData & 0xf0; // obtains the fourth highest position.
Ldata = (dData <4) & 0xf0; // retrieve four lower bits
Send_byte (start_data); // sends the start signal
Delaynms (10); // latency is required
Send_byte (hdata); // sends the last four digits
Delaynms (5); // latency is required
Send_byte (ldata); // four low sending bits
Delaynms (5); // latency is required
}
/*************************************** **************************************** ***********
* Function name: send_byte
* Function Description: Send a byte.
* Parameter: Parameter Name: input/output? Type description
*
* Return value:
* Author:
* Creation date:
* Global variables:
* Global static variables:
* Local static variables:
* ---------------------------------------- Modification history ------------------------------------------
* Current version: modifier: modification date:
* Modification description:
**************************************** **************************************** **********/
Void send_byte (u8 bbyte)
{
U8 I, T;
For (I = 0; I <8; I ++)
{
If (bbyte) & 0x80)
Sid_h; // retrieve the highest bit
Else
Sid_l;
Sclk_h;
T = 0x10;
While (t --); // latency LCD reads data
Sclk_l;
Bbyte <= 1; // move left
}
}
/*************************************** **************************************** ***********
* Function name: clr_scr
* Function Description: clear screen function
* Parameter: Parameter Name: input/output? Type description
*
* Return value:
* Author:
* Creation date:
* Global variables:
* Global static variables:
* Local static variables:
* ---------------------------------------- Modification history ------------------------------------------
* Current version: modifier: modification date:
* Modification description:
**************************************** **************************************** **********/
Void clr_scr (void) // screen clearing function
{
Write_char (0, 0x01 );
}
/*************************************** **************************************** ***********
* Function name: LCD _set_xy
* Function Description: Set the start position of the LCD display. X indicates the row and Y indicates the column.
* Parameter: Parameter Name: input/output? Type description
*
* Return value:
* Author:
* Creation date: 2006-12-19
* Global variables:
* Global static variables:
* Local static variables:
* ---------------------------------------- Modification history ------------------------------------------
* Current version: modifier: modification date:
* Modification description:
**************************************** **************************************** **********/
Void LCD _set_xy (u8 X, u8 y)
{
U8 address;
Switch (X)
{
Case 0:
Address = 0x80 + Y;
Break;
Case 1:
Address = 0x80 + Y;
Break;
Case 2:
Address = 0x90 + Y;
Break;
Case 3:
Address = 0x88 + Y;
Break;
Case 4:
Address = 0x98 + Y;
Break;
Default:
Address = 0x80 + Y;
Break;
}
Write_char (0, address );
}
/*************************************** **************************************** ***********
* Function name: LCD _write_string
* Function Description: a function for displaying Chinese and English strings
* Parameter: Parameter Name: input/output? Type description
*
* Return value:
* Author:
* Creation date: 2006-12-19
* Global variables:
* Global static variables:
* Local static variables:
* ---------------------------------------- Modification history ------------------------------------------
* Current version: modifier: modification date:
* Modification description:
**************************************** **************************************** **********/
Void LCD _write_string (u8 X, u8 y, uc8 * s)
{
LCD _set_xy (x, y );
While (* s)
{
Write_char (1, * s );
S ++;
Delaynms (1 );
}
}
/*************************************** **************************************** ***********
* Function name: LCD _write_number
* Function Description: Numeric Display Function
* Parameter: Parameter Name: input/output? Type description
*
* Return value:
* Author:
* Creation date: 2006-12-19
* Global variables:
* Global static variables:
* Local static variables:
* ---------------------------------------- Modification history ------------------------------------------
* Current version: modifier: modification date:
* Modification description:
**************************************** **************************************** **********/
Void LCD _write_number (u8 s) // numeric display function
{
Write_char (1, num_ LCD [s]);
Delaynms (1 );
}
/*************************************** **************************************** ***********
* Function name: img_disp
* Function Description: displays the image.
* Parameter: Parameter Name: input/output? Type description
*
* Return value:
* Author:
* Creation date: 2006-12-19
* Global variables:
* Global static variables:
* Local static variables:
* ---------------------------------------- Modification history ------------------------------------------
* Current version: modifier: modification date:
* Modification description:
**************************************** **************************************** **********/
Void display_img (u8 const * IMG)
{
U8 I, J;
For (j = 0; j <32; j ++)
{
For (I = 0; I <8; I ++)
{
Write_char (Comm, 0x34 );
Delaynms (10 );
Write_char (Comm, Y + J );
Delaynms (10 );
Write_char (Comm, X1 + I );
Delaynms (10 );
Write_char (Comm, 0x30 );
Delaynms (10 );
Write_char (dat, IMG [J * 16 + I * 2]);
Delaynms (10 );
Write_char (dat, IMG [J * 16 + I * 2 + 1]);
Delaynms (10 );
}
}
For (j = 32; j <64; j ++)
{
For (I = 0; I <8; I ++)
{
Write_char (Comm, 0x34 );
Delaynms (10 );
Write_char (Comm, Y + j-32 );
Delaynms (10 );
Write_char (Comm, X2 + I );
Delaynms (10 );
Write_char (Comm, 0x30 );
Delaynms (10 );
Write_char (dat, IMG [J * 16 + I * 2]);
Delaynms (10 );
Write_char (dat, IMG [J * 16 + I * 2 + 1]);
Delaynms (10 );
}
}
Delaynms (10 );
Write_char (Comm, 0x36 );
}
/*************************************** **************************************** ***********
* Function name: delay_ LCD
* Function description:
* Parameter: Parameter Name: input/output? Type description
*
* Return value:
* Author:
* Creation date: 2006-12-19
* Global variables:
* Global static variables:
* Local static variables:
* ---------------------------------------- Modification history ------------------------------------------
* Current version: modifier: modification date:
* Modification description:
**************************************** **************************************** **********/
Void delay_ LCD (2010us) // Delay Time
{
While (US --);
}