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

📄 display.c

📁 一个关于UCOS的KEIL工程
💻 C
字号:
/*
**===========================================================================
**  lcd driver NT7606
**===========================================================================
*/

/*
**---------------------------------------------------------------------------
   xm contrast menu: (default: level 4)
   +----------------------------------------------------------------------+
   | LCD level  |  contrast value                                         |
   |----------------------------------------------------------------------|
   | 1          |  0x1B                                                   |
   | 2          |  0x16                                                   |
   | 3          |  0x12                                                   |
   | 4          |  0x0D                                                   |
   | 5          |  0x09                                                   |
   | 6          |  0x04                                                   |
   | 7          |  0x00                                                   |
   +----------------------------------------------------------------------+
**---------------------------------------------------------------------------
*/

#include <reg51.h>

sbit LCD_SI 	= P1^3;//spi data
sbit LCD_SCL 	= P1^2;//spi clk
sbit LCD_RS 	= P1^5;//instruction(0)/data(1) register
sbit LCD_CS 	= P1^4;//chip select(0=active)
sbit LCD_RST 	= P1^1;
sbit LCD_BL 	= P1^6;

#define LCD_RST_SET()		LCD_RST = 1;//reset(0=reset)
#define LCD_RST_CLR()		LCD_RST = 0;
#define LCD_BL_ON()			LCD_BL = 1;
#define LCD_BL_OFF()		LCD_BL = 0;

//instruction 3:power save set
#define powerup		0x0E
#define powersave	0x0D
//instruction 4:function set
#define func2line	0x10
#define func3line	0x14
//instruction 5:line shift mode
#define firlin1		0x18
#define firlin2		0x19
#define firlin3		0x1A
#define firlin4		0x1B
//instruction 6:bias control
#define bias5		0x1E
#define bias4		0x1F
//instruction 7:power control set
#define poweron1	0x24
#define poweron2	0x26
#define poweron		0x27
#define poweroff1	0x25
#define poweroff2	0x24
#define poweroff	0x20
//instruction 8:display control
#define dispon		0x29
#define dispoff		0x28
//icon position
#define ICON_Antenna			0	//fact address:01
#define ICON_LowSignalBar		1	//fact address:02
#define ICON_MediumSignalBar	2	//fact address:03
#define ICON_HighSignalBar		3	//fact address:04
#define ICON_Scan				4	//fact address:05
#define ICON_Display1			5	//fact address:21
#define ICON_Display2			6	//fact address:22
#define ICON_Display3			7	//fact address:23
#define ICON_Category			8	//fact address:24
#define ICON_BankA				9	//fact address:61
#define ICON_BankB				10	//fact address:62
#define ICON_BankC				11	//fact address:63
#define ICON_Direct				12	//fact address:64
//#define ICON_					13	//reserved
//#define ICON_					14	//reserved
//#define ICON_					15	//reserved

/*CGRAM*/
unsigned char code CGRAM[8][8] =
{
	(0, 0, 0, 0, 0, 0, 0, 0),
	(0, 0, 0, 0, 0, 0, 0, 0),
	(0, 0, 0, 0, 0, 0, 0, 0),
	(0, 0, 0, 0, 0, 0, 0, 0),
	(0, 0, 0, 0, 0, 0, 0, 0),
	(0, 0, 0, 0, 0, 0, 0, 0),
	(0, 0, 0, 0, 0, 0, 0, 0),
	(0, 0, 0, 0, 0, 0, 0, 0),
};

#define power_on_sequ()			LCD_RS = 0;\
								sendb(poweron1);\
								delay1_ms(2);\
								sendb(poweron2);\
								delay1_ms(2);\
								sendb(poweron);\

#define power_off_sequ()		LCD_RS = 0;\
								sendb(poweroff1);\
								delay1_ms(50);\
								sendb(poweroff2);\
								delay1_ms(2);\
								sendb(poweroff);\
								delay1_ms(2);

/*Icon buffer*/
//unsigned char pdata IconBuff[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,};
unsigned int IconWord = 0;

// Contrast level
//unsigned char code ContrastTab[7] = {0x18, 0x14, 0x10, 0x0C, 0x08, 0x04, 0x00};

//void power_on_sequ();
//void power_off_sequ();
void lcdcontrast_set(unsigned char volume)reentrant;
void doubheight_on(unsigned char line)reentrant;
void doubheight_off()reentrant;
void fullscr(unsigned char cdata)reentrant;

void delay_us(unsigned char i) reentrant
{
	for(; i>0; i--);
}

void delay1_ms(unsigned char count) reentrant
{
	unsigned int i;
	for(; count>0; count--)
	{
		for(i=124; i>0; i--);
	}
}

void sendb(unsigned char x) reentrant
{
	unsigned char i;
	
	for (i=0; i<8; i++)
	{
		LCD_SCL = 0;
		x <<= 1;
		LCD_SI = CY;
		LCD_SCL = 1;
	}
	LCD_SCL = 0;
	LCD_SI = 0;
}

/*
**===========================================================================
**  x.    Function set
**===========================================================================
*/

void nt7606_init() reentrant
{
	unsigned char i;
	unsigned char code *p;
	
	LCD_CS = 1;
	
	/*reset*/
	LCD_RST_CLR();
	delay_us(50);
	LCD_RST_SET();
	//delay_us(20);
	delay1_ms(10);
	
	LCD_CS = 0;
	LCD_RS = 0;
	/*function set*/
	sendb(func2line);
	sendb(firlin1);
	sendb(bias5);
	/*power up*/
	sendb(powerup);
	//sendb(poweron);
	power_on_sequ();
	delay1_ms(20);
	
	/*clear ICONRAM*/
	sendb(0x40);
	LCD_RS = 1;
	for(i=0; i<16; i++)
	{
		sendb(0);
	}
	
	/*clear DDRAM*/
	LCD_RS = 0;
	sendb(0x80);
	LCD_RS = 1;
	for(i=0; i<64; i++)
	{
		sendb(0x20);
	}
	
	/*CGRAM ini*/
	p = &CGRAM[0][0];
	for(i=0; i<64; i++, p++)
	{
		sendb(*p);
	}
	
	/*display on*/
	LCD_RS = 0;
	sendb(dispon);
	
	LCD_CS = 1;
	
	/*contrast set*/
	lcdcontrast_set(0x0F);
	
	LCD_RS = 0;
}

void lcdcontrast_set(unsigned char volume) reentrant
{
	LCD_CS = 0;
	
	LCD_RS = 0;
	sendb(0x50);//eletronic volume address
	LCD_RS = 1;
	sendb(volume);
	
	LCD_CS = 1;
	
	LCD_RS = 0;
}

/*
void doubheight_on(unsigned char line)
{
	line&=0x03;
	LCD_CS=0;
	LCD_RS=0;
	sendb(line|0x08);
	LCD_CS=1;
}
void doubheight_off()
{
	LCD_CS=0;
	LCD_RS=0;
	sendb(0x08);
	LCD_CS=1;
}
*/

/*
**===========================================================================
**  x.    Power control
**===========================================================================
*/

/*
void power_on_sequ()
{
	LCD_RS=0;
	sendb(poweron1);
	delay1_ms(2);
	sendb(poweron2);
	delay1_ms(2);
	sendb(poweron);
}

void power_off_sequ()
{
	LCD_RS=0;
	sendb(poweroff1);
	delay1_ms(50);
	sendb(poweroff2);
	delay1_ms(2);
	sendb(poweroff);
}
*/

void nt7606_power_wake() reentrant
{
	unsigned char i;
	
	LCD_CS = 0;
	
	LCD_RS = 0;
	sendb(powerup);
	//sendb(poweron);
	power_on_sequ();
	for(i=0; i<10; i++)
	{
		delay_us(200);
	}
	sendb(dispon);
	
	LCD_CS = 1;
}

void nt7606_power_save() reentrant
{
	LCD_CS = 0;
	
	LCD_RS = 0;
	sendb(dispoff);
	sendb(powersave);
	//sendb(poweroff);
	power_off_sequ();
	
	LCD_CS = 1;
}

/*
**===========================================================================
**  x.    DOT MATRIX display
**===========================================================================
*/

/*
void clrscr()
{
	unsigned char i;
	
	LCD_CS = 0;
	
	// DDRAM frist address//
	LCD_RS = 0;
	sendb(0x80);
	
	LCD_RS = 1;
	for(i=0; i<32; i++)
	{
		sendb(0x20);
	}
	
	LCD_RS = 0;
	sendb(0x80);
	
	LCD_CS = 1;
}
*/

void fullscr(unsigned char cdata) reentrant
{
	unsigned char i;
	
	LCD_CS = 0;
	
	/* DDRAM frist address*/
	LCD_RS = 0;
	
	sendb(0x80);
	
	LCD_RS = 1;
	for(i=0; i<32; i++)
	{
		sendb(cdata);
	}
	
	LCD_RS = 0;
	
	sendb(0x80);
	
	LCD_CS = 1;
}

void clrln (char line) reentrant
{
	unsigned char i;
	
	line--;
	
	LCD_CS = 0;
	
	/*line DDRAM frist address*/
	LCD_RS = 0;
	sendb((line<<4)|0x80);
	
	LCD_RS = 1;
	for(i=0; i<16; i++)
	{
		sendb(0x20);
	}
	
	LCD_RS=0;
	sendb((line<<4)|0x80);
	
	LCD_CS = 1;
}

void putch (char cr) reentrant
{
	LCD_CS = 0;
	LCD_RS = 1;
	sendb(cr);
	LCD_CS = 1;
	
	LCD_RS = 0;
}

void putstr (char line, char *str) reentrant
{
	unsigned char i;
	
	line--;
	LCD_CS = 0;
	/*line DDRAM frist address*/
	LCD_RS = 0;
	sendb((line<<4)|0x80);
	LCD_RS = 1;
	for (i=0; (i<16) && (*str!='\0'); i++, str++)
	{
		sendb(*str);
	}
	
	LCD_CS = 1;
	
	LCD_RS = 0;
}

void movcur (char line, char x) reentrant
{
	line--;
	x--;
	
	LCD_CS = 0;
	/*line DDRAM frist address*/
	LCD_RS = 0;
	sendb((line<<4)|0x80|x);
	LCD_CS = 1;
}

/*
**===========================================================================
**  x.     ICON display
**===========================================================================
*/

void disp_icon(unsigned char addr, unsigned char wdata) reentrant
{
	LCD_CS = 0;
	LCD_RS = 0;
	sendb(0x40|addr);
	LCD_RS = 1;
	sendb(wdata);
	LCD_CS = 1;
	
	LCD_RS = 0;
}

void clricon() reentrant
{
	IconWord = 0;
	
	disp_icon(0, 0x00);
	disp_icon(4, 0x00);
	disp_icon(12, 0x00);
}

void icon_w0() reentrant
{
	unsigned char i, temp, icon;
	
	icon = IconWord & 0x001F;
	
	for(i=0, temp=0; i<5; i++)
	{
		temp <<= 1;
		icon >>= 1;
		temp |= CY;
	}
	
	disp_icon(0, temp);
}

void icon_w4() reentrant
{
	unsigned char i, temp, icon;
	
	icon = (IconWord >> 5) & 0x000F;
	
	for(i=0, temp=0; i<5; i++)
	{
		temp <<= 1;
		icon >>= 1;
		temp |= CY;
	}
	
	disp_icon(4, temp);
}

void icon_w12() reentrant
{
	unsigned char i, temp, icon;
	
	icon = (IconWord >> 9) & 0x000F;
	
	for(i=0, temp=0; i<5; i++)
	{
		temp <<= 1;
		icon >>= 1;
		temp |= CY;
	}
	//temp<<=2;
	//icon>>=1;
	//temp|=CY;
	disp_icon(12, temp);
}

void icon_wword(unsigned int wicon) reentrant
{
	IconWord = wicon;
	
	icon_w0();
	icon_w4();
	icon_w12();
}

void icon_on(unsigned char icon) reentrant
{
	IconWord |= (1 << icon);
	switch(icon)
	{
		case ICON_Antenna:
		case ICON_LowSignalBar:
		case ICON_MediumSignalBar:
		case ICON_HighSignalBar:
		case ICON_Scan:
			icon_w0();
			break;
		
		case ICON_Display1:
		case ICON_Display2:
		case ICON_Display3:
			icon_w4();
			break;
			
		case ICON_BankA:
		case ICON_BankB:
		case ICON_BankC:
		case ICON_Direct:
			icon_w12();
			break;
	}
}

void icon_off(unsigned char icon) reentrant
{
	IconWord &= ~(1 << icon);
	
	switch(icon)
	{
		case ICON_Antenna:
		case ICON_LowSignalBar:
		case ICON_MediumSignalBar:
		case ICON_HighSignalBar:
		case ICON_Scan:
			icon_w0();
			break;
		
		case ICON_Display1:
		case ICON_Display2:
		case ICON_Display3:
			icon_w4();
			break;
			
		case ICON_BankA:
		case ICON_BankB:
		case ICON_BankC:
		case ICON_Direct:
			icon_w12();
			break;
	}
}

/*
void clricon()
{
	unsigned char i;
	LCD_CS=0;
	LCD_RS=0;
	sendb(0x40);
	LCD_RS=1;
	for(i=0;i<16;i++)sendb(0x00);
	LCD_CS=1;
}

void icon_on(unsigned char icon)
{
	unsigned char i,j;
	icon--;
	i=icon/5;
	j=4-icon%5;
	IconBuff[i]|=1<<j;
	disp_icon(i);
}
void icon_off(unsigned char icon)
{
	unsigned char i,j;
	icon--;
	i=icon/5;
	j=4-icon%5;
	IconBuff[i]&=~(1<<j);
	disp_icon(i);
}
*/




⌨️ 快捷键说明

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