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

📄 12864led.c

📁 RT12864M的MSP430F149的并口驱动和应用,作者:AltKKs
💻 C
字号:
#include "RT12864_LCD.h"
#include "declare.h"

/**********************************************************
RT12864M LCD DISPLAY
建立时间:2006年12月17号
修改日期:2005年12月17号
**********************************************************/
void ST7920_ChkBusy(void)
{
	LCD_DATA_DIR &= ~LCD_DATA;	//SET DATA PORT IN =0
	LCD_RS_PORT &= ~LCD_RS;		//RS=0
	LCD_RW_PORT |= LCD_RW;		//RW=1
	LCD_EN_PORT |= LCD_EN;		//EN=1
	while(!(LCD_DATA_PIN&0x80)==0)
	{
		;
	}
	LCD_EN_PORT &= ~LCD_EN;		//EN=0
	LCD_DATA_DIR |= LCD_DATA;	//SET DATA PORT OUT 1
}

unsigned char ST7920_Read()
{
	unsigned char readtmp;
	ST7920_ChkBusy();
	LCD_DATA_DIR &= ~LCD_DATA;	//SET DATA PORT IN =0
	LCD_RS_PORT |= LCD_RS;		//RS=1
	LCD_RW_PORT |= LCD_RW;		//RW=1
	LCD_EN_PORT |= LCD_EN;		//EN=1
	delay_nus(1);
	readtmp=LCD_DATA_PIN;
	LCD_EN_PORT &= ~LCD_EN;		//EN=0
	LCD_DATA_DIR |= LCD_DATA;	//SET DATA PORT OUT 1
	return readtmp;
}

void ST7920_SendCmd(unsigned char cmd)			//write command to ST7920
{
	ST7920_ChkBusy();
	LCD_DATA_PORT = cmd;
	LCD_RS_PORT &= ~LCD_RS;		//RS=0
	LCD_RW_PORT &= ~LCD_RW;		//RW=0
	LCD_EN_PORT |= LCD_EN;		//EN=1
	delay_nus(1);
	LCD_EN_PORT &= ~LCD_EN;		//EN=0
	delay_nus(1);
	LCD_DATA_PORT = 0xff;
}

void ST7920_SendData(unsigned char dat)			//write data to ST7920
{
	ST7920_ChkBusy();
	LCD_DATA_PORT = dat;
	LCD_RS_PORT |= LCD_RS;		//RS=1
	LCD_RW_PORT &= ~LCD_RW;		//RW=0
	LCD_EN_PORT |= LCD_EN;		//EN=1
	delay_nus(1);
	LCD_EN_PORT &= ~LCD_EN;		//EN=0
	delay_nus(1);
	LCD_DATA_PORT = 0xff;
}
void LCD_Init(void)
{
	delay_nms(10);
	ST7920_SendCmd(0x30);		//function set :8-bit interface
	delay_nms(1);
	ST7920_SendCmd(0x30);		//basic instruction
	delay_nms(1);
	ST7920_SendCmd(0x0c);		//display on,cursor off,blink off
	delay_nms(10);
	ST7920_SendCmd(0x01);		//display clear
	delay_nms(10);
	ST7920_SendCmd(0x06);		//cursor move right AC increased by 1,display not shift
	delay_nms(10);
}

void LCD_SetXY(unsigned char x, unsigned char y )
{
	unsigned char address;
	switch(y)
	{
		case 0:
		{
			address = 0x80 + x;
			break;
		}
		case 1:
		{
			address = 0x90 + x;
			break;
		}
		case 2:
		{
			address = 0x88 + x;
			break;
		}
		case 3:
		{
			address = 0x98 + x;
			break;
		}
		default:address = 0x80 + x;
	}
	ST7920_SendCmd(address);
}

void LCD_WriteString(unsigned char X,unsigned char Y,unsigned char *s)
{
	LCD_SetXY( X, Y );
	while(*s)
	{
		ST7920_SendData(*s);
		*s ++;
		delay_nms(1);
	}
}

unsigned int LCD_Read16BIT(unsigned char X, unsigned char Y)
{
        unsigned int tempread;
          ST7920_SendCmd(0x34);
          ST7920_SendCmd(Y);
          ST7920_SendCmd(X);
          ST7920_SendCmd(0x30);
          ST7920_Read();
          tempread=(unsigned int)ST7920_Read();
          tempread=tempread<<8;
          tempread+=(unsigned int)ST7920_Read();
        return tempread;        
}

void LCD_DrawPoint(unsigned char X, unsigned char Y, unsigned char COLOR)
{
        unsigned char x,y,xb;
        unsigned char tmpv[2];
        unsigned int tmprd;
        unsigned char MASK[8]={0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
        x=(X >> 4) + 8*(Y >> 5);
        y=Y & 0x1f;
        x+=0x80;
        y+=0x80;
        xb=X & 0x0f;
        tmprd=LCD_Read16BIT(x,y);
        tmpv[1]=(unsigned char)tmprd;
        tmprd=tmprd>>8;
        tmpv[0]=(unsigned char)tmprd; 
        if( (COLOR&0x01) != 0 )
        {
          tmpv[xb>>3] |= MASK[xb&0x07];
        }
        else
        {
          tmpv[xb>>3] &= (~MASK[xb&0x07]);
        }
        ST7920_SendCmd(0x34);
        ST7920_SendCmd(y);
        ST7920_SendCmd(x);
        ST7920_SendCmd(0x30);
        ST7920_SendData(tmpv[0]);
        ST7920_SendData(tmpv[1]);
        ST7920_SendCmd(0x36);
}



⌨️ 快捷键说明

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