这是一个基于AVR单片机的3510i彩色液晶显示图片的范例

源代码在线查看: 3510i.c

软件大小: 13 K
上传用户: IsABC
关键词: 3510i AVR 单片机 彩色
下载地址: 免注册下载 普通下载 VIP

相关代码

				#include "3510i.h"
				
				void LCD_Delay(void)
				{
					uint16_t i;
					for(i = 0; i < 32768; i ++)
						asm("NOP");
				}
				
				void LCD_Reset(void)
				{
					cbi(LCD_RST_PORT, LCD_RST);		//set RST = L
					LCD_Delay();
					sbi(LCD_RST_PORT, LCD_RST);		//set RST = H
					LCD_Delay();
				}
				
				void LCD_SendCommand(uint8_t cmd)
				{
					sbi(LCD_SIO_DDR, LCD_SIO);		//set SDI.DDR = 1
					cbi(LCD_CS_PORT, LCD_CS);		//set CS = L
					cbi(LCD_SCL_PORT, LCD_SCL);		//set SCK = L
					cbi(LCD_SIO_PORT, LCD_SIO);		//send 0, for command
					sbi(LCD_SCL_PORT, LCD_SCL);		//set SCK = H, latch data
				//Bit 0(MSB)
					cbi(LCD_SCL_PORT, LCD_SCL);
					if(cmd & 0x80)
						sbi(LCD_SIO_PORT, LCD_SIO);
					else
						cbi(LCD_SIO_PORT, LCD_SIO);
					sbi(LCD_SCL_PORT, LCD_SCL);
				//Bit 1
					cbi(LCD_SCL_PORT, LCD_SCL);
					if(cmd & 0x40)
						sbi(LCD_SIO_PORT, LCD_SIO);
					else
						cbi(LCD_SIO_PORT, LCD_SIO);
					sbi(LCD_SCL_PORT, LCD_SCL);
				//Bit 2
					cbi(LCD_SCL_PORT, LCD_SCL);
					if(cmd & 0x20)
						sbi(LCD_SIO_PORT, LCD_SIO);
					else
						cbi(LCD_SIO_PORT, LCD_SIO);
					sbi(LCD_SCL_PORT, LCD_SCL);
				//Bit 3
					cbi(LCD_SCL_PORT, LCD_SCL);
					if(cmd & 0x10)
						sbi(LCD_SIO_PORT, LCD_SIO);
					else
						cbi(LCD_SIO_PORT, LCD_SIO);
					sbi(LCD_SCL_PORT, LCD_SCL);
				//Bit 4
					cbi(LCD_SCL_PORT, LCD_SCL);
					if(cmd & 0x08)
						sbi(LCD_SIO_PORT, LCD_SIO);
					else
						cbi(LCD_SIO_PORT, LCD_SIO);
					sbi(LCD_SCL_PORT, LCD_SCL);
				//Bit 5
					cbi(LCD_SCL_PORT, LCD_SCL);
					if(cmd & 0x04)
						sbi(LCD_SIO_PORT, LCD_SIO);
					else
						cbi(LCD_SIO_PORT, LCD_SIO);
					sbi(LCD_SCL_PORT, LCD_SCL);
				//Bit 6
					cbi(LCD_SCL_PORT, LCD_SCL);
					if(cmd & 0x02)
						sbi(LCD_SIO_PORT, LCD_SIO);
					else
						cbi(LCD_SIO_PORT, LCD_SIO);
					sbi(LCD_SCL_PORT, LCD_SCL);
				//Bit 7(LSB)
					cbi(LCD_SCL_PORT, LCD_SCL);
					if(cmd & 0x01)
						sbi(LCD_SIO_PORT, LCD_SIO);
					else
						cbi(LCD_SIO_PORT, LCD_SIO);
					sbi(LCD_SCL_PORT, LCD_SCL);
				//done
				}
				
				void LCD_SendData(uint8_t data)
				{
					sbi(LCD_SIO_DDR, LCD_SIO);		//set SDI.DDR = 1
					cbi(LCD_CS_PORT, LCD_CS);		//set CS = L
					cbi(LCD_SCL_PORT, LCD_SCL);		//set SCK = L
					sbi(LCD_SIO_PORT, LCD_SIO);		//send 1, for command
					sbi(LCD_SCL_PORT, LCD_SCL);		//set SCK = H, latch data
				//Bit 0(MSB)
					cbi(LCD_SCL_PORT, LCD_SCL);
					if(data & 0x80)
						sbi(LCD_SIO_PORT, LCD_SIO);
					else
						cbi(LCD_SIO_PORT, LCD_SIO);
					sbi(LCD_SCL_PORT, LCD_SCL);
				//Bit 1
					cbi(LCD_SCL_PORT, LCD_SCL);
					if(data & 0x40)
						sbi(LCD_SIO_PORT, LCD_SIO);
					else
						cbi(LCD_SIO_PORT, LCD_SIO);
					sbi(LCD_SCL_PORT, LCD_SCL);
				//Bit 2
					cbi(LCD_SCL_PORT, LCD_SCL);
					if(data & 0x20)
						sbi(LCD_SIO_PORT, LCD_SIO);
					else
						cbi(LCD_SIO_PORT, LCD_SIO);
					sbi(LCD_SCL_PORT, LCD_SCL);
				//Bit 3
					cbi(LCD_SCL_PORT, LCD_SCL);
					if(data & 0x10)
						sbi(LCD_SIO_PORT, LCD_SIO);
					else
						cbi(LCD_SIO_PORT, LCD_SIO);
					sbi(LCD_SCL_PORT, LCD_SCL);
				//Bit 4
					cbi(LCD_SCL_PORT, LCD_SCL);
					if(data & 0x08)
						sbi(LCD_SIO_PORT, LCD_SIO);
					else
						cbi(LCD_SIO_PORT, LCD_SIO);
					sbi(LCD_SCL_PORT, LCD_SCL);
				//Bit 5
					cbi(LCD_SCL_PORT, LCD_SCL);
					if(data & 0x04)
						sbi(LCD_SIO_PORT, LCD_SIO);
					else
						cbi(LCD_SIO_PORT, LCD_SIO);
					sbi(LCD_SCL_PORT, LCD_SCL);
				//Bit 6
					cbi(LCD_SCL_PORT, LCD_SCL);
					if(data & 0x02)
						sbi(LCD_SIO_PORT, LCD_SIO);
					else
						cbi(LCD_SIO_PORT, LCD_SIO);
					sbi(LCD_SCL_PORT, LCD_SCL);
				//Bit 7(LSB)
					cbi(LCD_SCL_PORT, LCD_SCL);
					if(data & 0x01)
						sbi(LCD_SIO_PORT, LCD_SIO);
					else
						cbi(LCD_SIO_PORT, LCD_SIO);
					sbi(LCD_SCL_PORT, LCD_SCL);
				//done
				}
				
				void LCD_ReadDummy(void)
				{
					cbi(LCD_SIO_DDR, LCD_SIO);		//set SDI.DDR = 0
					sbi(LCD_SIO_PORT, LCD_SIO);	
					cbi(LCD_CS_PORT, LCD_CS);		//set CS = L
					cbi(LCD_SCL_PORT, LCD_SCL);
					sbi(LCD_SCL_PORT, LCD_SCL);
				}
				
				uint16_t LCD_ReadData(void)
				{
					uint16_t r = 0;
					cbi(LCD_SIO_DDR, LCD_SIO);		//set SDI.DDR = 0
					sbi(LCD_SIO_PORT, LCD_SIO);	
					cbi(LCD_CS_PORT, LCD_CS);		//set CS = L
				//Bit 0(MSB)
					cbi(LCD_SCL_PORT, LCD_SCL);
					sbi(LCD_SCL_PORT, LCD_SCL);
					if(bit_is_set(LCD_SIO_PIN, LCD_SIO))
						r |= 0x800;
					else
						r &= ~0x800;
				//Bit 1
					cbi(LCD_SCL_PORT, LCD_SCL);
					sbi(LCD_SCL_PORT, LCD_SCL);
					if(bit_is_set(LCD_SIO_PIN, LCD_SIO))
						r |= 0x400;
					else
						r &= ~0x400;
				//Bit 2
					cbi(LCD_SCL_PORT, LCD_SCL);
					sbi(LCD_SCL_PORT, LCD_SCL);
					if(bit_is_set(LCD_SIO_PIN, LCD_SIO))
						r |= 0x200;
					else
						r &= ~0x200;
				//Bit 3
					cbi(LCD_SCL_PORT, LCD_SCL);
					sbi(LCD_SCL_PORT, LCD_SCL);
					if(bit_is_set(LCD_SIO_PIN, LCD_SIO))
						r |= 0x100;
					else
						r &= ~0x100;
				//Bit 4
					cbi(LCD_SCL_PORT, LCD_SCL);
					sbi(LCD_SCL_PORT, LCD_SCL);
					if(bit_is_set(LCD_SIO_PIN, LCD_SIO))
						r |= 0x080;
					else
						r &= ~0x080;
				//Bit 5
					cbi(LCD_SCL_PORT, LCD_SCL);
					sbi(LCD_SCL_PORT, LCD_SCL);
					if(bit_is_set(LCD_SIO_PIN, LCD_SIO))
						r |= 0x040;
					else
						r &= ~0x040;
				//Bit 6
					cbi(LCD_SCL_PORT, LCD_SCL);
					sbi(LCD_SCL_PORT, LCD_SCL);
					if(bit_is_set(LCD_SIO_PIN, LCD_SIO))
						r |= 0x020;
					else
						r &= ~0x020;
				//Bit 7
					cbi(LCD_SCL_PORT, LCD_SCL);
					sbi(LCD_SCL_PORT, LCD_SCL);
					if(bit_is_set(LCD_SIO_PIN, LCD_SIO))
						r |= 0x010;
					else
						r &= ~0x010;
				//Bit 8
					cbi(LCD_SCL_PORT, LCD_SCL);
					sbi(LCD_SCL_PORT, LCD_SCL);
					if(bit_is_set(LCD_SIO_PIN, LCD_SIO))
						r |= 0x008;
					else
						r &= ~0x008;
				//Bit 9
					cbi(LCD_SCL_PORT, LCD_SCL);
					sbi(LCD_SCL_PORT, LCD_SCL);
					if(bit_is_set(LCD_SIO_PIN, LCD_SIO))
						r |= 0x004;
					else
						r &= ~0x004;
				//Bit 10
					cbi(LCD_SCL_PORT, LCD_SCL);
					sbi(LCD_SCL_PORT, LCD_SCL);
					if(bit_is_set(LCD_SIO_PIN, LCD_SIO))
						r |= 0x002;
					else
						r &= ~0x002;
				//Bit 11(LSB)
					cbi(LCD_SCL_PORT, LCD_SCL);
					sbi(LCD_SCL_PORT, LCD_SCL);
					if(bit_is_set(LCD_SIO_PIN, LCD_SIO))
						r |= 0x001;
					else
						r &= ~0x001;
				//done
					return r;
				}
				
				void LCD_Initialize(void)
				{
					uint8_t i;
				
					sbi(LCD_RST_PORT, LCD_RST);		//set RST = H
					sbi(LCD_RST_DDR, LCD_RST);	//set RST.DDR = 1
					sbi(LCD_CS_PORT, LCD_CS);		//set CS = H
					sbi(LCD_CS_DDR, LCD_CS);	//set CS.DDR = 1
					cbi(LCD_SIO_PORT, LCD_SIO);		//set SDI = L
					cbi(LCD_SIO_DDR, LCD_SIO);	//set SDI.DDR = 0
					sbi(LCD_SCL_PORT, LCD_SCL);		//set SCK = H
					sbi(LCD_SCL_DDR, LCD_SCL);	//set SCK.DDR = 1
				
					LCD_Reset();
				
					LCD_SendCommand(0x01);		//software reset
					LCD_DataOver();
					LCD_Delay();
				
					LCD_SendCommand(0xc6);		//initial escape
					LCD_DataOver();
				
					LCD_SendCommand(0xb9);		//refresh set
					LCD_SendData(0x00);
					LCD_DataOver();
				
					LCD_SendCommand(0xb6);		//display control
					LCD_SendData(0x80);
					LCD_SendData(0x80);
					LCD_SendData(0x81);
					LCD_SendData(84);
					LCD_SendData(69);
					LCD_SendData(82);
					LCD_SendData(67);
					LCD_DataOver();
				
					LCD_SendCommand(0xb3);		//gray scale position set
					LCD_SendData(1);
					LCD_SendData(2);
					LCD_SendData(4);
					LCD_SendData(8);
					LCD_SendData(16);
					LCD_SendData(30);
					LCD_SendData(40);
					LCD_SendData(50);
					LCD_SendData(60);
					LCD_SendData(70);
					LCD_SendData(80);
					LCD_SendData(90);
					LCD_SendData(100);
					LCD_SendData(110);
					LCD_SendData(127);
					LCD_DataOver();
				
					LCD_SendCommand(0xb5);		//gamma curve set
					LCD_SendData(0x01);
					LCD_DataOver();
				
					LCD_SendCommand(0xbd);		//common driver output select
					LCD_SendData(0x00);
					LCD_DataOver();
				
					LCD_SendCommand(0xbe);		//power control
					LCD_SendData(0x04);
					LCD_DataOver();
				
					LCD_SendCommand(0x11);		//sleep out
					LCD_DataOver();
					
					LCD_SendCommand(0xba);		//voltage control
					LCD_SendData(127);
					LCD_SendData(3);
					LCD_DataOver();
				
					LCD_SendCommand(0xb7);		//temperature gradient set
					for(i = 0; i < 14; i ++)
						LCD_SendData(0x00);
					LCD_DataOver();
				
					LCD_SendCommand(0x29);		//display ON
					LCD_DataOver();
				
					LCD_SendCommand(0x03);		//booster voltage ON
					LCD_DataOver();
					LCD_Delay();
				
					LCD_SendCommand(0x20);		//display inversion OFF
					LCD_DataOver();
					
					LCD_SendCommand(0x25);		//write contrast
					LCD_SendData(72);
					LCD_DataOver();
					
					LCD_BGColor = 0x000;
					LCD_PenColor = 0xfff;
				}
				
				void LCD_ClearScreen(void)
				{
					uint8_t x, y;
					LCD_SendCommand(0x2a);		//column address set
					LCD_SendData(0);
					LCD_SendData(97);
					LCD_DataOver();
				
					LCD_SendCommand(0x2b);		//page address set
					LCD_SendData(0);
					LCD_SendData(66);
					LCD_DataOver();
					
					LCD_SendCommand(0x2c);		//memory write
					for(y = 0; y < 67; y ++)
						for(x = 0; x < 98; x += 2)
						{
							LCD_SendData(LCD_BGColor >> 4);
							LCD_SendData(((LCD_BGColor & 0x00f) > 8));
							LCD_SendData(LCD_BGColor & 0x0ff);
						}
					LCD_DataOver();
				}
				
				void LCD_BlockWrite(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t *b)
				{
					uint8_t x, y;
					LCD_SendCommand(0x2a);		//column address set
					LCD_SendData(x1);
					LCD_SendData(x2);
					LCD_DataOver();
				
					LCD_SendCommand(0x2b);		//page address set
					LCD_SendData(y1);
					LCD_SendData(y2);
					LCD_DataOver();
				
					LCD_SendCommand(0x2c);		//memory write
					for(y = y1; y 						for(x = x1; x 						{
							LCD_SendData(*(b ++));
							LCD_SendData(*(b ++));
							LCD_SendData(*(b ++));
						}
					LCD_DataOver();
				}
							

相关资源