#include #include"intrins.h" sbit LCD_nCS=P2^3; sbit LCD_nRD=P2^6; sbit LCD_nWR=P2^5; sbit LCD_RS=P2^4; sbit LCD_nRST=P2^2; sbit LCD_BLEN=P2^7; #define RED 0xf800 #define GREEN 0x07e0 #define BLUE 0x001f #define WHITE 0xffff #define BLACK 0x0000 #define YELLOW 0xFFE0 #define TRANSP 1 //字体显示的时候不带背景颜色 #define NORMAL 0 //字体显示的时候有背景颜色 #define LCD_W 240 #define LCD_H 320 #define LCD_Sx 0 #define LCD_Sy 0 #define LCD_Ex (LCD_W-1) #define LCD_Ey (LCD_H-1) #define XBYTE ((unsigned char volatile xdata *) 0) #define LCD_BLEN_0 LCD_BLEN=0 #define LCD_BLEN_1 LCD_BLEN=1 #define LCD_nCS_0 LCD_nCS=0 #define LCD_nCS_1 LCD_nCS=1 #define LCD_nRST_0 LCD_nRST=0 #define LCD_nRST_1 LCD_nRST=1 #define LCD_RS_0 LCD_RS=0 #define LCD_RS_1 LCD_RS=1 #define LCD_nRD_0 LCD_nRD=0 #define LCD_nRD_1 LCD_nRD=1 #define LCD_nWR_0 LCD_nWR=0 #define LCD_nWR_1 LCD_nWR=1 #define LCD_DAT P0 #define U16 int #define U8 unsigned char U16 PenColor; U16 BackColor; void DelayUs(U16 us) { while(us--); } void DelayMs( U16 ms) { while(ms--) DelayUs(1); } void LCD_WrCmd( char cmd) //时序见手册 { LCD_nCS=0; LCD_RS=0; LCD_DAT=(cmd>>8); //write high byte LCD_nWR=0; LCD_nWR=1; LCD_DAT=(cmd&0xff); //write low byte LCD_nWR=0; LCD_nWR=1; LCD_nCS=1; } void LCD_WrDat(U16 dat) { LCD_nCS=0; LCD_RS=1; LCD_DAT=(dat>>8); //write high byte LCD_nWR=0; LCD_nWR=1; LCD_DAT=(dat&0xff); //write low byte LCD_nWR=0; LCD_nWR=1; LCD_nCS=1; } void LCD_WrCmdDat(U16 addr,U16 dat) { LCD_WrCmd(addr); LCD_WrDat(dat); } void LCD_SetGramPoit(U16 x,U16 y) { LCD_WrCmdDat(0x0020,x); LCD_WrCmdDat(0x0021,y); LCD_WrCmd(0x0022); //设置地址后重新启动写RAM命令 } /*void LCD_WrDat8(U8 dat) { LCD_nCS_0; LCD_RS_1; LCD_DAT=(dat); LCD_nWR_0; LCD_nWR_1; LCD_nCS_1; }*/ void LCD_SetWindows(U16 HSA, U16 VSA,U16 HEA, U16 VEA) { LCD_WrCmdDat(0x0050,HSA); LCD_WrCmdDat(0x0051,HEA); LCD_WrCmdDat(0x0052,VSA); LCD_WrCmdDat(0x0053,VEA); LCD_SetGramPoit(HSA,VSA); //根据扫描方式不同而不同 } void Display_full_screen_color(U16 color) { U16 X, Y; LCD_SetWindows(LCD_Sx, LCD_Sy, LCD_Ex, LCD_Ey); LCD_SetGramPoit(LCD_Sx,LCD_Sy); //根据扫描方式不同而不同 for(X = 0; X < LCD_W; X++) { for(Y = 0; Y < LCD_H; Y++) { LCD_WrDat(color); } } } void LCD_Init(void) { LCD_BLEN_0; LCD_nRST_0; //低电平复位 DelayMs(1); LCD_nRST_1; //************* Start Initial Sequence **********// LCD_WrCmdDat(0x00E3, 0x3008);// Set internal timing LCD_WrCmdDat(0x00E7, 0x0012); // Set internal timing LCD_WrCmdDat(0x00EF, 0x1231); // Set internal timing LCD_WrCmdDat(0x0001, 0x0100); // set SS and SM bit LCD_WrCmdDat(0x0002, 0x0700); // set 1 line inversion LCD_WrCmdDat(0x0003, 0x1030); // set GRAM write direction and BGR=1. LCD_WrCmdDat(0x0004, 0x0000); // Resize register LCD_WrCmdDat(0x0008, 0x0207); // set the back porch and front porch LCD_WrCmdDat(0x0009, 0x0700); //00,00// set non-display area refresh cycle ISC[3:0] LCD_WrCmdDat(0x000A, 0x0000); // FMARK function LCD_WrCmdDat(0x000C, 0x0000); // RGB interface setting LCD_WrCmdDat(0x000D, 0x0000); // Frame marker Position LCD_WrCmdDat(0x000F, 0x0000); // RGB interface polarity //*************Power On sequence ****************// LCD_WrCmdDat(0x0010, 0x00f0); //00,00// SAP, BT[3:0], AP, DSTB, SLP, STB LCD_WrCmdDat(0x0011, 0x0007); // DC1[2:0], DC0[2:0], VC[2:0] LCD_WrCmdDat(0x0012, 0x0096); //00,00 // VREG1OUT voltage LCD_WrCmdDat(0x0013, 0x0000); // VDV[4:0] for VCOM amplitude DelayMs(20); // Dis-charge capacitor power voltage LCD_WrCmdDat(0x0010, 0x1490); // SAP, BT[3:0], AP, DSTB, SLP, STB LCD_WrCmdDat(0x0011, 0x0227); // Set DC1[2:0], DC0[2:0], VC[2:0] DelayMs(20); // Delay 50ms LCD_WrCmdDat(0x0012, 0x001D); // External reference voltage= Vci; DelayMs(20); // Delay 50ms LCD_WrCmdDat(0x0013, 0x1A00); // Set VDV[4:0] for VCOM amplitude LCD_WrCmdDat(0x0029, 0x0033); //00,0b // SetVCM[5:0] for VCOMH LCD_WrCmdDat(0x002B, 0x000e); //00,00 // Set Frame Rate DelayMs(20); // Delay 50ms LCD_WrCmdDat(0x0020, 0x0000); // GRAM horizontal Address LCD_WrCmdDat(0x0021, 0x0000); // GRAM Vertical Address // ----------- Adjust the Gamma Curve ----------// LCD_WrCmdDat(0x0030, 0x0007); LCD_WrCmdDat(0x0031, 0x0206); LCD_WrCmdDat(0x0032, 0x0506); LCD_WrCmdDat(0x0035, 0x0704); LCD_WrCmdDat(0x0036, 0x1203); LCD_WrCmdDat(0x0037, 0x0007); LCD_WrCmdDat(0x0038, 0x0000); LCD_WrCmdDat(0x0039, 0x0706); LCD_WrCmdDat(0x003C, 0x0701); LCD_WrCmdDat(0x003D, 0x000F); //------------------ Set GRAM area ---------------// LCD_WrCmdDat(0x0050, 0x0000); // Horizontal GRAM Start Address LCD_WrCmdDat(0x0051, 0x00EF); // Horizontal GRAM End Address LCD_WrCmdDat(0x0052, 0x0000); // Vertical GRAM Start Address LCD_WrCmdDat(0x0053, 0x013F); // Vertical GRAM Start Address LCD_WrCmdDat(0x0060, 0xA700); // Gate Scan Line LCD_WrCmdDat(0x0061, 0x0001); // NDL,VLE, REV LCD_WrCmdDat(0x006A, 0x0000); // set scrolling line //-------------- Panel Control -------------------// */ LCD_WrCmdDat(0x0090, 0x0010); LCD_WrCmdDat(0x0092, 0x0600); LCD_WrCmdDat(0x0093, 0x0003); LCD_WrCmdDat(0x0095, 0x0110); LCD_WrCmdDat(0x0097, 0x0000); LCD_WrCmdDat(0x0098, 0x0000); LCD_WrCmdDat(0x0007, 0x0133); // 262K color and display ON //DelayMs(9000); //while(1); //LCD_BLEN_1; PenColor=YELLOW; BackColor=RED; } void DispOneColor(U16 X,U16 Y,U16 W,U16 H,U16 Color) { U16 i,j; LCD_SetWindows(X,Y,X+W-1,Y+H-1); LCD_SetGramPoit(X,Y); //根据扫描方式不同而不同 for(i=0;i0;i--); //1T单片机i=600,若是12T单片机i=125 } //------------------------------------------------------------------------------ void AD_init(void) { P1ASF=0xff; //P1口全部作为模拟功能AD使用 ADC_RES=0; //清零转换结果寄存器高8位 ADC_RESL=0; //清零转换结果寄存器低2位 ADC_CONTR=0x80;//开启AD电源 //delay(2); //等待1ms,让AD电源稳定 } void drawdot(unsigned char X,unsigned char Y) { DispOneColor(X,Y,2,2,RED); } void main(void) { unsigned char x=0; P1M0|=0x01; //设P1_0为开漏模式 如: P1_0= #00000000B P1M1|=0x01; LCD_Init(); AD_init(); LCD_Init(); //while(1) Display_full_screen_color(YELLOW); while(1) { drawdot(x,100+AD_get(0)/10); x++; if(x==220) { x=0; Display_full_screen_color(YELLOW); } } }