📄 main.c
字号:
/*************************************************
* project: YT028C6S-B01 *
* IC: HX8346 *
* test_mcu: S3C44B0 *
* Interface: I8080/8bit *
* programmer: Allen *
* date: 2008.01.13 *
*************************************************/
#include "option.h"
#include "def.h"
#include "44b.h"
#include "44blib.h"
#include "QVGA.h"
//------------------------------
#define red 0xf800
#define green 0x07e0
#define blue 0x001f
#define white 0x0000
#define black 0xffff
#define LCD_H 320
#define LCD_W 240
//---------------------------
void LCD_CtrlWrite(U16 c,U16 d);
void Write_C (U16 cmd);
void Write_D (U16 dat);
void Initial_LCM(void);
void Display_full(U16 color);
U8 get_touch_num(void);
U8 get_ative(void);
U8 gettouch(U16 reg);
//void Display_bar(U8 x);
//void Draw_bar(U8 x,U8 y,U8 color_data1,U8 color_data2);
//void Display0 (U8 d1,U8 d2,U8 number);
void Display_bmp(U16 *p);
#define DCLK (1<<4)
#define ACS (1<<5)
#define DIN (1<<6)
#define BUSY (1)
#define DOUT (1<<1)
/**********************************************************
* 主程序
**********************************************************/
void Main(void)
{
U8 num=0;
U8 tou_num;
rSYSCFG=CACHECFG; // Using 8KB Cache//
Port_Init();
Delay(10);
Initial_LCM();
if((rPDATG&0x00000010)==0)
{
while(1)
{
Display_full(red);
Delay(10000);
while((rPDATG&0x00000020)==0){;};
Display_full(green);
Delay(10000);
while((rPDATG&0x00000020)==0){;};
while((rPDATG&0x00000020)==0){;};
Display_full(blue);
Delay(10000);
while((rPDATG&0x00000020)==0){;};
Display_full(white);
Delay(10000);
while((rPDATG&0x00000020)==0){;};
Display_full(black);
Delay(10000);
while((rPDATG&0x00000020)==0){;};
Display_bmp(picture);
Delay(15000);
while((rPDATG&0x00000020)==0){;};
}
}
else
{
while(1)
{
while((num=get_ative())==0){;};
if(num==1)
{
tou_num=get_touch_num();
switch(tou_num)
{
case 1: Display_full(red);
Delay(10000);
break;
case 2: Display_full(green);
Delay(10000);
break;
case 3: Display_full(blue);
Delay(10000);
break;
case 4: Display_full(white);
Delay(10000);
break;
case 5: Display_full(black);
Delay(10000);
break;
case 6: Display_full(red);
Delay(10000);
break;
case 7: Display_full(red);
Delay(10000);
break;
case 8: Display_full(red);
Delay(10000);
break;
case 9: Display_full(red);
Delay(10000);
break;
default:
break;
}
num=0;
tou_num=0;
}
if(num==2) //自动
{
Display_full(red);
Delay(10000);
while((rPDATG&0x00000020)==0){;};
Display_full(green);
Delay(10000);
while((rPDATG&0x00000020)==0){;};
while((rPDATG&0x00000020)==0){;};
Display_full(blue);
Delay(10000);
while((rPDATG&0x00000020)==0){;};
Display_full(white);
Delay(10000);
while((rPDATG&0x00000020)==0){;};
Display_full(black);
Delay(10000);
while((rPDATG&0x00000020)==0){;};
Display_bmp(picture);
Delay(15000);
while((rPDATG&0x00000020)==0){;};
num=0;
}
if(num==3) //单步
{
num=0;
Display_full(red);
Delay(10000);
while((num=get_ative())!=3){;};
num=0;
Display_full(green);
Delay(10000);
while((num=get_ative())!=3){;};
num=0;
Display_full(blue);
Delay(10000);
while((num=get_ative())!=3){;};
num=0;
Display_full(white);
Delay(10000);
while((num=get_ative())!=3){;};;
num=0;
Display_full(black);
Delay(10000);
while((num=get_ative())!=3){;};
num=0;
Display_bmp(picture);
Delay(15000);
while((num=get_ative())!=3){;};
num=0;
}
}
}
}
/*******************************************************
* 液晶初始化子程序 *
*******************************************************/
U8 get_ative(void)
{
if((rPDATG&0x4)==0)
{
return(1);
}
if((rPDATF&0x100)==0)
{
Delay(500);
if((rPDATF&0x100)==0)
{
while((rPDATF&0x100)==0){;}
return(2);
}
else
return(0);
}
if((rPDATG&0x40)==0)
{
Delay(500);
if((rPDATG&0x40)==0)
{
while((rPDATG&0x40)==0){;}
return(3);
}
else
return(0);
}
return(0);
}
/*******************************************************
* 液晶初始化子程序 *
*******************************************************/
void Initial_LCM(void)
{
//PD3--LCD_reset
rPDATD&=0x7f; //LCD_CS=0;PD7
rPDATD&=0xf7; // LCD_reset=0;PD3
Delay(100); //Delay20ms
rPDATD|=0x08; // LCD_reset=1;
Delay(500); //Delay50ms
// Gamma
LCD_CtrlWrite(0x0046,0x0022);
LCD_CtrlWrite(0x0047,0x0022);
LCD_CtrlWrite(0x0048,0x0020);
LCD_CtrlWrite(0x0049,0x0035);
LCD_CtrlWrite(0x004A,0x0000);
LCD_CtrlWrite(0x004B,0x0077);
LCD_CtrlWrite(0x004C,0x0024);
LCD_CtrlWrite(0x004D,0x0075);
LCD_CtrlWrite(0x004E,0x0012);
LCD_CtrlWrite(0x004F,0x0028);
LCD_CtrlWrite(0x0050,0x0024);
LCD_CtrlWrite(0x0051,0x0044);
//240x320 window setting
LCD_CtrlWrite(0x0002,0x0000); // Column address start2
LCD_CtrlWrite(0x0003,0x0000); // Column address start1
LCD_CtrlWrite(0x0004,0x0000); // Column address end2
LCD_CtrlWrite(0x0005,0x00EF); // Column address end1
LCD_CtrlWrite(0x0006,0x0000); // Row address start2
LCD_CtrlWrite(0x0007,0x0000); // Row address start1
LCD_CtrlWrite(0x0008,0x0001); // Row address end2
LCD_CtrlWrite(0x0009,0x003F); // Row address end1
// Display Setting
LCD_CtrlWrite(0x0001,0x0006); // IDMON=0, INVON=1, NORON=1, PTLON=0
LCD_CtrlWrite(0x0016,0x0008); // MY=0, MX=0, MV=0, BGR=1, TEON=0
LCD_CtrlWrite(0x0023,0x0095); // N_DC=1001 0101
LCD_CtrlWrite(0x0024,0x0095); // P_DC=1001 0101
LCD_CtrlWrite(0x0025,0x00FF); // I_DC=1111 1111
LCD_CtrlWrite(0x0028,0x0002); // N_BP=0000 0010
LCD_CtrlWrite(0x0029,0x0002); // N_FP=0000 0010
LCD_CtrlWrite(0x002A,0x0002); // P_BP=0000 0010
LCD_CtrlWrite(0x002B,0x0002); // P_FP=0000 0010
LCD_CtrlWrite(0x002C,0x0002); // I_BP=0000 0010
LCD_CtrlWrite(0x002D,0x0002); // I_FP=0000 0010
LCD_CtrlWrite(0x003A,0x0001); // N_RTN=0000, N_NW=001
LCD_CtrlWrite(0x003B,0x0001); // P_RTN=0000, P_NW=001
LCD_CtrlWrite(0x003C,0x00F0); // I_RTN=1111, I_NW=000
LCD_CtrlWrite(0x003D,0x0000); // DIV=00
Delay(20);
// Power Supply Setting
LCD_CtrlWrite(0x0019,0x0041); // OSCADJ=100 010, OSD_EN=1
Delay(10);
LCD_CtrlWrite(0x0020,0x0080); // BT=1000
LCD_CtrlWrite(0x001D,0x0047); // VC2=100, VC1=001
LCD_CtrlWrite(0x001E,0x0000); // VC3=000
LCD_CtrlWrite(0x001F,0x0003); // VRH=1101
LCD_CtrlWrite(0x0044,0x0020); // VCM=010 0000
LCD_CtrlWrite(0x0045,0x000E); // VDV=0 1011
Delay(10);
LCD_CtrlWrite(0x001C,0x0004); // AP=110
Delay(20);
LCD_CtrlWrite(0x001B,0x0018); // NIDSENB=0, PON=1, DK=1, XDK=0,
// VLCD_TRI=0, STB=0
Delay(40);
LCD_CtrlWrite(0x001B,0x0010); // NIDSENB=0, PON=1, DK=0, XDK=0,
// VLCD_TRI=1, STB=0
Delay(40);
LCD_CtrlWrite(0x0043,0x0080); // VCOMG=1
Delay(100);
// Display ON Setting
LCD_CtrlWrite(0x0030,0x0008); // SAPS1=1000
Delay(40);
LCD_CtrlWrite(0x0026,0x0004); //GON=0, DTE=0, D=01
Delay(40);
LCD_CtrlWrite(0x0026,0x0024); //GON=1, DTE=0, D=01
Delay(40);
LCD_CtrlWrite(0x0026,0x002C); //GON=1, DTE=0, D=11
Delay(40);
LCD_CtrlWrite(0x0026,0x003C); //GON=1, DTE=1, D=11
}
/********************************************************
* 图片显示程序
********************************************************/
void Display_bmp(U16 *p)
{
U16 i,j;
LCD_CtrlWrite(0x0020,0x0000);
LCD_CtrlWrite(0x0021,0x0000);
Write_C(0x0022);
for(i=0;i<LCD_H;i++)
{
for(j=0;j<LCD_W;j++,p++)
{
Write_D(*p);
}
}
}
/********************************************************
* 全屏显示程序
********************************************************/
void Display_full(U16 color)
{
U16 i,j;
LCD_CtrlWrite(0x0020,0x0000);
LCD_CtrlWrite(0x0021,0x0000);
Write_C(0x0022);
for(i=0;i<LCD_H;i++)
{
for(j=0;j<LCD_W;j++)
{
Write_D(color);
}
}
}
/**********************************************************
* LCD设置 *
**********************************************************/
void LCD_CtrlWrite(U16 c,U16 d)
{
Write_C(c);
Write_D(d);
}
/**********************************************************
* 写指令子程序 *
**********************************************************/
void Write_C (U16 cmd)
{
rPDATD&=0xbf; //LCD_RS=0 PD6
rPDATD|=0x10; //LCD_RD=1 PD4
// Delay1(1);
rPDATD&=0x7f; //LCD_CS=0;PD7
rPDATC=cmd; //send the 16 bit
rPDATD&=0xdf; //LCD_WR=0;PD5
//Delay(10);
rPDATD|=0x20; //LCD_WR=1;PD5
rPDATD|=0x10; //LCD_CS=1;PD7
}
/********************************************************
* 写数据子程序 *
********************************************************/
void Write_D (U16 dat)
{
rPDATD|=0x40; //LCD_RS=1 PD6
rPDATD|=0x10; //LCD_RD=1 PD4
// Delay1(1);
rPDATD&=0x7f; //LCD_CS=0;PD7
rPDATC=dat; //send the 16 bit
rPDATD&=0xdf; //LCD_WR=0;PD5
//Delay(10);
rPDATD|=0x20; //LCD_WR=1;PD5
rPDATD|=0x10; //LCD_CS=1;PD7
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -