⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd_12864.c

📁 ATMEGA16单片机控制LCD1264程序。
💻 C
字号:
#include "..\delay_function.h"
#include "LCD_12864_Interface.h"
#include "LCD_12864.h"
//#include "bmp1_12864.h"
//#include "Charactor_Generation.h"

//往LCD12864写一字节数据
void LCD12864_write_byte(unsigned char cmd, unsigned char Data)
{
	unsigned char i;
	unsigned int tmp;
	tmp = ( ((int)Data<<8|Data<<4) & 0xF0F0);
	LCD12864_Clk_cls;
	LCD12864_Do;
	LCD12864_CS_stb;
	delay_1us();
	for (i=0;i<8;i++) {
		if (cmd & 0x80)
			LCD_SID_stb;
		else
			LCD_SID_cls;
		LCD12864_Clk;
		cmd = cmd<<1;
	}
	for (i=0;i<16;i++) {
		if (tmp & 0x8000)
			LCD_SID_stb;
		else
			LCD_SID_cls;
		LCD12864_Clk;
		tmp = tmp<<1;
	}
//	LCD_SID_stb;
	delay_1us();
	LCD12864_CS_cls;
}

//设置坐标(X:0-7;Y:0-3)
void LCD_set_XY( unsigned char posx, unsigned char posy )
{
	unsigned char temp,temp1;
	temp1 = posy & 0x01;
	temp = posx;
	if ( !temp1 ) temp |= 0x80;
	if ( temp1 ) temp |= 0x90;
	temp1 = posy & 0x02;
	if ( temp1 ) temp += 0x08;
	LCD12864_write_byte( LCD_WR_CMD,LCD_DDRAM|temp );
}


//显示字符串(posx:0-7;posy:0-3)
void LCD_puts(unsigned char posx, unsigned char posy, char *s)
{
	LCD_set_XY( posx, posy );
	while ( *s )
	{
		LCD12864_write_byte( LCD_WR_DAT,*s );
		delay_nms(50);
		s++;
	}

}

/**************图形操作函数*************/
#ifdef _BMP1_12864_H__
//调入图片
void Lcd_GDrw(const char *ptr)
{
	char i,j,tmp;
	char XX,YY;
	LCD12864_write_byte( LCD_WR_CMD,LCD_FUNCTION|b_DL|b_RE );

	XX = LCD_DRAW;
	YY = LCD_DRAW;
	for (i=0;i<32;i++) {
		LCD12864_write_byte( LCD_WR_CMD,YY );
		LCD12864_write_byte( LCD_WR_CMD,XX );
		for (j=0;j<16;j++) {
			tmp = pgm_read_byte(ptr++);
			LCD12864_write_byte( LCD_WR_DAT,tmp );
		}
		YY++;
	}

	XX = LCD_DRAW|0x08;
	YY = LCD_DRAW;
	for (i=0;i<32;i++) {
		LCD12864_write_byte( LCD_WR_CMD,YY );
		LCD12864_write_byte( LCD_WR_CMD,XX );
		for (j=0;j<16;j++) {
			tmp = pgm_read_byte(ptr++);
			LCD12864_write_byte( LCD_WR_DAT,tmp );
		}
		YY++;
	}
	LCD12864_write_byte( LCD_WR_CMD,LCD_EFUNCTION|b_DL );
}

//选择图片
void LCD_Pic_Sel(unsigned char index)
{
	switch (index) {
		case 0:
			Lcd_GDrw(Graphy1);
			break;
		case 1:
			break;
		case 2:
			break;
		case 3:
			break;
		default:
			break;
	}
}

//图片显示开关
void LCD_Pic_Show(enum DisplayOnOff onoff)
{
	if (Off == onoff) {
		LCD12864_write_byte( LCD_WR_CMD,LCD_EFUNCTION|b_DL|b_RE);
	}
	else {
		LCD12864_write_byte( LCD_WR_CMD,LCD_EFUNCTION|b_DL|b_RE|b_G );
	}
	LCD12864_write_byte( LCD_WR_CMD,LCD_EFUNCTION|b_DL );
}

#endif

/************自定义字型操作***********/
#ifdef __CHARACTOR_GENERATION_H_
//编码自定义字型(最多4个16*16自定义字型)
void LCD_Char_Gen(const char *ptr, unsigned char num)
{
	unsigned char i,j,tmp;
	LCD12864_write_byte( LCD_WR_CMD,LCD_CGRAM );
	for (i=0;i<num;i++) {
		for (j=0;j<32;j++) {
			tmp = pgm_read_byte(ptr++);
			LCD12864_write_byte( LCD_WR_DAT,tmp );
		}
	}
}

//显示自定义字型(posx:0-7;posy:0-3;index:0-3)
void LCD_Char_Show(unsigned char posx, unsigned char posy, enum Char_sel index)
{
	LCD_set_XY( posx, posy );
	LCD12864_write_byte( LCD_WR_DAT,0x00 ); 
	LCD12864_write_byte( LCD_WR_DAT,index ); 
}
#endif

//LCD清屏
void LCD_clear(void)
{
	LCD12864_write_byte( LCD_WR_CMD,LCD_CLS );
}

//初始化LCD
void Init_LCD12864( void )
{
	Init_LCD_Port();

	delay_nms(45);
	LCD12864_write_byte( LCD_WR_CMD,LCD_FUNCTION|b_DL );
	delay_1ms();
	LCD12864_write_byte( LCD_WR_CMD,LCD_FUNCTION|b_DL );
	delay_1ms();
	LCD12864_write_byte( LCD_WR_CMD,LCD_VISIBLE );
	delay_1ms();
	LCD12864_write_byte( LCD_WR_CMD,LCD_CLS );
	delay_nms(10);
	LCD12864_write_byte( LCD_WR_CMD,LCD_POINT|b_I_D );
	delay_1ms();
	LCD12864_write_byte( LCD_WR_CMD,LCD_VISIBLE|b_D );
	delay_1ms();
#ifdef __CHARACTOR_GENERATION_H_
	LCD_Char_Gen(CharGen,4);
#endif
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -