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

📄 st7920.c

📁 ST7920液晶驱动芯片初始化程序以及字符工作模式操作
💻 C
字号:
#ifndef _LCDdriver_H_
#define _LCDdriver_H_

#define DATE		portc
#define BUSY		portc.7
#define RS			portb.4
#define RW			porta.5
#define EN			portb.1

/*****************ORDER********************************/
#define SET_NC		0x02//set the cursor to start but no clear the screen
#define SET_C		0x01//set the addres to start and clear the screen
#define CLE			0x00//clear the screen
#define CUR_ON		0x0f//turn on the cursor to flash
#define CUR_OFF		0x0c//turn off the cursor
/******************************************************/

rom char *psotion_lcd = {0x80, 0x90, 0x88, 0x98};

void DelayS(void)
{
	 uchar i;
	 i = 0x1f;
	 while(i--);
}
void wait_5ms( void )
{
	unsigned int i ;
	for( i=0 ; i<1000 ; i++ );
}
void wait_for_busy(void)
{
	trisc = 0xff;
	RS = 0;
	RW = 1;
	EN = 1;
	while(BUSY); // wait while busy set
	EN = 0;
	trisc = 0x00;
}
void WriteCmd(uchar ch)
{
     wait_for_busy();
     DelayS();
     EN 	= 0;
     RS 	= 0;
     RW 	= 0;
     nop();
     EN 	= 1;
     DATE	= ch;
	 nop();
     EN		= 0;
}
void WriteData(uchar ch)
{
     wait_for_busy();
     DelayS();
     EN 	= 0;
     RS 	= 1;
     RW 	= 0;
     nop();
     EN 	= 1;
     DATE	= ch;
	 nop();
     EN 	= 0;
     RS 	= 0;
}
void InitLcd(void)
{
	 //RST=0;
     wait_5ms();
	// RST=1;
	 wait_5ms();
	 wait_5ms();
	 WriteCmd(0x30);
	 WriteCmd(0x0c);
	 WriteCmd(0x01);
     WriteCmd(0x02);
	 WriteCmd(0x80);
}
/*******************************************************
function: set the addres for DBC
e.g:    1,1 1,2					1,7	1,8
		2,1					2,6		2,8
		3,1		3,3					3,8
		4,1			4,4	4,5			4,8
*******************************************************/
void set_addres(uchar row,uchar column)
{
	WriteCmd(psotion_lcd[row]+column);
}
/*********************************************************
function:write ch on the postion of row and column
**********************************************************/
void write_dbc(uchar row,uchar column,uchar *ch)
{
	uchar c,pi=0;
	WriteCmd(psotion_lcd[row]+column);
	while(1)
	{
		c = ch[pi++];
		if ( !c )
			break;
		WriteData(c);
	}
}
/*******************************************************
function: set the addres for SBC
e.g:    1,1 1,2					1,7	1,8
		2,1					2,6		2,8
		3,1		3,3					3,8
		4,1			4,4	4,5			4,8
*******************************************************/
void display(uchar x_add,uchar y_add,uchar dat1,uchar dat2)
{
	WriteCmd(psotion_lcd[x_add]+y_add);	
     WriteData(dat1);
     WriteData(dat2);
}
/*****************************************
function: display the welcome message
*****************************************/
void welcome(void)
{
    uchar i,j;
    WriteCmd(CLE);
    clear_wdt();
    wait_5ms();
    for(i=1; i<5; i++)
    {
    	for(j=7; j>i; j--)
    	{
    		display(1,j+1,0xD7,0xa0);//clear
    		switch(i)
    		{
				case 1:
					display(1,j,0xba,0xcf);//合
					break;
				case 2:
					display(1,j,0xb3,0xc9);//成
					break;
				case 3:
					display(1,j,0xb5,0xe7);//电
					break;
				case 4:
					display(1,j,0xc6,0xf7);//器
					break;
				default:
					write_dbc(1,3,"erro!!!");
			}
    	delay_s(1);
		clear_wdt();
    	}
    }
	for(i=0; i<2; i++)
	{
		delay_s(2);
		clear_wdt();
	}
	WriteCmd(CLE);
}
/*********************************************************
function:write ch on the postion of row and column
**********************************************************/
void write_dbc_l(uchar row,uchar column, uchar len, uchar *ch)
{
	uchar c,pi=0;
	WriteCmd(psotion_lcd[row]+column);	
	while(len--)
	{
		c = ch[pi++];
		WriteData(c);
	}
}
#endif

⌨️ 快捷键说明

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