- void LCD_CtrlWrite_IC(unsigned char c)
- {
- unsigned char i=0;
- DDRA |= _BV(PA0) | _BV(PA1) | _BV(PA2) | _BV(PA3) | _BV(PA4);
- CLR_LCD_CS(); //片选后指令为拉低
- CLR_LCD_RS();
- for(i=0;i<8;i++)
- {
- if(c & 0x80) SET_LCD_SDA();
- else CLR_LCD_SDA();
-
- CLR_LCD_SCK();SET_LCD_SCK();
- c <<= 1;
- }
- SET_LCD_CS();
- }
- void LCD_DataWrite_IC(unsigned char data)
- {
- unsigned char i=0;
- DDRA |= _BV(PA0) | _BV(PA1) | _BV(PA2) | _BV(PA3) | _BV(PA4);
- CLR_LCD_CS(); //片选后指令为拉高
- SET_LCD_RS();
- for(i=0;i<8;i++)
- {
- if(data & 0x80) SET_LCD_SDA();
- else CLR_LCD_SDA();
-
- CLR_LCD_SCK();SET_LCD_SCK();
- data <<= 1;
- }
- SET_LCD_CS();
- }
- void LCD_DataWrite(unsigned char LCD_DataH,unsigned char LCD_DataL)
- {
- LCD_DataWrite_IC(LCD_DataH);
- LCD_DataWrite_IC(LCD_DataL);
- }
- void write_command(unsigned char c)
- {
- unsigned char i=0;
- DDRA |= _BV(PA0) | _BV(PA1) | _BV(PA2) | _BV(PA3) | _BV(PA4);
- CLR_LCD_CS();
- CLR_LCD_RS();
- for(i=0;i<8;i++)
- {
- if(c & 0x80) SET_LCD_SDA();
- else CLR_LCD_SDA();
-
- CLR_LCD_SCK();SET_LCD_SCK();
- c <<= 1;
- }
- SET_LCD_CS();
- }
- void write_data(unsigned char d)
- {
- unsigned char i=0;
- DDRA |= _BV(PA0) | _BV(PA1) | _BV(PA2) | _BV(PA3) | _BV(PA4);
- CLR_LCD_CS();
- SET_LCD_RS();
- for(i=0;i<8;i++)
- {
- if(d & 0x80) SET_LCD_SDA();
- else CLR_LCD_SDA();
-
- CLR_LCD_SCK(); SET_LCD_SCK();
- d <<= 1;
- }
- SET_LCD_CS();
- }
- void dsp_single_colour(unsigned char DH,unsigned char DL)
- {
- unsigned char i,j;
- //RamAdressSet();
- for (i=0;i<160;i++)
- for (j=0;j<128;j++)
- LCD_DataWrite(DH,DL);
- }
- void init_lcd18(void)
- {
- DDRA |= _BV(PA0) | _BV(PA1) | _BV(PA2) | _BV(PA3) | _BV(PA4); //PA0-4设置输出
- CLR_LCD_RESET();
- _delay_ms(5);
- SET_LCD_RESET();
- _delay_ms(5);
- //------------------------------------------------------------------//
- //-------------------Software Reset-------------------------------//
- //------------------------------------------------------------------//
- write_command(0x01); //Sofeware setting
- _delay_ms(10);
- write_command(0x11); //Sleep out
- _delay_ms(120); //Delay 120ms
- //------------------------------------ST7735S Frame Rate-----------------------------------------//
- write_command(0xB1);
- write_data(0x01);
- write_data(0x2C);
- write_data(0x2D);
- write_command(0xB2);
- write_data(0x01);
- write_data(0x2C);
- write_data(0x2D);
- write_command(0xB3);
- write_data(0x01);
- write_data(0x2C);
- write_data(0x2D);
- write_data(0x01);
- write_data(0x2C);
- write_data(0x2D);
- //------------------------------------End ST7735R Frame Rate-----------------------------------------//
- write_command(0xB4);//Column inversion
- write_data(0x07);
- //------------------------------------ST7735R Power Sequence-----------------------------------------//
- write_command(0xC0);
- write_data(0xA2);
- write_data(0x02);
- write_data(0x84);
- write_command(0xC1);
- write_data(0XC5);
- write_command(0xC2);
- write_data(0x0A);
- write_data(0x00);
- write_command(0xC3);
- write_data(0x8A);
- write_data(0x2A);
- write_command(0xC4);
- write_data(0x8A);
- write_data(0xEE);
- //---------------------------------End ST7735S Power Sequence-------------------------------------//
- write_command(0xC5); //VCOM
- write_data(0x1A);
- write_command(0x36); //MX, MY, RGB mode
- write_data(0xC8);
- //------------------------------------ST7735S Gamma Sequence-----------------------------------------//
- write_command(0xE0);
- write_data(0x02);
- write_data(0x1c);
- write_data(0x07);
- write_data(0x12);
- write_data(0x37);
- write_data(0x32);
- write_data(0x29);
- write_data(0x2d);
- write_data(0x29);
- write_data(0x25);
- write_data(0x2b);
- write_data(0x39);
- write_data(0x00);
- write_data(0x01);
- write_data(0x03);
- write_data(0x10);
- write_command(0xE1);
- write_data(0x03);
- write_data(0x1d);
- write_data(0x07);
- write_data(0x06);
- write_data(0x2e);
- write_data(0x2c);
- write_data(0x29);
- write_data(0x2d);
- write_data(0x2e);
- write_data(0x2e);
- write_data(0x37);
- write_data(0x3f);
- write_data(0x00);
- write_data(0x00);
- write_data(0x02);
- write_data(0x10);
- write_command(0x2A);
- write_data(0x00);
- write_data(0x02);
- write_data(0x00);
- write_data(0x81);
-
- write_command(0x2B);
- write_data(0x00);
- write_data(0x01);
- write_data(0x00);
- write_data(0xA0);
- //------------------------------------End ST7735S Gamma Sequence-----------------------------------------//
- write_command(0x3A); //65k mode
- write_data(0x05);
- write_command(0x29); //Display on
- */
- }
- //===========================================================================
- void RamAdressSet(void)
- {
- write_command(0x2A);
- write_data(0x00);
- write_data(0x00);
- write_data(0x00);
- write_data(0x7f);
-
- write_command(0x2B);
- write_data(0x00);
- write_data(0x00);
- write_data(0x00);
- write_data(0x9f);
- }
- void PutPixel(unsigned int x_start,unsigned int y_start,unsigned int color)
- {
- LCD_CtrlWrite_IC(0x2a);
- LCD_DataWrite_IC(x_start);
- LCD_DataWrite_IC(0x5f);
- LCD_CtrlWrite_IC(0x2b);
- LCD_DataWrite_IC(y_start+0x34);
- LCD_DataWrite_IC(0x7F);
- LCD_CtrlWrite_IC(0x2c);
- LCD_DataWrite_IC(color>>8);
- LCD_DataWrite_IC(color&0xff);
- }
- void RedLine(void)
- {
- unsigned char i=0,j=0;
- i=66; // 11格灰阶
- for(j=0;j<16;j++)
- {
- PutPixel(i,j,0xf800);
- }
- }
- void Output_Pixel(unsigned int x,unsigned int y)
- {
- LCD_CtrlWrite_IC(0x2A); //Column Address Set ****
- LCD_DataWrite_IC(x);//xsh
- LCD_DataWrite_IC(x);//xsl
- LCD_CtrlWrite_IC(0x2B);//Row Address Set ****
- LCD_DataWrite_IC(y);//ysl
- LCD_DataWrite_IC(y);//ysl
- LCD_CtrlWrite_IC(0x2c);
- LCD_DataWrite(0xf8,0x00);
- RamAdressSet();
- }
- void Display_ASCII8X16(unsigned int x0,unsigned int y0,unsigned char *s)
- {
- int i,j,k,x,y,xx;
-
- unsigned char qm;
-
- long int ulOffset;
-
- char ywbuf[32],temp[2];
- for(i = 0; i<strlen((char*)s);i++)
- {
- if(((unsigned char)(*(s+i))) >= 161)
- {
- temp[0] = *(s+i);
- temp[1] = '0';
- return;
- }
-
- else
- {
- qm = *(s+i);
- ulOffset = (long int)(qm) * 16;
-
- for (j = 0; j < 16; j ++)
- {
- ywbuf[j]=Zk_ASCII8X16[ulOffset+j];
- }
-
- for(y = 0;y < 16;y++)
- {
- for(x=0;x<8;x++)
- {
- k=x % 8;
-
- if(ywbuf[y]&(0x80 >> k))
- {
- xx=x0+x+i*8;
- Output_Pixel(xx,y+y0);
- }
- }
- }
- }
- }
- }
- void Display_Desc(void)
- {
- Display_ASCII8X16(1,52,str1);
- Display_ASCII8X16(1,64,str2);
- Display_ASCII8X16(1,76,str3);
- Display_ASCII8X16(1,88,str4);
- Display_ASCII8X16(1,100,str5);
- Display_ASCII8X16(1,112,str6);
- }
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/bian-cheng-ri-ji/40294.html