📄 s6d0144.c
字号:
//#include "AT89x52.h"
//#include "image.c"
#include "head.c"
#define START_ADD 500 //2800 //2700
#define START_ADD_END 24065 //(START_ADD+78*2)
/*
sbit _CS =P3^3;
sbit RS= P3^5;
sbit _WR =P3^2;
*/
sbit _CS= P3^2;
sbit RS= P3^3;
sbit _RD= P3^5;
sbit _WR= P3^4;
sbit RES= P3^7;
#define OUTPORT_H P1
#define OUTPORT_L P2
sbit LATCH =P0^0;
#define LATCH_PORT P1
#define uchar unsigned char
#define uint unsigned int
#define MAX_STEP 6
void HX8312_init();
void W_D(uchar h,uchar l);
void W_D2(uint ua);
void delay(uint ms);
void W_D8(uchar h);
void delay_check_key();
void CMD16(unsigned char a,unsigned int b);
void test_pixel2();
void set_whole_screen();
void display1();//模线
void display2();//竖线
void display3();//雪花
void display4();//文字
void display5();//全显
void display6();//竖条
void display7();//竖条
unsigned char read_ROM(unsigned int a);
void display_picture(unsigned char a); //0~15 共16张图片
void set_pixel(unsigned char x,unsigned int y);
void display_text();
void press_up_key();
void press_down_key();
void press_auto_key();
void press_contrast_add();
void press_contrast_sub();
void display_cat_mouse();
uint RGB(uchar r,uchar g,uchar b);
uchar contrast,current_display,last_display;
unsigned char auto_loop;
unsigned char epp_data;
unsigned int epp_data_count;
unsigned int rom_addr;
unsigned char lcm_res;
unsigned int ia,ib;
unsigned int inta,intb;
unsigned int pageadd,addint;
unsigned char k,temp;
void extern0_ISR() interrupt 0{
EA=0;
EA=1;
} /* not used */
void timer0_ISR () interrupt 1{} /* not used */
void extern1_ISR() interrupt 2{} /* not used */
void timer1_ISR () interrupt 3{} /* not used */
void serial_ISR () interrupt 4
{
if(RI)
{
epp_data_count++;
//ROM_CLE=0; //2read the data?!
//ROM_ALE=0; //3
//ROM_RD=1; //7
//P3=0xf3;
/*
ROM_DATAPORT=SBUF;//epp_data;
ROM_WR=0;//---->
ROM_WR=1;
*/
//ROM_CS=1;
//ROM_ALE=1;
if(epp_data_count%2!=0)
epp_data=SBUF;
else
{
RS=1;
_CS=0;
OUTPORT_H=epp_data;
OUTPORT_L=SBUF;
_WR=0;
_WR=1;
_CS=1;
}
RI=0;
//W_D8(SBUF);
}
} /* not used */
void main()
{
epp_data=0;
epp_data_count=0;
rom_addr=START_ADD;
lcm_res=0xff;
AUXR |=0x40;//seial 12 time
EA=0;//int en
IT0=1;//fall edge triger
EX0=0;//extern int0 en
EX1=0;//extern int0 en
SCON = 0x50; //SCON: serail mode 1, 8-bit UART, enable ucvr
TMOD |= 0x20; //TMOD: timer 1, mode 2, 8-bit reload
PCON |= 0x80; //SMOD=1; X2-->
TH1 = 0xF4; //Baud:4800 fosc=11.0592MHz
IE |= 0x90; //Enable Serial Interrupt
TR1 = 1; // timer 1 run
/*
rom_send_com(0xff);
delay(300);
*/
//ROM_ALE=1;
auto_loop=1;
HX8312_init();
//while(1);///------stop ,else touchpanel test!!
/*
set_whole_screen();
while(1);
*/
display6();//
delay(300);
display1();//
delay(300);
display2();//
delay(300);
display3();//
delay(300);
display4();//
delay(300);
display5();//
EA=1;
EA=1;
//while(1);///------stop ,else touchpanel test!!
set_whole_screen();
while(1);
/*
while(1)
{
ia=tp_read(2);
printc(ia);
delay(20);
}
*/
while(1)
{
ia=tp_read(2);
delay(1);
//delay(1);
ib=tp_read(1);
//delay(1);
set_pixel(ia,ib);
//delay(1);
//printc(ia);
//printc(ib);
inta++;
if(inta>4200)
{
display5();
inta=0;
}
}
//while(1);
/*
display6();//
*/
//while(1);
//while(1);
last_display=0;
current_display=0;
while(1)
{
delay_check_key();
if(last_display!=current_display)
{
last_display=current_display;
switch(current_display)
{
case(1):
display1();//
break;
case(2):
display2();//red
break;
case(3):
display3();//green
break;
case(4):
display4();//blue
break;
case(5):
display5();//文字
break;
case(6):
display6();// clear
break;
}//end switch
}//end if
}
}//end sub main
uint RGB(uchar r,uchar g,uchar b)
{uint rgb,rgb2;
rgb2=r>>3;
rgb=rgb2<<11;
rgb2=g>>2;
rgb=rgb|rgb2<<5;
rgb2=b>>3;
rgb=rgb|rgb2;
return rgb;
}
void set_whole_screen()
{
W_C(0x20);
W_D(0x00,0);
W_C(0x21);
W_D(0x00,0x0);
W_C(0X22);
}
void display1()//red
{
uchar i;
unsigned int k;
set_whole_screen();
for(k=0;k<320;k++)
for(i=0;i<240;i++)
{
W_D(0xf8,0);
}
}//end sub
void display2()//green
{
uchar i;
unsigned int k;
set_whole_screen();
for(k=0;k<320;k++)
for(i=0;i<240;i++)
{
W_D(0x07,0xe0);
}
}//end sub
void display3()//blue
{
uchar i;
unsigned int k;
set_whole_screen();
for(k=0;k<320;k++)
for(i=0;i<240;i++)
{
W_D(0x0,0x1f);
}
}//end sub
void display4()//white
{
uchar i;
unsigned int k;
set_whole_screen();
for(k=0;k<320;k++)
for(i=0;i<240;i++)
{
W_D(0xff,0xff);
}
}//end sub
void display5()//black+绿色的框,作为边界确认
{
unsigned int i,ii;
set_whole_screen();
for(ii=0;ii<240;ii++)
W_D(0xff,0xff);
for(i=0;i<318;i++)
{
W_D(0xf8,0x0);
for(ii=0;ii<238;ii++)
W_D(0x0,0);
W_D(0x0,0x1f);
}
for(ii=0;ii<240;ii++)
W_D(0xff,0xff);
}
void display6()//clear
{
unsigned char i,ii;
set_whole_screen();
for(ii=0;ii<32;ii++)
for(i=0;i<240;i++)
W_D2(RGB(254,0,0));//red
for(ii=0;ii<32;ii++)
for(i=0;i<240;i++)
W_D2(RGB(0,254,0));//g
for(ii=0;ii<32;ii++)
for(i=0;i<240;i++)
W_D2(RGB(0,0,254));//b
for(ii=0;ii<32;ii++)
for(i=0;i<240;i++)
W_D2(RGB(0,254,254));//b+g
for(ii=0;ii<32;ii++)
for(i=0;i<240;i++)
W_D2(RGB(254,0,254));//r+b
for(ii=0;ii<32;ii++)
for(i=0;i<240;i++)
W_D2(RGB(254,254,0));//r+g
for(ii=0;ii<32;ii++)
for(i=0;i<240;i++)
W_D2(RGB(0,0,0));//black
for(ii=0;ii<32;ii++)
for(i=0;i<240;i++)
W_D2(RGB(254,254,254));//white
for(ii=0;ii<32;ii++)
for(i=0;i<240;i++)
W_D2(RGB(0,0,0));//black
for(ii=0;ii<32;ii++)
for(i=0;i<240;i++)
W_D2(RGB(254,254,254));//white
}//end sub
//////////////////////
void delay(uint ms)
{uint a,b;
for(b=0;b<ms;b++)
for(a=0;a<900;a++)
{nop;nop;}
}
void delays()
{
_nop_(); _nop_();_nop_();//_nop_();_nop_();_nop_();_nop_();_nop_();
}
void delay_check_key()
{
unsigned char a;
for(a=0;a<10;a++)
{
delay(50);
//check_key();
}
//LED=~LED;
if(auto_loop==1)
{
if(current_display<MAX_STEP)
{current_display++;}
else
{current_display=1;}//for auto change
}
}
void HX8312_init2()
{
RES=0;
delay(300);
RES=1;
delay(100);
//************* Start Initial Sequence **********//
CMD16(0x002b, 0x0000);
CMD16(0x00E5, 0x8000); // Set the Vcore voltage and this setting is must.
CMD16(0x0000, 0x0001); // Start internal OSC.
CMD16(0x0001, 0x0100); // set SS and SM bit
CMD16(0x0002, 0x0700); // set 1 line inversion
CMD16(0x0003, 0x1030); // set GRAM write direction and BGR=1.
CMD16(0x0004, 0x0000); // Resize register
CMD16(0x0008, 0x0202); // set the back porch and front porch
CMD16(0x0009, 0x0000); // set non-display area refresh cycle ISC[3:0]
CMD16(0x000A, 0x0000); // FMARK function
CMD16(0x000C, 0x0000); // RGB interface setting
CMD16(0x000D, 0x0000); // Frame marker Position
CMD16(0x000F, 0x0000); // RGB interface polarity
//*************Power On sequence ****************//
CMD16(0x0010, 0x0000); // SAP, BT[3:0], AP, DSTB, SLP, STB
CMD16(0x0011, 0x0007); // DC1[2:0], DC0[2:0], VC[2:0]
CMD16(0x0012, 0x0000); // VREG1OUT voltage
CMD16(0x0013, 0x0000); // VDV[4:0] for VCOM amplitude
delay(200); // Dis-charge capacitor power voltage
CMD16(0x0010, 0x17B0); // SAP, BT[3:0], AP, DSTB, SLP, STB
CMD16(0x0011, 0x0007); // R11h=0x0001 at VCI=3.3V DC1[2:0], DC0[2:0], VC[2:0]
delay(50); // Delay 50ms
CMD16(0x0012, 0x013A); // R11h=0x0138 at VCI=3.3V VREG1OUT voltage
delay(50); // Delay 50ms
CMD16(0x0013, 0x1A00); // R11h=0x1800 at VCI=3.3V VDV[4:0] for VCOM amplitude
CMD16(0x0029, 0x000C); // R11h=0x0008 at VCI=3.3V VCM[4:0] for VCOMH
delay(50);
CMD16(0x0020, 0x0000); // GRAM horizontal Address
CMD16(0x0021, 0x0000); // GRAM Vertical Address
// ----------- Adjust the Gamma Curve ----------//
CMD16(0x0030, 0x0000);
CMD16(0x0031, 0x0505);
CMD16(0x0032, 0x0004);
CMD16(0x0035, 0x0006);
CMD16(0x0036, 0x0707);
CMD16(0x0037, 0x0105);
CMD16(0x0038, 0x0002);
CMD16(0x0039, 0x0707);
CMD16(0x003C, 0x0704);
CMD16(0x003D, 0x0807);
//------------------ Set GRAM area ---------------//
CMD16(0x0050, 0x0000); // Horizontal GRAM Start Address
CMD16(0x0051, 0x00EF); // Horizontal GRAM End Address
CMD16(0x0052, 0x0000); // Vertical GRAM Start Address
CMD16(0x0053, 0x013F); // Vertical GRAM Start Address
CMD16(0x0060, 0x2700); // Gate Scan Line
CMD16(0x0061, 0x0001); // NDL,VLE, REV
CMD16(0x006A, 0x0000); // set scrolling line
//-------------- Partial Display Control ---------//
CMD16(0x0080, 0x0000);
CMD16(0x0081, 0x0000);
CMD16(0x0082, 0x0000);
CMD16(0x0083, 0x0000);
CMD16(0x0084, 0x0000);
CMD16(0x0085, 0x0000);
//-------------- Panel Control -------------------//
CMD16(0x0090, 0x0010);
CMD16(0x0092, 0x0000);
CMD16(0x0093, 0x0003);
CMD16(0x0095, 0x0110);
CMD16(0x0097, 0x0000);
CMD16(0x0098, 0x0000);
CMD16(0x0007, 0x0173); // 262K color and display ON
}
void HX8312_init()
{
RES=0;
delay(300);
RES=1;
delay(100);
CMD16(0x00E5, 0x8000); // Set the Vcore voltage and this setting is must.
CMD16(0x0000, 0x0001); // Start internal OSC.
CMD16(0x0001, 0x0100); // set SS and SM bit
CMD16(0x0002, 0x0700); // set 1 line inversion
CMD16(0x0003, 0x1030); // set GRAM write direction and BGR=0.
CMD16(0x0004, 0x0000); // Resize register
CMD16(0x0008, 0x0202); // set the back porch and front porch
CMD16(0x0009, 0x0000); // set non-display area refresh cycle ISC[3:0]
CMD16(0x000A, 0x0000); // FMARK function
CMD16(0x000C, 0x0000); // RGB interface setting
CMD16(0x000D, 0x0000); // Frame marker Position
CMD16(0x000F, 0x0000); // RGB interface polarity
//*************Power On sequence ****************//
CMD16(0x0010, 0x0000); // SAP, BT[3:0], AP, DSTB, SLP, STB
CMD16(0x0011, 0x0007); // DC1[2:0], DC0[2:0], VC[2:0]
CMD16(0x0012, 0x0000); // VREG1OUT voltage
CMD16(0x0013, 0x0000); // VDV[4:0] for VCOM amplitude
delay(200); // Dis-charge capacitor power voltage
CMD16(0x0010, 0x17B0); // SAP, BT[3:0], AP, DSTB, SLP, STB
CMD16(0x0011, 0x0007); // DC1[2:0], DC0[2:0], VC[2:0]
delay(50); // Delay 50ms
CMD16(0x0012, 0x013E); // VREG1OUT voltage
delay(50); // Delay 50ms
CMD16(0x0013, 0x1F00); // VDV[4:0] for VCOM amplitude
CMD16(0x0029, 0x0013); // VCM[4:0] for VCOMH
delay(50);
CMD16(0x0020, 0x0000); // GRAM horizontal Address
CMD16(0x0021, 0x0000); // GRAM Vertical Address
// ----------- Adjust the Gamma Curve ----------//
CMD16(0x0030, 0x0000);
CMD16(0x0031, 0x0404);
CMD16(0x0032, 0x0404);
CMD16(0x0035, 0x0004);
CMD16(0x0036, 0x0404);
CMD16(0x0037, 0x0404);
CMD16(0x0038, 0x0404);
CMD16(0x0039, 0x0707);
CMD16(0x003C, 0x0500);
CMD16(0x003D, 0x0607);
//------------------ Set GRAM area ---------------//
CMD16(0x0050, 0x0000); // Horizontal GRAM Start Address
CMD16(0x0051, 0x00EF); // Horizontal GRAM End Address
CMD16(0x0052, 0x0000); // Vertical GRAM Start Address
CMD16(0x0053, 0x013F); // Vertical GRAM Start Address
CMD16(0x0060, 0x2700); // Gate Scan Line
CMD16(0x0061, 0x0001); // NDL,VLE, REV
CMD16(0x006A, 0x0000); // set scrolling line
//-------------- Partial Display Control ---------//
CMD16(0x0080, 0x0000);
CMD16(0x0081, 0x0000);
CMD16(0x0082, 0x0000);
CMD16(0x0083, 0x0000);
CMD16(0x0084, 0x0000);
CMD16(0x0085, 0x0000);
//-------------- Panel Control -------------------//
CMD16(0x0090, 0x0010);
CMD16(0x0092, 0x0000);
CMD16(0x0093, 0x0003);
CMD16(0x0095, 0x0110);
CMD16(0x0097, 0x0000);
CMD16(0x0098, 0x0000);
CMD16(0x0007, 0x0173); // 262K color and display ON
delay(50);
}
void W_D(uchar h,uchar l)
{
RS=1;
_CS=0;
OUTPORT_H=h;
OUTPORT_L=l;
_WR=0;
_WR=1;
_CS=1;
}
void W_D2(uint ua)
{
uchar aa;
RS=1;//==>Data
_CS=0;
aa=(unsigned char)(ua>>8);
OUTPORT_H=aa;//
OUTPORT_L=(unsigned char)ua;//
_WR=0;
_WR=1;
_CS=1;
}
void CMD16(unsigned char a,unsigned int b)
{
W_C(a);
W_D2(b);
}
void W_C(unsigned char ua)
{
RS=0;//==>Command
_CS=0;
OUTPORT_H=0;//
OUTPORT_L=ua;//
_WR=0;
_WR=1;
_CS=1;
}
void set_pixel(unsigned char x,unsigned int y)
{
if(x>=240)x=240-1;
if(y>=320)y=320-1;
W_C(0x20);
W_D2(x);
W_C(0x21);
W_D2(y);
W_C(0X22);
W_D(0xff,0xff);
}
void test_pixel2()
{
unsigned int a;
for(a=0;a<320;a++)
{
if(a<240)
{
W_C(0x20);
W_D2(a);
}
else
{
W_C(0x20);
W_D2(120);
}
W_C(0x21);
W_D2(a);
W_C(0X22);
W_D(0xff,0xff);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -