stm32 控制lcd12864-hal库

stm32 控制lcd12864-hal库

12864.h
#ifndef __12864_H
#define __12864_H

#include "gpio.h"
	
#define	PAGE_ADD	0xB8
#define COL_ADD 0x40
#define LCD_Off   0x3e
#define LCD_On    0x3f
	
#define LCD12864_RS_SET()		HAL_GPIO_WritePin(RS_GPIO_Port,RS_Pin,GPIO_PIN_SET)
#define LCD12864_RS_CLS()		HAL_GPIO_WritePin(RS_GPIO_Port,RS_Pin,GPIO_PIN_RESET)	

#define LCD12864_RW_SET()		HAL_GPIO_WritePin(RW_GPIO_Port,RW_Pin,GPIO_PIN_SET)
#define LCD12864_RW_CLS()		HAL_GPIO_WritePin(RW_GPIO_Port,RW_Pin,GPIO_PIN_RESET)

#define LCD12864_EN_SET()		HAL_GPIO_WritePin(EN_GPIO_Port,EN_Pin,GPIO_PIN_SET)		
#define LCD12864_EN_CLS()		HAL_GPIO_WritePin(EN_GPIO_Port,EN_Pin,GPIO_PIN_RESET)

#define LCD12864_CS1_SET()	HAL_GPIO_WritePin(CS1_GPIO_Port,CS1_Pin,GPIO_PIN_SET)		
#define LCD12864_CS1_CLS()	HAL_GPIO_WritePin(CS1_GPIO_Port,CS1_Pin,GPIO_PIN_RESET)

#define LCD12864_CS2_SET()	HAL_GPIO_WritePin(CS2_GPIO_Port,CS2_Pin,GPIO_PIN_SET)
#define LCD12864_CS2_CLS()	HAL_GPIO_WritePin(CS2_GPIO_Port,CS2_Pin,GPIO_PIN_RESET)

#define LCD12864_DataOutput(x)	GPIOE->ODR = x
#define LCD12864_DataInput()	GPIOE->ODR	


void LCD12864_Writecmd(uint8_t cmd);
void LCD12864_Writedat(uint8_t data);
void LCD12864_SetCursor(uint16_t page,uint16_t column);
void LCD12864_CLS(void);
void LCD12864_Init(void);
uint8_t LCD12864_OverTurn(uint8_t data);
void LCD12864_ShowChar(uint8_t page,uint8_t column,uint8_t chr,uint8_t size);
void LCD12864_ShowString(uint8_t page,uint8_t column,uint8_t* str,uint8_t size);
void hz_LCDDisp16(unsigned char page,unsigned char column,const unsigned char *hzk);

#endif

12864.c
#include "12864.h"
#include "font.h"

uint8_t LCD12864_OverTurn(uint8_t data)
{
	uint8_t i;
	uint8_t retval=0x00;
	
	for(i=0;i<8;i++)
	{
		retval|=((data>>i)&0x01)<<(7-i);
	}
	
	return retval;
}

void LCD12864_Writecmd(uint8_t cmd)
{
	//LCD12864_WaitReady();
	
	LCD12864_RS_CLS();	//指令
	LCD12864_RW_CLS();	 //写
	
	LCD12864_DataOutput(cmd);
	HAL_Delay(1);
	LCD12864_EN_SET();
	HAL_Delay(2);
	LCD12864_EN_CLS();
	HAL_Delay(1);
}

void LCD12864_Writedat(uint8_t data)
{
	//LCD12864_WaitReady();
	
	LCD12864_RS_SET();	//数据
	LCD12864_RW_CLS();	 //写
	
	LCD12864_DataOutput(data);
	HAL_Delay(1);
	LCD12864_EN_SET();
	HAL_Delay(2);
	LCD12864_EN_CLS();
	HAL_Delay(1);
}


void LCD12864_SetCursor(uint16_t page,uint16_t column)
{
	LCD12864_Writecmd(PAGE_ADD+page);			//设置页地址
	LCD12864_Writecmd(COL_ADD+column);				//设置列地址
}

void LCD12864_CLS()
{
	LCD12864_Writecmd(0x01);
}

void hz_LCDDisp16(unsigned char page,unsigned char column,const unsigned char *hzk)
{
	unsigned char j=0,i=0;
	for(j=0;j<2;j++)
	{
		//LCD12864_Writecmd(PAGE_ADD+page+j);
		//LCD12864_Writecmd(COL_ADD+column);
		for(i=0;i<16;i++) 
		{
			LCD12864_SetCursor(page+j,column+i);
			LCD12864_Writedat(hzk[16*j+i]);			
		}
	}
}

void LCD12864_ShowChar(uint8_t page,uint8_t column,uint8_t chr,uint8_t size)
{
	uint8_t size1,size2,chr1,temp;
	uint8_t i;
	size1=size/8+((size%8)?1:0);
  size2=size1*(size/2);

	chr1=chr-' ';
	
	for(i=0;i=' ') && (*str<='~'))
		{
			LCD12864_ShowChar(page,column,*str,size);
			column+=size/2;
			if(column>64-size)
			{
				column=0;
				page+=2;
			}	
			str++;
	}
}
void LCD12864_Init()
{
	LCD12864_CS1_SET();
	LCD12864_CS2_SET();
	
	LCD12864_Writecmd(LCD_Off);
	LCD12864_Writecmd(0xc0);
	LCD12864_Writecmd(PAGE_ADD);
	LCD12864_Writecmd(COL_ADD);
	LCD12864_Writecmd(0x01);
	LCD12864_Writecmd(LCD_On);
}


你可能感兴趣的:(笔记,stm32,单片机,arm)