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

📄 h146it01.c

📁 包内含有关于ipod mp3透反式1.46 tft液晶屏的avr示例程序和液晶屏转接板的protel原理图和pcb图。
💻 C
字号:
/******************************************************************************************
         Manufacturer: SHENZHEN JINGHUA DISPLAYS CO.,LTD.
                    All rights reserved.
					
					
                    H146IT01
					
Programmer: 	ldqmoon
      Date:     2007-9-1
       Ver:     A
________________________________________________________________________________________
lcm  information:
H146IT01   TFT
176RGB*132
IC: NT3916
 V: 3.v
 
cpu: atmega16
fosc: 7.3728MHz

Interface:
---------------------------------------------------------------------------------------
...
________________________________________________________________________________________

filename : H146IT01.c
descibe: program to control a tft modula

modified flow here:
yyyy-mm-dd :   changer      reason

*******************************************************************************************/

#include "h146it01.h"
#include <avr/delay.h> 
#include "control.h"
#include<avr/pgmspace.h>

#include<avr/pgmspace.h>


#if FONTTAB
#include "ascii2.h"
#else
#include "ascii.h"
#endif

#define  uchar unsigned char


#if COLORDEPTH==262
void DisplayScreen(unsigned char ColorR, unsigned char ColorG, unsigned char ColorB)
{
    int i;
    LCDWriteCmd(0x2c);
	for(i=0; i<23232; i++)
	{
	    LCDWriteData(ColorR);
		LCDWriteData(ColorG);
		LCDWriteData(ColorB);
	}
}
void PutPixel(int x, int y, unsigned char ColorR, unsigned char ColorG, unsigned char ColorB)
{
    LCDWriteCmd(0x2a);
	LCDWriteData( (unsigned char)(x&0xff00)>>8 );
	LCDWriteData((unsigned char)(x&0x00ff));
	LCDWriteCmd(0x2b);
	LCDWriteData( (unsigned char)(y&0xff00)>>8 );
	LCDWriteData((unsigned char)(y&0x00ff));
    LCDWriteCmd(0x2c);
	LCDWriteData(ColorR);
	LCDWriteData(ColorG);
	LCDWriteData(ColorB);
}
#else
void DisplayScreen(unsigned int color)
{
    int i;
    LCDWriteCmd(0x2c);
	for(i=0; i<23232; i++)
	{
	    LCDWriteData((unsigned char)(color&0xff00)>>8);
		LCDWriteData((unsigned char)(color&0x00ff));
	}
}
void PutPixel(int x, int y, unsigned int color)
{
    LCDWriteCmd(0x2a);
	LCDWriteData( (unsigned char)(x&0xff00)>>8 );
	LCDWriteData((unsigned char)(x&0x00ff));
	LCDWriteCmd(0x2b);
	LCDWriteData( (unsigned char)(y&0xff00)>>8 );
	LCDWriteData((unsigned char)(y&0x00ff));
    LCDWriteCmd(0x2c);
	LCDWriteData((unsigned char)(color&0xff00)>>8);
	LCDWriteData((unsigned char)(color&0x00ff));
}
#endif


void LCDInit(void)
{
    _RST1;
	_delay_ms(500);
	_RST0;
	_delay_ms(800);
	_RST1;
	_delay_ms(500);

    //******send initial commands******// 
	LCDWriteCmd(0x01);    //SWREST
	_delay_ms(1000);
	LCDWriteCmd(0x11);    //SLPOUT 273PG
	_delay_ms(1000);
	
	LCDWriteCmd(0x3a);    //Pixel format 
#if COLORDEPTH==262
	LCDWriteData(0x66);   //change to 262k
#else
    LCDWriteData(0x65);   // change to 56k
#endif
	
	LCDWriteCmd(0xab);    //Sperate Gamma ON
	
	//**********send Gamma commands ***********/// 
	LCDWriteCmd(0xf2);    //enable
	LCDWriteData(0x00);
	LCDWriteData(0x01);
	LCDWriteCmd(0xe4);    //>B positive 
	LCDWriteData(0x00);   //P1
	LCDWriteData(0x71);
	LCDWriteData(0x00);   //P2
	LCDWriteData(0x01);
	LCDWriteData(0x00);   //P3
	LCDWriteData(0x82);
	LCDWriteData(0x00);   //P4
	LCDWriteData(0x04);
	LCDWriteData(0x00);   //P5
	LCDWriteData(0x1f);
	LCDWriteData(0x00);   //P6
	LCDWriteData(0x11);
	LCDWriteCmd(0xe5);    //>B negative
	LCDWriteData(0x00);   //P1
	LCDWriteData(0x64);
	LCDWriteData(0x00);   //P2
	LCDWriteData(0x41);
	LCDWriteData(0x00);   //P3
	LCDWriteData(0x64);
	LCDWriteData(0x00);   //P4
	LCDWriteData(0x19);
	LCDWriteData(0x00);   //P5
	LCDWriteData(0xb3); 
	LCDWriteData(0x00);   //P6
	LCDWriteData(0x09);
	LCDWriteData(0x00);   //P7
	LCDWriteData(0x00);
	LCDWriteData(0x00);   //P8
	LCDWriteData(0x00);
	_delay_ms(100);
	
	LCDWriteCmd(0xe2);    //G positive
	LCDWriteData(0x00);   //P1
	LCDWriteData(0x71);
	LCDWriteData(0x00);   //P2
	LCDWriteData(0x65);
	LCDWriteData(0x00);   //P3
	LCDWriteData(0x24);
	LCDWriteData(0x00);   //P4
	LCDWriteData(0x01);
	LCDWriteData(0x00);   //P5
	LCDWriteData(0x97); 
	LCDWriteData(0x00);   //P6
	LCDWriteData(0x08);
	LCDWriteData(0x00);   //P7
	LCDWriteData(0x15);
	LCDWriteData(0x00);   //P8
	LCDWriteData(0x11);
	_delay_ms(100);
	
	LCDWriteCmd(0xe3);    //G negative
	LCDWriteData(0x00);   //P1
	LCDWriteData(0x51);
	LCDWriteData(0x00);   //P2
	LCDWriteData(0x01);
	LCDWriteData(0x00);   //P3
	LCDWriteData(0x62);
	LCDWriteData(0x00);   //P4
	LCDWriteData(0x13);
	LCDWriteData(0x00);   //P5
	LCDWriteData(0xf3);
	LCDWriteData(0x00);   //P6
	LCDWriteData(0x0b);
	LCDWriteData(0x00);   //P7
	LCDWriteData(0x00);
	LCDWriteData(0x00);   //P8
	LCDWriteData(0x00);
	_delay_ms(100);
	
	LCDWriteCmd(0xe0);    //R positive 
	LCDWriteData(0x00);   //P1
	LCDWriteData(0x71);
	LCDWriteData(0x00);   //P2
	LCDWriteData(0x76);
	LCDWriteData(0x00);   //P3
	LCDWriteData(0x25);
	LCDWriteData(0x00);   //P4
	LCDWriteData(0x01);
	LCDWriteData(0x00);   //P5
	LCDWriteData(0xa5);
	LCDWriteData(0x00);   //P6
	LCDWriteData(0x09);
	LCDWriteData(0x00);   //P7
	LCDWriteData(0x15);
	LCDWriteData(0x00);   //P8
	LCDWriteData(0x11);
	_delay_ms(100);
	
	LCDWriteCmd(0xe1);    //R negative
	LCDWriteData(0x00);   //P1
	LCDWriteData(0x40);
	LCDWriteData(0x00);   //P2
	LCDWriteData(0x21);
	LCDWriteData(0x00);   //P3
	LCDWriteData(0x64);
	LCDWriteData(0x00);   //P4
	LCDWriteData(0x13);
	LCDWriteData(0x00);   //P5
	LCDWriteData(0xf3);
	LCDWriteData(0x00);   //P6
	LCDWriteData(0x0b);
	LCDWriteData(0x00);   //P7
	LCDWriteData(0x00);
	LCDWriteData(0x00);   //P8
	LCDWriteData(0x00);
	_delay_ms(100);
	
	LCDWriteCmd(0x29);    //DISPON 273PG
	LCDWriteCmd(0xac);    //VSYNC OFF  
	LCDWriteCmd(0x35);    //TE ON 
	LCDWriteData(0x00);
	_delay_ms(100);


}


void LCDWriteCmd(unsigned char cmd)
{
    _CS0;
	_RD1;
	_RS0;
	DATAPORT = cmd;
	_WR0;
	_WR1;
	_CS1;
}

void LCDWriteData(unsigned char dat)
{
    _CS0;
	_RD1;
	_RS1;
	DATAPORT = dat;
	_WR0;
	_WR1;
	_CS1;
}






#if COLORDEPTH==262
void PutChar8x16(int x, int y, char pFont, uchar bkR, uchar bkG, uchar bkB,uchar ftR, uchar ftG, uchar ftB)
{
    int i,j;
	unsigned char mask = 0x80;
	unsigned char tmp;
	const prog_uchar *ptr;
#if FONTTAB
	if(pFont<33)
	{
	    pFont = 33;
	}
	else if(pFont>65)
	{
	    pFont = 65;
	}
	pFont = pFont-33;              // for the font, I need to reduce 32 to get the right font point
	                                // 528 = 33*16;
#endif
    
	ptr = &ascii8x16[pFont];

	for(j=0; j<16; j++)
	{
	    mask = 0x80;
	    for(i=0; i<8; i++)
		{
		    tmp = pgm_read_byte(ptr);
		    
		    if( tmp&mask)
			{
			    PutPixel(x+i,y, ftR, ftG, ftB);
			}
			else
			{  
			    //if( !(bkcolor &0x8000) )        // if bkcolor<0, use the default bkcolor
				{
				    PutPixel(x+i, y, bkR, bkG, bkB);
			  
				}
			}
			mask>>=1;
			
		}
		y++;
		ptr++;
	}
}

void PutString(int StartX, int StartY, char *pString, uchar bkR,uchar bkG, uchar bkB, uchar ftR, uchar ftG, uchar ftB)
{
    int x,y;
	x = StartX;
	y = StartY;
    do
	{
	    PutChar8x16(x, y, *pString, bkR, bkG, bkB, ftR, ftG, ftB);
		x+=8;
		pString++;
		if(x>=176)              
		{
		    y+=16;
			if(y>=132)             // 显示位置是从144开始,y方向累加是在子程序操作中
			{
			    x = 0;
				y = 0;
			}
			x = 0;
		}
	}while(*pString);
}
#else
void PutChar8x16(int x, int y, char pFont,int bkcolor,int fontcolor)
{
    int i,j;
	unsigned char mask = 0x80;
	unsigned char tmp;
	const prog_uchar *ptr;
#if FONTTAB
	if(pFont<33)
	{
	    pFont = 33;
	}
	else if(pFont>65)
	{
	    pFont = 65;
	}
	pFont = pFont-33;              // for the font, I need to reduce 32 to get the right font point
	                                // 528 = 33*16;
#endif
    
	ptr = &ascii8x16[pFont];

	for(j=0; j<16; j++)
	{
	    mask = 0x80;
	    for(i=0; i<8; i++)
		{
		    tmp = pgm_read_byte(ptr);
		    
		    if( tmp&mask)
			{
			    PutPixel(x+i,y, fontcolor);
			}
			else
			{  
			    //if( !(bkcolor &0x8000) )        // if bkcolor<0, use the default bkcolor
				{
				    PutPixel(x+i, y, bkcolor);
			  
				}
			}
			mask>>=1;
			
		}
		y++;
		ptr++;
	}

}

void PutString(int StartX, int StartY, char *pString, int bkcolor, int fontcolor)
{
    int x,y;
	x = StartX;
	y = StartY;
    do
	{
	    PutChar8x16(x, y, *pString, bkcolor, fontcolor);
		x+=8;
		pString++;
		if(x>=176)              
		{
		    y+=16;
			if(y>=132)             // 显示位置是从144开始,y方向累加是在子程序操作中
			{
			    x = 0;
				y = 0;
			}
			x = 0;
		}
	}while(*pString);
}

#endif

⌨️ 快捷键说明

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