新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > stm32單片機(jī)12864驅(qū)動(dòng)

stm32單片機(jī)12864驅(qū)動(dòng)

作者: 時(shí)間:2016-11-29 來(lái)源:網(wǎng)絡(luò) 收藏
/****************************************************************
【文 件 名 稱】lcd12864.h【功 能 描 述】lcd12864 頭文件【 作 者 】shifu*****************************************************************/#ifndef __LCD12864_H#define __LCD12864_H//****************************************************************#include "stm32f10x_gpio.h"#include "systick_delay.h"http://*****************************************************************//管腳定義#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//數(shù)據(jù)#define LCD_SID_1 GPIO_LCD->BSRR = GPIO_Pin_9#define LCD_SID_0 GPIO_LCD->BRR = GPIO_Pin_9//同步時(shí)鐘#define LCD_CLK_1 GPIO_LCD->BSRR = GPIO_Pin_10#define LCD_CLK_0 GPIO_LCD->BRR = GPIO_Pin_10//復(fù)位 低電平復(fù)位#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//********************函數(shù)聲明************************************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);/*****************************************************************液晶模塊指令集定義*****************************************************************0x01 //清顯示指令0x06 //設(shè)置輸入模式0x0c //設(shè)置開(kāi)顯控制0x30 //功能設(shè)定(基本指令)0x34 //功能設(shè)定(擴(kuò)充指令)0x36 //打開(kāi)繪圖(擴(kuò)充指令)*****************************************************************/#endif/****************************************************************************【文 件 名 稱】lcd12864.c【功 能 描 述】lcd12864 驅(qū)動(dòng)【 作 者 】shifu****************************************************************************//**************************************************************************/#include "lcd12864.h"#include "stm32f10x_lib.h"/****************************************************************************【功能說(shuō)明】I/O端口功能、方向設(shè)定****************************************************************************/void LCD_Port_Config(void){GPIO_InitTypeDef GPIO_InitStructure;/* 使能端口時(shí)鐘*/RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_LCD, ENABLE);/* 配置所用管腳為推免輸出,端口速度為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);}/****************************************************************************【功能說(shuō)明】 LCD寫(xiě)字節(jié)函數(shù)入口參數(shù) inst=cmd/data: 命令/數(shù)據(jù)標(biāo)志(data:寫(xiě)顯示數(shù)據(jù) cmd:寫(xiě)控制指令)x : 命令/數(shù)據(jù)字節(jié)****************************************************************************/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; //選中12864//拉低CLK引腳,準(zhǔn)備產(chǎn)生上升沿LCD_CLK_0;//串行傳送24個(gè)二進(jìn)制位for(i=0;i<24;i++){if(temp & 0x80000000) LCD_SID_1;else LCD_SID_0;//拉高CLK引腳,產(chǎn)生一個(gè)上升沿,最高位被傳送到LCD模塊中LCD_CLK_1;t = 0x10; while(t--); //延時(shí) lcd讀取數(shù)據(jù)//拉低CLK引腳,準(zhǔn)備產(chǎn)生上升沿LCD_CLK_0;//左移一位,準(zhǔn)備下一個(gè)待傳送的位temp = temp<<1;}LCD_CS_0; //取消選中12864}/****************************************************************************【功能說(shuō)明】LCD字符串顯示函數(shù):void LCD_Dis_Str(u8 x, u8 y, u8 *str);入口參數(shù) row: 字符串起始顯示位置的行col: 字符串起始顯示位置的列str: 指向待顯示字符串的字符指針,字符串以