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

📄 s3tft.c

📁 全新三星lcd 开发源码, 采用芯片LTS180S3 HD66773
💻 C
字号:
#include "S3TFT.h"
#include <avr/signal.h>

unsigned int z[35][32]=
{ 
{0x02,0x00,0x01,0x00,0x00,0x00,0x1F,0x00,
0x01,0x08,0x01,0x18,0x7D,0xA0,0x05,0x40,
0x05,0x40,0x09,0x20,0x09,0x20,0x11,0x10,
0x21,0x0E,0x41,0x04,0x05,0x00,0x02,0x00},  //永

{0x00,0x10,0x43,0xF8,0x30,0x00,0x10,0x00,
0x00,0x08,0x07,0xFC,0xF1,0x20,0x11,0x20,
0x11,0x20,0x11,0x24,0x12,0x24,0x12,0x1C,
0x14,0x00,0x28,0x06,0x47,0xFC,0x00,0x00},  //远
{0x10,0x00,0x12,0x7C,0x7F,0x44,0x12,0x44,
0x14,0x48,0xFF,0x48,0x08,0x50,0x12,0x48,
0x3F,0x44,0x62,0x42,0xA2,0x42,0x3E,0x62,
0x22,0x54,0x22,0x48,0x3E,0x40,0x22,0x40}, //都
{0x00,0x04,0xFF,0xFE,0x00,0x80,0x00,0x80,
0x01,0x00,0x01,0x00,0x03,0x40,0x05,0x20,
0x09,0x18,0x11,0x0C,0x21,0x04,0x41,0x00,
0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00},//不
{0x00,0x08,0x7F,0xFC,0x04,0x40,0x3F,0xF8,
0x24,0x48,0x24,0x48,0x3F,0xF8,0x02,0x00,
0x02,0x04,0xFF,0xFE,0x04,0x20,0x08,0x20,
0x06,0x40,0x01,0x80,0x06,0x60,0x38,0x10},//要
{0x10,0x80,0x10,0x48,0x17,0xFC,0x20,0x00,
0x23,0xF8,0x62,0x08,0xA3,0xF8,0x20,0x00,
0x2F,0xFE,0x28,0x02,0x33,0xF4,0x20,0x40,
0x20,0x40,0x20,0x40,0x21,0x40,0x20,0x80},//停
{0x01,0x00,0x01,0x00,0x01,0x00,0x11,0x00,
0x11,0x00,0x11,0x10,0x11,0xF8,0x11,0x00,
0x11,0x00,0x11,0x00,0x11,0x00,0x11,0x00,
0x11,0x00,0x11,0x04,0xFF,0xFE,0x00,0x00},//止
{0x12,0x10,0x12,0x10,0x2A,0x90,0x4A,0xA4,
0x8A,0xBE,0x1F,0xC4,0x20,0x24,0x7F,0xA8,
0xA0,0x28,0x2F,0x28,0x29,0x10,0x29,0x50,
0x29,0xA8,0x29,0x28,0x30,0x46,0x20,0x84},//微
{0x10,0x40,0x12,0x48,0x1F,0x7C,0x28,0xA0,
0x45,0x10,0x00,0xF8,0x3F,0x00,0x01,0x00,
0x01,0x04,0xFF,0xFE,0x02,0x00,0x02,0x80,
0x04,0x40,0x08,0x30,0x10,0x0E,0x60,0x04},//笑
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x18,0x00,0x18,0x00,
0x10,0x00,0x20,0x00,0x00,0x00,0x00,0x00}, //,
{0x00,0x04,0x7E,0xFE,0x42,0x84,0x42,0x84,
0x7E,0x84,0x42,0x84,0x42,0x84,0x7E,0x84,
0x40,0x84,0x44,0xA4,0x44,0x94,0x4A,0x88,
0x72,0x80,0x40,0x80,0x00,0x80,0x00,0x80},//即
{0x10,0x40,0x10,0x44,0x1F,0xFE,0x20,0x40,
0x27,0xFC,0x64,0x44,0xA4,0x44,0x24,0x44,
0x27,0xFC,0x24,0x44,0x22,0x40,0x21,0x80,
0x20,0xC0,0x21,0x30,0x26,0x0E,0x28,0x04},//使
{0x02,0x00,0x02,0x00,0x02,0x04,0xFF,0xFE,
0x04,0x00,0x04,0x40,0x08,0x40,0x08,0x50,
0x13,0xF8,0x30,0x40,0x50,0x40,0x90,0x40,
0x10,0x40,0x10,0x44,0x17,0xFE,0x10,0x00},//在 
{0x11,0x00,0x11,0x00,0x11,0x00,0x23,0xFC,
0x22,0x04,0x64,0x08,0xA8,0x40,0x20,0x40,
0x21,0x50,0x21,0x48,0x22,0x4C,0x24,0x44,
0x20,0x40,0x20,0x40,0x21,0x40,0x20,0x80},//你
{0x00,0x60,0x04,0x50,0xFE,0x44,0x04,0xFE,
0x44,0x90,0x45,0x90,0x2A,0xFC,0x28,0x90,
0x10,0x90,0x10,0xFC,0x28,0x90,0x24,0x90,
0x44,0x94,0x80,0xFE,0x00,0x80,0x00,0x80},//难 
{0x00,0x10,0x40,0x10,0x20,0x10,0x17,0xFC,
0x00,0x10,0x00,0x10,0xF1,0x10,0x10,0x90,
0x10,0x90,0x10,0x10,0x10,0x10,0x10,0x50,
0x10,0x20,0x28,0x06,0x47,0xFC,0x00,0x00},//过
{0x10,0x40,0x10,0x40,0x22,0x44,0x7F,0x7E,
0x42,0x84,0x43,0x04,0x42,0x04,0x42,0x84,
0x7E,0x64,0x42,0x24,0x42,0x04,0x42,0x04,
0x42,0x04,0x7E,0x04,0x42,0x28,0x00,0x10},//的 
{0x00,0x08,0x04,0x08,0x7E,0x08,0x44,0x08,
0x47,0xFE,0x44,0x08,0x44,0x08,0x7C,0x88,
0x44,0x48,0x44,0x48,0x44,0x08,0x44,0x08,
0x7C,0x08,0x44,0x48,0x00,0x28,0x00,0x10},//时
{0x10,0x10,0x13,0xF8,0x20,0x10,0x28,0x14,
0x6F,0xFE,0xA9,0x00,0x29,0x08,0x2B,0xFC,
0x2C,0x40,0x28,0x44,0x2F,0xFE,0x28,0x40,
0x28,0xA0,0x21,0x10,0x22,0x0E,0x24,0x04},//候

{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x18,0x00,0x18,0x00,
0x10,0x00,0x20,0x00,0x00,0x00,0x00,0x00}, //,
{0x01,0x00,0x01,0x00,0x01,0x00,0x11,0x00,
0x11,0x30,0x11,0xD0,0x1F,0x10,0xF1,0x10,
0x11,0x10,0x11,0x50,0x11,0x20,0x11,0x02,
0x10,0x02,0x10,0x02,0x0F,0xFE,0x00,0x00},//也
{0x02,0x00,0x42,0x08,0x33,0xFC,0x12,0x40,
0x04,0x40,0x00,0x40,0xF0,0x44,0x1F,0xFE,
0x10,0x40,0x10,0x40,0x10,0x40,0x12,0x40,
0x14,0x40,0x18,0x40,0x10,0x40,0x00,0x40},//许
{0x02,0x00,0x02,0x04,0xFF,0xFE,0x04,0x00,
0x04,0x10,0x0F,0xF8,0x08,0x10,0x18,0x10,
0x2F,0xF0,0x48,0x10,0x88,0x10,0x0F,0xF0,
0x08,0x10,0x08,0x10,0x08,0x50,0x08,0x20},//有
{0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,
0x01,0x00,0x01,0x00,0x01,0x00,0x02,0x80,
0x02,0x80,0x02,0x80,0x04,0x40,0x04,0x40,
0x08,0x20,0x10,0x10,0x20,0x0E,0x40,0x04},//人
{0x01,0x00,0x01,0x00,0x02,0x80,0x04,0x40,
0x08,0x20,0x10,0x10,0x2F,0xEE,0xC0,0x04,
0x00,0x10,0x3F,0xF8,0x02,0x00,0x02,0x00,
0x04,0x40,0x08,0x20,0x1F,0xF0,0x00,0x10},//会
{0x00,0x04,0x7F,0xFE,0x41,0x04,0x41,0x04,
0x41,0x24,0x5F,0xF4,0x41,0x04,0x41,0x04,
0x42,0x84,0x42,0x84,0x44,0x44,0x48,0x34,
0x50,0x14,0x40,0x04,0x7F,0xFC,0x40,0x04},//因

{0x11,0x00,0x11,0x00,0x11,0x00,0x23,0xFC,
0x22,0x04,0x64,0x08,0xA8,0x40,0x20,0x40,
0x21,0x50,0x21,0x48,0x22,0x4C,0x24,0x44,
0x20,0x40,0x20,0x40,0x21,0x40,0x20,0x80},//你


{0x10,0x40,0x10,0x40,0x22,0x44,0x7F,0x7E,
0x42,0x84,0x43,0x04,0x42,0x04,0x42,0x84,
0x7E,0x64,0x42,0x24,0x42,0x04,0x42,0x04,
0x42,0x04,0x7E,0x04,0x42,0x28,0x00,0x10},//的 
{0x10,0x40,0x12,0x48,0x1F,0x7C,0x28,0xA0,
0x45,0x10,0x00,0xF8,0x3F,0x00,0x01,0x00,
0x01,0x04,0xFF,0xFE,0x02,0x00,0x02,0x80,
0x04,0x40,0x08,0x30,0x10,0x0E,0x60,0x04},//笑{0x02,0x00,0x01,0x00,0x7F,0xFE,0x40,0x02,

0x84,0x44,0x09,0x30,0x12,0x90,0x04,0x40,
0x08,0x20,0x10,0x10,0x2F,0xEE,0xC8,0x24,
0x08,0x20,0x08,0x20,0x0F,0xE0,0x08,0x20},//容
{0x00,0x04,0xFF,0xFE,0x02,0x00,0x02,0x00,
0x04,0x04,0x7F,0xFE,0x44,0x44,0x44,0x44,
0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,
0x44,0x44,0x44,0x44,0x44,0x54,0x40,0x08},//而
{0x00,0x78,0x3F,0x80,0x11,0x10,0x09,0x20,
0x7F,0xFE,0x42,0x02,0x82,0x04,0x7F,0xF8,
0x04,0x00,0x07,0xF0,0x0A,0x20,0x09,0x40,
0x10,0x80,0x11,0x60,0x22,0x1C,0x0C,0x08},//爱
{0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,
0x01,0x10,0x01,0xF8,0x01,0x00,0x01,0x00,
0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,
0x01,0x00,0x01,0x04,0xFF,0xFE,0x00,0x00},//上

{0x11,0x00,0x11,0x00,0x11,0x00,0x23,0xFC,
0x22,0x04,0x64,0x08,0xA8,0x40,0x20,0x40,
0x21,0x50,0x21,0x48,0x22,0x4C,0x24,0x44,
0x20,0x40,0x20,0x40,0x21,0x40,0x20,0x80},//你
{0x00,0x00,0x01,0x80,0x03,0xC0,0x03,0xC0,
0x03,0xC0,0x01,0x80,0x01,0x80,0x01,0x80,
0x01,0x80,0x01,0x80,0x00,0x00,0x00,0x00,
0x01,0x80,0x01,0x80,0x00,0x00,0x00,0x00}//!
};

void delay_1ms(void)
 {
  unsigned int i;
  for (i=1;i<1053;i++)
  ;
 }
void delay(unsigned int n)
 {
  unsigned int i=0;
  for(i=0;i<n;i++)
  delay_1ms();
 } 
 void delay_1us(void)                 
  { 
  unsigned int i; 
  for(i=0;i<2;i++) ;                                   
  } 



void Send(unsigned int a,unsigned int n)
{ 
  PORTG|=(1<<LCD_CS); 
  
  if(n)
  PORTB|= (1<<LCD_RS); //RS=1;
  else
  PORTB&=~(1<<LCD_RS); //RS=0;
  
  PORTG&=~(1<<LCD_CS);
  PORTG&=~(1<<LCD_WR);
  PORTC=(a>>8);//高8位
  PORTD=a;//低8位
  PORTG|= (1<<LCD_WR);

  
}

void LCD_Send(unsigned int Index,unsigned int Instruction)
{ 
  Send(Index,0);
  Send(Instruction,1); 
}
 
void RESET(void)
{
  PORTB|=(1<<LCD_RESET);
  delay(100);
  PORTB&=~(1<<LCD_RESET);
  delay(100);
  PORTB|=(1<<LCD_RESET);
}

void LCD_Initialize(void)
 {
  DDRB=0XFF;
  DDRG=0XFF;
  DDRD=0XFF;
  DDRC=0XFF;
  DDRE=0XFF;
  RESET();
  
  LCD_Send(0x0000,0x0001);
  delay(10);
  //初始化函数1
  LCD_Send(0x0001,0x0115);//驱动输出模式控制,分辨率,//0115
  LCD_Send(0x0002,0x0700);//波形控制
  LCD_Send(0x0005,0x1030);//模式设置,扫描方式//1030
  LCD_Send(0x0006,0x0000);
  LCD_Send(0x0007,0x0104);//显示控制
  LCD_Send(0x000B,0x0000); //帧循环控制//
  //电源设置函数
  LCD_Send(0x000C,0x0000);//电源
  LCD_Send(0x000D,0x0401);
  LCD_Send(0x000E,0x0D18);
  delay(40);
  LCD_Send(0x0003,0X0214);//鲜艳度//0214
  LCD_Send(0x0004,0x8000);
  delay(40);
  LCD_Send(0x000E,0x2910);
  delay(40);
  LCD_Send(0x000D,0x0512);
  //初始化函数2
  LCD_Send(0x0021,0x0100);
  LCD_Send(0x0030,0x0000);//伽码设置;
  LCD_Send(0x0031,0x0000);
  LCD_Send(0x0032,0x0000);
  LCD_Send(0x0033,0x0000);
  LCD_Send(0x0034,0x0000);
  LCD_Send(0x0035,0x0707);
  LCD_Send(0x0036,0x0707);
  LCD_Send(0x0037,0x0000);  
  LCD_Send(0x000F,0x0000);
  LCD_Send(0x0011,0x0000);
  LCD_Send(0x0014,0x5C00);
  LCD_Send(0x0015,0xA05D);
  LCD_Send(0x0016,0x7F00);
  LCD_Send(0x0017,0xA000);
  LCD_Send(0x003A,0x0000);//对比度
  LCD_Send(0x003B,0x0000);
  delay(10);
  //显示开函数
  LCD_Send(0x0007,0x0105);
  delay(40);
  LCD_Send(0x0007,0x0125);
  LCD_Send(0x0007,0x0127);
  delay(40);
  LCD_Send(0x0007,0x0137);
  //设置RAM地址
  LCD_Send(0x0021,0x0000);
  
 } 
void LCD_STOP(void)
{
 LCD_Send(0x0007,0x0136); 
 delay(40);
 LCD_Send(0x0007,0x0125);
 delay(40);
 LCD_Send(0x0007,0x0004);
 LCD_Send(0x0010,0x0000);
}

void initUART(void)
{
   UCSR0B=(1<<RXEN0)|(1<<TXEN0); //disable while setting baud rate 
   UCSR0A = 0x00; 
   UCSR0C = (1<<UCSZ00)|(1<<UCSZ01);    
   UBRR0L = 0x03;    //   (7372800/16/115200-1)%256;    
   UBRR0H = 0x00;  //  (7372800/16/115200-1)/256; 
   UCSR0B = (1<<RXEN0)|(1<<RXCIE0)|(1<<TXEN0);    
}

void sendUART(unsigned char data)
{
   while( !(UCSR0A & (1<<UDRE0)) );
  UDR0=data;
}


unsigned char Usart0_receive( void) 
{ 
  while (!(UCSR0A&(1<<RXC0))) ; 
  return UDR0; 
} 

void LCD_DrawPoint(unsigned char x,unsigned char y,unsigned int color )
{  
  Send(0x0016,0);
  PORTG&=~(1<<LCD_CS);
  PORTB|= (1<<LCD_RS);
  PORTG&=~(1<<LCD_WR);
  PORTC=x;//高8位
  PORTD=x-1;//低8位
  PORTG|= (1<<LCD_WR);
  
  Send(0x0017,0);
  PORTG&=~(1<<LCD_CS);
  PORTB|= (1<<LCD_RS);
  PORTG&=~(1<<LCD_WR);
  PORTC=y;//高8位
  PORTD=y-1;//低8位
  PORTG|= (1<<LCD_WR);
  
  Send(0x0021,0);
  PORTG&=~(1<<LCD_CS);
  PORTB|= (1<<LCD_RS);
  PORTG&=~(1<<LCD_WR);
  PORTC=y-1;//高8位
  PORTD=x-1;//低8位
  PORTG|= (1<<LCD_WR);

  LCD_Send(0x0022,color); 

}

void put(unsigned char x,unsigned char y,unsigned int color1,unsigned int color2,unsigned char n)
{
  unsigned int i,a;
  Send(0x0016,0);
  PORTG&=~(1<<LCD_CS);
  PORTB|= (1<<LCD_RS);
  PORTG&=~(1<<LCD_WR);
  PORTC=x+15;//高8位
  PORTD=x;//低8位
  PORTG|= (1<<LCD_WR);
  
  Send(0x0017,0);
  PORTG&=~(1<<LCD_CS);
  PORTB|= (1<<LCD_RS);
  PORTG&=~(1<<LCD_WR);
  PORTC=y+15;//高8位
  PORTD=y;//低8位
  PORTG|= (1<<LCD_WR);
  
  Send(0x0021,0);
  PORTG&=~(1<<LCD_CS);
  PORTB|= (1<<LCD_RS);
  PORTG&=~(1<<LCD_WR);
  PORTC=y;//高8位
  PORTD=x;//低8位
  PORTG|= (1<<LCD_WR);

  for(i=0;i<32;i++)
 { 
      a=z[n][i];                             // Color1 ;背景颜色,
	                                         // Color2 ;汉字颜色 
	  if(a&0x80)                          //第8位比较,选择颜色
	   LCD_Send(0x0022,color2);
	  else
	   LCD_Send(0x0022,color1);
	  
	  if(a&0x40)                          //7	   LCD_Send(0x0022,color2);
	  else
	   LCD_Send(0x0022,color1);	   	  if(a&0x20)                          //6
	   LCD_Send(0x0022,color2);
	  else
	   LCD_Send(0x0022,color1); 
	  	   if(a&0x10)                         //5
	   LCD_Send(0x0022,color2);
	  else
	   LCD_Send(0x0022,color1);	  	   if(a&0x08)                         //4
	   LCD_Send(0x0022,color2);
	  else
	   LCD_Send(0x0022,color1);	  	  if(a&0x04)                          //3
	   LCD_Send(0x0022,color2);
	  else
	   LCD_Send(0x0022,color1);
	  	  if(a&0x02)                          //2
	   LCD_Send(0x0022,color2);
	  else
	   LCD_Send(0x0022,color1);
	   
	  if(a&0x01)                          //1
	   LCD_Send(0x0022,color2);
	  else
	   LCD_Send(0x0022,color1);  }

}



void LCD_DrawLine(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2,unsigned int color)
{
	uint8_t x, y, t;
	if((x1 == x2) && (y1 == y2))
		LCD_DrawPoint(x1, y1,color);
	else if(abs(y2 - y1) > abs(x2 - x1))
	{
		if(y1 > y2)
		{
			t = y1;
			y1 = y2;
			y2 = t;
			t = x1;
			x1 = x2;
			x2 = t;
		}
		for(y = y1; y <= y2; y ++)
		{
			x = (y - y1) * (x2 - x1) / (y2 - y1) + x1;
			LCD_DrawPoint(x, y,color);
		}
	}
	else
	{
		if(x1 > x2)
		{
			t = y1;
			y1 = y2;
			y2 = t;
			t = x1;
			x1 = x2;
			x2 = t;
		}
		for(x = x1; x <= x2; x ++)
		{
			y = (x - x1) * (y2 - y1) / (x2 - x1) + y1;
			LCD_DrawPoint(x, y,color);
		}
		
	}
}


void LCD_DrawRectangle(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2,unsigned int color,unsigned char n)
{   if(n)
		{ 
		unsigned int i,a;
	    a=abs(x1-x2);
	  for(i=0;i<a;i++)
	  LCD_DrawLine(x1+i,y1,x1+i,y2,color);
	}
	else
	{
	  LCD_DrawLine(x1, y1, x2, y1,color);
	  LCD_DrawLine(x2, y1, x2, y2,color);
	  LCD_DrawLine(x2, y2, x1, y2,color);
	  LCD_DrawLine(x1, y2, x1, y1,color);
	}
}


void circlePlotPoints (float xcenter, float ycenter, float x, float y,unsigned int color)
{
  LCD_DrawPoint(xcenter + x, ycenter + y, color);
  LCD_DrawPoint(xcenter - x, ycenter + y, color);
  LCD_DrawPoint(xcenter + x, ycenter - y, color);
  LCD_DrawPoint(xcenter - x, ycenter - y, color);
  LCD_DrawPoint(xcenter + y, ycenter + x, color);
  LCD_DrawPoint(xcenter - y, ycenter + x, color);
  LCD_DrawPoint(xcenter + y, ycenter - x, color);
  LCD_DrawPoint(xcenter - y, ycenter - x, color);
}


void circlea (float xcenter, float ycenter, float radius,unsigned int color)
{
  float x = 0;
  float y = radius;
  float p = 1 - radius;

  circlePlotPoints(xcenter, ycenter, x, y,color);
  while (x < y)
  {
    x++;
    if (p < 0)
      p += 2 * x + 1;
    else
    {
      y--;
      p += 2 * (x - y) + 1;
    }
    circlePlotPoints(xcenter, ycenter, x, y,color);
  }
}




 void circle (float xcenter, float ycenter, float radius,unsigned int color,unsigned char n)
 {
   if(n)
   {
     float i;
     for(i=0;i<radius;i=i+0.5 )
     {
	  circlea(xcenter,ycenter,i,color);
	 circlea(xcenter+0.1,ycenter+0.1,i,color);//多次画圆,保证质量!
	 circlea(xcenter-0.1,ycenter-0.1,i,color);
	 
	 
	 }
	} 
   else
   { 
    circlea(xcenter,ycenter,radius,color);
   }
  
}

   

⌨️ 快捷键说明

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