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

📄 lcd_lm6029a.c

📁 topway的点阵液晶模块lm6029的程序
💻 C
字号:
//LCD drivers for TOPWAY LM6029A,by Wang-Yongqiang at 2008-07-09
#include <msp430x14x.h>
#include "lcd_lm6029a.h"

void lcd_delay(uint argi)
{
	for (;argi;argi--);
}

void LcdCommand(uchar argX)
{
	uchar tmpi,tmpj,tmpk;
	tmpj = argX;
	tmpk = 0;
	if (tmpj & BIT0)
	{
		tmpk |= BIT0;
	}
	for (tmpi=0;tmpi<7;tmpi++)
	{
		tmpj >>= 1;
		tmpk <<= 1;
		if (tmpj & BIT0)
		{
			tmpk |= BIT0;
		}
	}
	lcd_rd_1;
	lcd_rs_0;
	lcd_dat = tmpk;
	lcd_wr_0;
	lcd_wr_1;	
}

void LcdDataWrite(uchar argX)
{
	lcd_rd_1;
	lcd_rs_1;
	lcd_dat = argX;
	lcd_wr_0;
	lcd_wr_1;	
}

void lcd_init(void)
{
	lcd_cs_0;
	lcd_rst_0;
	_NOP();_NOP();_NOP();_NOP();_NOP();_NOP();_NOP();_NOP();
	_NOP();_NOP();_NOP();_NOP();_NOP();_NOP();_NOP();_NOP();
	lcd_rst_1;	
	LcdCommand(0xa0);
	LcdCommand(0xc8);
	LcdCommand(0xa2);
	LcdCommand(0x40);
	LcdCommand(0xa4);
	LcdCommand(0x26);
	LcdCommand(0x2c);

	LcdCommand(0x2e);

	LcdCommand(0x2f);

	LcdCommand(0x25); 	
	LcdCommand(0x81);
	LcdCommand(0x20);
	LcdCommand(0xaf);

	LcdCommand(0xad);
	LcdCommand(0x00);
	lcd_cs_1;
}

void LcdSetPage(uchar argX)
{
	argX &= 0x07;
	argX |= 0xb0;
	LcdCommand(argX);	
}

void LcdSetColumn(uchar argX)
{
	uchar tmpc;
	tmpc = argX;
	argX &= 0x0f;
	LcdCommand(argX);
	tmpc >>= 4;
	argX = tmpc & 0x0f;
	argX |= 0x10;
	LcdCommand(argX);	
}

void lcd_cls(void)
{
	uchar tmpi,tmpj;
	lcd_cs_0;
	for (tmpi=0;tmpi<8;tmpi++)
	{
		LcdSetColumn(0);
		LcdSetPage(tmpi);
		for (tmpj=0;tmpj<128;tmpj++)
		{
			LcdDataWrite(0x00);
		}
	}
	lcd_cs_1;
}

void LcdPowerSave(void)
{
	lcd_bla_1;
	lcd_cs_0;
	LcdCommand(0xae);
	LcdCommand(0xa5);
	lcd_cs_1;	
}

void LcdPowerActive(void)
{
	lcd_cs_0;
	LcdCommand(0xa4);
	LcdCommand(0xaf);
	lcd_cs_1;	
}

extern const uchar SmallFonts5x8[];
typedef struct {uchar dat[5];uchar idx[1];}yqBitmap5x8;

void LcdProgressBar(uint argCur,uint argTotal)
{
	uchar tmpi,tmpk;
	lcd_cs_0;
	tmpk = (unsigned char)(argCur*100/argTotal);
	LcdSetColumn(13);
	LcdSetPage(7);
	LcdDataWrite(0x3f);
	for (tmpi=0;tmpi<tmpk;tmpi++)
	{
		LcdDataWrite(0x3f);
	}
	for (;tmpi<100;tmpi++)
	{
		LcdDataWrite(0x21);
	}
	LcdDataWrite(0x3f);
	lcd_cs_1;
}
void LcdShowSmallText(uchar argPage,uchar argColumn,uchar *argString)
{
	uchar tmpi,tmpj;
	yqBitmap5x8  *tmp6x16  = (yqBitmap5x8 *)SmallFonts5x8;
	lcd_cs_0;
	while (*argString)
	{
		tmpi = 0;
		while (tmp6x16[tmpi].idx[0])
		{
			if (tmp6x16[tmpi].idx[0] == *argString)
			{	
				if (argPage&0x80)
				{
					LcdSetColumn(argColumn);
					LcdSetPage(argPage);
					for (tmpj=0;tmpj<5;tmpj++)
					{
						LcdDataWrite(~tmp6x16[tmpi].dat[tmpj]);
					}
					break;
				}
				else
				{
					LcdSetColumn(argColumn);
					LcdSetPage(argPage);
					for (tmpj=0;tmpj<5;tmpj++)
					{
						LcdDataWrite(tmp6x16[tmpi].dat[tmpj]);
					}
					break;
				}
			}
			tmpi++;
		}
		argColumn += 5;
		argString++;
	}
	lcd_cs_1;
}

extern const uchar XinSongTi6x16[];
extern const uchar XinSongTi12x16[];
typedef struct {uchar dat[12];uchar idx[1];}yqBitmap6x16;
typedef struct {uchar idx[2];uchar dat[24];}yqBitmap12x16;

void LcdShowText(uchar argPage,uchar argColumn,uchar *argString)
{
	uchar tmpi,tmpj;
	yqBitmap6x16  *tmp6x16  = (yqBitmap6x16 *)XinSongTi6x16;
	yqBitmap12x16 *tmp12x16 = (yqBitmap12x16 *)XinSongTi12x16;
	lcd_cs_0;
	while (*argString)
	{
		tmpi = 0;
		if (*argString<0xa0)
		{
			while (tmp6x16[tmpi].idx[0])
			{
				if (tmp6x16[tmpi].idx[0] == *argString)
				{		
					if (argPage&0x80)
					{
						LcdSetColumn(argColumn);
						LcdSetPage(argPage);
						for (tmpj=0;tmpj<6;tmpj++)
						{
							LcdDataWrite(~tmp6x16[tmpi].dat[tmpj]);
						}
						LcdSetColumn(argColumn);
						LcdSetPage(argPage+1);
						for (tmpj=0;tmpj<6;tmpj++)
						{
							LcdDataWrite(~tmp6x16[tmpi].dat[tmpj+6]);
						}
						break;
					}
					else
					{
						LcdSetColumn(argColumn);
						LcdSetPage(argPage);
						for (tmpj=0;tmpj<6;tmpj++)
						{
							LcdDataWrite(tmp6x16[tmpi].dat[tmpj]);
						}
						LcdSetColumn(argColumn);
						LcdSetPage(argPage+1);
						for (tmpj=0;tmpj<6;tmpj++)
						{
							LcdDataWrite(tmp6x16[tmpi].dat[tmpj+6]);
						}
						break;
					}
				}
				tmpi++;
			}
			argColumn += 6;
			argString++;
		}
		else
		{
			while (tmp12x16[tmpi].idx[0])
			{
				if ((tmp12x16[tmpi].idx[0] == *argString)&&(tmp12x16[tmpi].idx[1] == *(argString+1)))
				{			
					if (argPage&0x80)
					{
						LcdSetColumn(argColumn);
						LcdSetPage(argPage);
						for (tmpj=0;tmpj<12;tmpj++)
						{
							LcdDataWrite(~tmp12x16[tmpi].dat[tmpj]);
						}
						LcdSetColumn(argColumn);
						LcdSetPage(argPage+1);
						for (tmpj=0;tmpj<12;tmpj++)
						{
							LcdDataWrite(~tmp12x16[tmpi].dat[tmpj+12]);
						}
						break;
					}
					else
					{
						LcdSetColumn(argColumn);
						LcdSetPage(argPage);
						for (tmpj=0;tmpj<12;tmpj++)
						{
							LcdDataWrite(tmp12x16[tmpi].dat[tmpj]);
						}
						LcdSetColumn(argColumn);
						LcdSetPage(argPage+1);
						for (tmpj=0;tmpj<12;tmpj++)
						{
							LcdDataWrite(tmp12x16[tmpi].dat[tmpj+12]);
						}
						break;
					}
				}
				tmpi++;
			}
			argColumn += 12;
			argString++;
			argString++;
		}
	}
	lcd_cs_1;
}
void LcdShowText_frame(uchar argPage,uchar argColumn,uchar *argString)
{
	uchar tmpi,tmpj;
	yqBitmap6x16  *tmp6x16  = (yqBitmap6x16 *)XinSongTi6x16;
	yqBitmap12x16 *tmp12x16 = (yqBitmap12x16 *)XinSongTi12x16;
	lcd_cs_0;
	while (*argString)
	{
		tmpi = 0;
		if (*argString<0xa0)
		{
			while (tmp6x16[tmpi].idx[0])
			{
				if (tmp6x16[tmpi].idx[0] == *argString)
				{		
					if (argPage&0x80)
					{
						LcdSetColumn(argColumn);
						LcdSetPage(argPage);
						for (tmpj=0;tmpj<6;tmpj++)
						{
							LcdDataWrite(0xbf&~tmp6x16[tmpi].dat[tmpj]);
						}
						LcdSetColumn(argColumn);
						LcdSetPage(argPage+1);
						for (tmpj=0;tmpj<6;tmpj++)
						{
							LcdDataWrite(0xfa&~tmp6x16[tmpi].dat[tmpj+6]);
						}
						break;
					}
					else
					{
						LcdSetColumn(argColumn);
						LcdSetPage(argPage);
						for (tmpj=0;tmpj<6;tmpj++)
						{
							LcdDataWrite(0x80|tmp6x16[tmpi].dat[tmpj]);
						}
						LcdSetColumn(argColumn);
						LcdSetPage(argPage+1);
						for (tmpj=0;tmpj<6;tmpj++)
						{
							LcdDataWrite(0x02|tmp6x16[tmpi].dat[tmpj+6]);
						}
						break;
					}
				}
				tmpi++;
			}
			argColumn += 6;
			argString++;
		}
		else
		{
			while (tmp12x16[tmpi].idx[0])
			{
				if ((tmp12x16[tmpi].idx[0] == *argString)&&(tmp12x16[tmpi].idx[1] == *(argString+1)))
				{			
					if (argPage&0x80)
					{
						LcdSetColumn(argColumn);
						LcdSetPage(argPage);
						for (tmpj=0;tmpj<12;tmpj++)
						{
							LcdDataWrite(0xbf&~tmp12x16[tmpi].dat[tmpj]);
						}
						LcdSetColumn(argColumn);
						LcdSetPage(argPage+1);
						for (tmpj=0;tmpj<12;tmpj++)
						{
							LcdDataWrite(0xfa&~tmp12x16[tmpi].dat[tmpj+12]);
						}
						break;
					}
					else
					{
						LcdSetColumn(argColumn);
						LcdSetPage(argPage);
						for (tmpj=0;tmpj<12;tmpj++)
						{
							LcdDataWrite(0x80|tmp12x16[tmpi].dat[tmpj]);
						}
						LcdSetColumn(argColumn);
						LcdSetPage(argPage+1);
						for (tmpj=0;tmpj<12;tmpj++)
						{
							LcdDataWrite(0x02|tmp12x16[tmpi].dat[tmpj+12]);
						}
						break;
					}
				}
				tmpi++;
			}
			argColumn += 12;
			argString++;
			argString++;
		}
	}
	lcd_cs_1;
}





⌨️ 快捷键说明

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