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

📄 my_nokia6610.c

📁 GPS DEMO CODE FOR NOKIA6610 LCD,下载于OURAVR.COM.
💻 C
字号:
#include "LCD_6610_Config.h"
#include "LCD_ASCII.h"

uint8 Red   =0x00;
uint8 Green =0x00;
uint8 Blue  =0x00;

uint8 CurX_MIN = X_MIN;
uint8 CurX_MAX = X_MAX;
uint8 CurY_MIN = Y_MIN;
uint8 CurY_MAX = Y_MAX;


void Init_LCD_PORT()//配置引脚最初状态
{
	_LCD_CS_H;//引脚配置为高,输出
	_LCD_RST_H;
	LCD_SDATA_H;
	LCD_SCLK_L;
	DDR_LCD_6610 |= (1<<_LCD_CS) | (1<<LCD_SDATA)
				 | (1<<_LCD_RST) | (1<<LCD_SCLK);
}

void LCD_6610_Reset()//液晶复位
{
	_LCD_RST_L;
	_delay_us(100);
	_LCD_RST_H;
	_delay_ms(50);
}

uint8 LCD_6610_ReadOneByte()//读1Byte数据LCD_SCLK_L
{
	uint8  i;
	uint8  dat = 0;
	dat = 0;
	for(i=0; i<8; i++)
	{
		LCD_SCLK_H;
		LCD_SCLK_L;
		asm("nop");
		if(Get_LCD_SDATA)
		{
			dat |= (1<<(7-i));
		}
	}
	return dat;
}

void LCD_6610_ReadDat(uint8 *dat, uint8 n)//读数据
{
	uint8 i;
	LCD_SDATA_IN;//数据线配置为输入
	for(i=0; i<n; i++)
	{
		*(dat++) = LCD_6610_ReadOneByte();//读数据LCD_SCLK_L,LCD_SDATA_H
	}
	LCD_SDATA_OUT;//数据线配置为输出
}

void LCD_6610_ReadDev(uint8 cmd, uint8 *dat, uint8 n)//读设备ID,Status
{
	_LCD_CS_L;
	LCD_6610_WriteCmd(cmd);    //写指令
	LCD_6610_ReadDat(dat, n);  //读数据
	_LCD_CS_H;
}

void LCD_6610_Booster(uint8 OnOff)//后备电源开关ON/OFF
{
	_LCD_CS_L;//选通
	if(OnOff == ON)
	{
		LCD_6610_WriteCmd(LCD_Sleep_OUT); //写指令,0x11
		LCD_6610_WriteCmd(LCD_DISPON);    //写指令,0x29
		LCD_6610_WriteCmd(LCD_BSTRON);    //写指令,0x03
	//	LCD_6610_WriteCmd(LCD_DAL);       //写指令,0x23所有"点"亮
	}
	else if(OnOff == OFF)
	{
		LCD_6610_WriteCmd(LCD_DISPOFF);  //写指令,0x28
		LCD_6610_WriteCmd(LCD_BSTROFF);  //写指令,0x02
//		LCD_6610_WriteCmd(LCD_DALO);     //写指令,0x22所有"点"灭
	}
	_LCD_CS_H;//	
}

void LCD_6610_WindowRec(uint8 xs, uint8 xe, uint8 ys, uint8 ye)//设置显示区大小
{
	_LCD_CS_L;//选通
	LCD_6610_WriteCmd(LCD_CASET);      //写指令,0x2A
	LCD_6610_WriteDat(xs);             //写数据,xs
	LCD_6610_WriteDat(xe);             //写数据,xe
	LCD_6610_WriteCmd(LCD_PASET);      //写指令,0x2B
	LCD_6610_WriteDat(ys);             //写数据,ys
	LCD_6610_WriteDat(ye);             //写数据,ye
	_LCD_CS_H;//	
}

void LCD_6610_WindowRAMAccess(uint8 mode)//窗口显示模式
{
	_LCD_CS_L;
	LCD_6610_WriteCmd(LCD_MADCTL);      //写指令,0x36
	LCD_6610_WriteDat(mode);            //写数据,
	_LCD_CS_H;
}

void LCD_6610_RGBMode()//颜色模式
{
	_LCD_CS_L;
	LCD_6610_WriteCmd(LCD_COLMOD);      //写指令,0x3A
	LCD_6610_WriteDat(RGB);             //写数据,RGB565,16-bit/pixel
	_LCD_CS_H;
}

void LCD_6610_BrightBlack(uint8 bb)//对比度调节
{
	_LCD_CS_L;
	LCD_6610_WriteCmd(LCD_SETCON);      //写指令,0x25
	LCD_6610_WriteDat(bb);             //写数据,RGB565,16-bit/pixel
	_LCD_CS_H;
}

void LCD_6610_DspMode(uint8 mode, uint8 x1,
				 uint8 x2, uint8 x3, uint8 x4)//显示模式
{
	_LCD_CS_L;
	if(mode == LCD_NORON)               //正常显示,0x13,LCD_NORON
	{
		LCD_6610_WriteCmd(LCD_NORON);   //写指令,0x13
	}
	else if(mode == LCD_PTLON)          //部分显示,0x12,LCD_PTLON
	{
		LCD_6610_WriteCmd(LCD_PTLAR);   //写指令,0x30
		LCD_6610_WriteDat(x1);          //写数据,AA1S
		LCD_6610_WriteDat(x2);          //写数据,SS1E
		LCD_6610_WriteCmd(LCD_PTLON);   //写指令,0x12,部分显示模式
	}
	else if(mode == LCD_SEP)//滚动显示,0x37,LCD_SEP
	{
		LCD_6610_WriteCmd(LCD_VSCRDEF); //写指令,0x33
		LCD_6610_WriteDat(x1);          //写数据,TF
		LCD_6610_WriteDat(x2);          //写数据,SA
		LCD_6610_WriteDat(x3);          //写数据,BF
		LCD_6610_WriteCmd(LCD_SEP);     //写指令,0x37,滚动模式
		LCD_6610_WriteDat(x4);          //写数据,SEP

	}
	else
	{
	}
	_LCD_CS_H;
}

void ClearRAM()//清空RAM
{
	uint16 i;
	LCD_6610_WindowRec(X_MIN, X_MAX, Y_MIN, Y_MAX); //设置显示区大小(xs,xe,ys,ye)
	_LCD_CS_L;//选通
	LCD_6610_WriteCmd(LCD_RAMWR);      //写指令,0x2C,写RAM
	for(i=0; i<(uint16)((uint8)X_MAX*(uint8)Y_MAX*2); i++)
	{
		LCD_6610_WriteDat(0xff);
	}
	_LCD_CS_H;//
}

void Init_LCD_Dev()//初始化LCD
{
	LCD_6610_Reset();                        //复位
	ClearRAM();                              //清空RAM
	LCD_6610_RGBMode();                      //颜色模式
	LCD_6610_Booster(ON);                    //后备电源开关ON/OFF
	LCD_6610_WindowRec(  0, 130,   0, 132);  //设置显示区大小(xs,xe,ys,ye)
	LCD_6610_DspMode(LCD_NORON, 0, 0, 0, 0); //显示模式,正常
	LCD_6610_WindowRAMAccess(0xC0);          //窗口显示模式(MY,MX,V,LAO,RGB,x,x,x)
	LCD_6610_BrightBlack(0x37);              //对比度调节
}

void LCD_6610_WritePoint(uint8 x, uint8 y, uint8 dot)//写入或消去一点(x,y)
{
	LCD_6610_WindowRec(x, X_MAX, y, Y_MAX);   //设置显示区大小(xs,xe,ys,ye)
	_LCD_CS_L;//选通
	LCD_6610_WriteCmd(LCD_RAMWR);             //写指令,0x2C,写RAM
	LCD_6610_W1RGBDot(Red, Green, Blue, dot);//写入一个点
	_LCD_CS_H;//	
}

void LCD_6610_DrawLine(uint8 xs, uint8 ys, uint8 xe, uint8 ye)//画线函数
{
	uint16 x;
	uint16 y;
	uint8 i;
	if(xs > xe)
	{
		x  = xs;
		y  = ys;
		xs = xe;
		ys = ye;
		xe = x;
		ye = y;
	}
	if(xs == xe)
	{
		if(ys == ye)
		{
			x = xe;
			y = ye;
			LCD_6610_WritePoint(x, y, 1);//写入或消去一点(x,y)//;;;;;
		}
		if(ys > ye)
		{
			y  = ys;
			ys = ye;
			ye = y;
		}
		for(i=ys; i<ye; i++)
		{
			LCD_6610_WritePoint(xe, i, 1);//写入或消去一点(x,y)//''
		}
		goto END;
	}

	if(ys < ye)
	{
		if((ye-ys) <= (xe-xs))//用x坐标
		{
			for(i=xs; i<xe; i++)
			{
				x = i;
				y = ye -((xe-x)*(ye-ys)/(xe-xs));
				LCD_6610_WritePoint(x, y, 1);//写入或消去一点(x,y)
			}
		}
		else//用y坐标
		{
			for(i=ys; i<ye; i++)
			{
				y = i;
				x = xe - ((ye-y)*(xe-xs)/(ye-ys));
				LCD_6610_WritePoint(x, y, 1);//写入或消去一点(x,y)
			}
		}
	}

	if(ys > ye)
	{
		if((ys-ye) <= (xe-xs))//用x坐标
		{
			for(i=xs; i<xe; i++)
			{
				x = i;
				y = ye +((xe-x)*(ys-ye)/(xe-xs));
				LCD_6610_WritePoint(x, y, 1);//写入或消去一点(x,y)
			}
		}
		else//用y坐标
		{
			for(i=ye; i<ys; i++)
			{
				y = i;
				x = xe - ((y-ye)*(xe-xs)/(ys-ye));
				LCD_6610_WritePoint(x, y, 1);//写入或消去一点(x,y)
			}
		}
	}

	if(ys == ye)
	{
		for(i=xs; i<xe; i++)
		{
			LCD_6610_WritePoint(i, ys, 1);//写入或消去一点(x,y)//''
		}
	}

	END:
	x=xe;
	y=ye;
}

void LCD_6610_ShowGraphic(uint8 xs, uint8 ys,
	 uint8 x_dot, uint8 y_dot, prog_char *pG)//写入位图(xs,ys,x_dot,y_dot,pG)
{
	uint16 i;
	uint16 pels;
	LCD_6610_DspMode(LCD_NORON, 0, 0, 0, 0);  //显示模式,正常
	pels = x_dot*y_dot*2;
	LCD_6610_WindowRec(xs, xs+x_dot-1, ys, ys+y_dot-1); //设置显示区大小(xs,xe,ys,ye)
	_LCD_CS_L;//选通
	LCD_6610_WriteCmd(LCD_RAMWR);      //写指令,0x2C,写RAM
	for(i=0; i<pels; i++)
	{
		LCD_6610_WriteDat(pgm_read_byte(pG++));
	}
	_LCD_CS_H;//	
}

void LCD_ShowChar(uint8 x, uint8 y, uint8 pchar)//显示字符
{
	uint8 i;
	uint8 j;
	uint8 char_addr;
	LCD_6610_WindowRec(x, x+8-1, y, y+16-1); //设置显示区大小(xs,xe,ys,ye)
	_LCD_CS_L;//选通
	LCD_6610_WriteCmd(LCD_RAMWR);            //写指令,0x2C,写RAM
	for(i=0; i<16; i++)
	{
		for(j=0; j<8; j++)
		{
			char_addr = (pgm_read_byte(nAsciiDot+16*(pchar-' ')+i));
			LCD_6610_W1RGBDot(Red, Green, Blue, (char_addr&(1<<(7-j))));
		}
	}
	_LCD_CS_H;//	
}

void LCD_ShowStr(uint8 xs, uint8 ys, uint8 *str)//显示字符串
{
	uint16 i;
	uint8  x;
	uint8  y;
	x = xs;
	y = ys;
	for(i=0; (*str)!='\0'; i++)
	{
		if(x > (CurX_MAX-8))//满一行
		{
			y += 16;
			x = CurX_MIN;
			if(y > CurY_MAX) //写出界
				break;
		}
		LCD_ShowChar(x, y, *(str++));//显示字符
		x += 8;
	}
}

uint8 Hex4ToChar(uint8 Hex4)//4位二进制转为字符
{
	uint8 hChar = 0;
	hChar = Hex4 + '0';
	if(Hex4 > 9)
		hChar += ('A'-'9'-1);
	return hChar;
}

void LCD_ShowHex(uint8 xs, uint8 ys, uint8 hex)//显示HEX
{
	uint8 hexl;
	uint8 hexh;
	hexl = Hex4ToChar(hex & 0x0f);
	hexh = Hex4ToChar(hex>>4);
	LCD_ShowChar(xs, ys, hexh);//显示字符
	if(xs > (CurX_MAX-8))//超过一行
	{
		xs = CurX_MIN;
		ys += 16;
		if(ys > CurY_MAX) //写出界
			ys -= 16;//原地写
	}
	LCD_ShowChar(xs + 8, ys, hexl);//显示字符
}

void LCD_ShowDen(uint8 xs, uint8 ys, uint16 den)//显示十进制数据
{
	uint16 denx;
	uint8  dens = 0;
	uint8  wei  = 0;
	denx = den;
	if(den > 9999)
	{
		dens = denx / 10000;
		denx -= dens*10000;
		LCD_ShowChar(xs + wei, ys, dens+'0');//显示字符
		wei +=8;
	}
	if(den > 999)
	{
		dens = denx / 1000;
		denx -= dens*1000;
		LCD_ShowChar(xs + wei, ys, dens+'0');//显示字符
		wei +=8;
	}
	if(den > 99)
	{
		dens = denx / 100;
		denx -= dens*100;
		LCD_ShowChar(xs + wei, ys, dens+'0');//显示字符
		wei +=8;
	}
	if(den > 9)
	{
		dens = denx / 10;
		denx -= dens*10;
		LCD_ShowChar(xs + wei, ys, dens+'0');//显示字符
		wei +=8;
	}
	dens = denx;
	LCD_ShowChar(xs + wei, ys, dens+'0');//显示字符

}

⌨️ 快捷键说明

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