#include "Lcd.h" //下载中 unsigned char Downloading[]={ 0x00,0x02,0x02,0xC2,0x02,0x02,0x02,0xFE,0x82,0x82,0x82,0x82,0x82,0x02,0x00,0x00, 0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00, 0x08,0x08,0x88,0xC8,0x38,0x0C,0x0B,0x08,0x08,0xE8,0x08,0x08,0x08,0x08,0x08,0x00, 0x02,0x01,0x00,0xFF,0x40,0x41,0x41,0x41,0x41,0x7F,0x41,0x41,0x41,0x41,0x40,0x00, 0x02,0x02,0x02,0x02,0x02,0x02,0xFE,0x02,0x02,0x42,0x82,0x02,0x02,0x02,0x02,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x01,0x06,0x00,0x00,0x00, 0x90,0x94,0x94,0xF4,0x9F,0x94,0x94,0x94,0x10,0x10,0xFF,0x10,0x12,0xD4,0x10,0x00, 0x20,0x26,0x25,0x24,0xFE,0x14,0x14,0x14,0x80,0x40,0x27,0x18,0x26,0x41,0xF0,0x00, 0x00,0x00,0xF0,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0xF0,0x00,0x00,0x00, 0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x0F,0x00,0x00,0x00, }; //下载成功 unsigned char downloadSuccess[] { 0x02,0x02,0x02,0x02,0x02,0x02,0xFE,0x02,0x02,0x42,0x82,0x02,0x02,0x02,0x02,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x01,0x06,0x00,0x00,0x00, 0x90,0x94,0x94,0xF4,0x9F,0x94,0x94,0x94,0x10,0x10,0xFF,0x10,0x12,0xD4,0x10,0x00, 0x20,0x26,0x25,0x24,0xFE,0x14,0x14,0x14,0x80,0x40,0x27,0x18,0x26,0x41,0xF0,0x00, 0x10,0x0C,0x04,0x24,0x24,0x24,0x25,0x26,0x24,0x24,0x24,0x24,0x04,0x14,0x0C,0x00, 0x00,0x81,0x81,0x41,0x31,0x0F,0x01,0x01,0x01,0x7F,0x81,0x81,0x81,0xF1,0x00,0x00, 0x00,0x00,0xF8,0x88,0x88,0x88,0x88,0x08,0x08,0xFF,0x08,0x09,0x0A,0xC8,0x08,0x00, 0x80,0x60,0x1F,0x00,0x10,0x20,0x1F,0x80,0x40,0x21,0x16,0x18,0x26,0x41,0xF8,0x00, 0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x33,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }; //下载失败 unsigned char downloadFailure[] { 0x02,0x02,0x02,0x02,0x02,0x02,0xFE,0x02,0x02,0x42,0x82,0x02,0x02,0x02,0x02,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x01,0x06,0x00,0x00,0x00, 0x90,0x94,0x94,0xF4,0x9F,0x94,0x94,0x94,0x10,0x10,0xFF,0x10,0x12,0xD4,0x10,0x00, 0x20,0x26,0x25,0x24,0xFE,0x14,0x14,0x14,0x80,0x40,0x27,0x18,0x26,0x41,0xF0,0x00, 0x00,0x40,0x30,0x1E,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0x10,0x00,0x00,0x00, 0x81,0x81,0x41,0x21,0x11,0x0D,0x03,0x01,0x03,0x0D,0x11,0x21,0x41,0x81,0x81,0x00, 0x00,0xFE,0x02,0xFA,0x02,0xFE,0x40,0x20,0xD8,0x17,0x10,0x10,0xF0,0x10,0x10,0x00, 0x80,0x47,0x30,0x0F,0x10,0x67,0x80,0x40,0x21,0x16,0x08,0x16,0x21,0x40,0x80,0x00, 0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x33,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }; unsigned char ChooseAgain[]{ 0x40,0x42,0xCC,0x00,0x00,0x44,0x54,0x54,0x54,0x7F,0x54,0x54,0x54,0x44,0x40,0x00, 0x00,0x00,0x7F,0x20,0x10,0x00,0xFF,0x15,0x15,0x15,0x55,0x95,0x7F,0x00,0x00,0x00, 0x40,0x40,0x42,0xCC,0x00,0x50,0x4E,0xC8,0x48,0x7F,0xC8,0x48,0x48,0x40,0x00,0x00, 0x00,0x40,0x20,0x1F,0x20,0x50,0x4C,0x43,0x40,0x40,0x4F,0x50,0x50,0x5C,0x40,0x00, 0x10,0x10,0xFF,0x10,0x00,0x82,0x86,0x4A,0x52,0xA2,0x52,0x4A,0x86,0x80,0x80,0x00, 0x42,0x82,0x7F,0x01,0x00,0x10,0x12,0x12,0x12,0xFF,0x12,0x12,0x12,0x10,0x00,0x00, 0x10,0x10,0x10,0xFF,0x90,0x20,0x98,0x88,0x88,0xE9,0x8E,0x88,0x88,0xA8,0x98,0x00, 0x02,0x42,0x81,0x7F,0x00,0x00,0x80,0x84,0x4B,0x28,0x10,0x28,0x47,0x80,0x00,0x00, 0x40,0x30,0xEF,0x24,0x24,0x80,0xE4,0x9C,0x10,0x54,0x54,0xFF,0x54,0x7C,0x10,0x00, 0x01,0x01,0x7F,0x21,0x51,0x26,0x18,0x27,0x44,0x45,0x45,0x5F,0x45,0x45,0x44,0x00, }; Lcd::Lcd():spi_sck(51),spi_sda(72),spi_cs(154),spi_reset(150),spi_rs(156),COM_BOOT0(153) { printf("Lcd()\n"); write_dev(IOEXPORTPATH, 51); write_dev(IOEXPORTPATH, 72); write_dev(IOEXPORTPATH, 154); write_dev(IOEXPORTPATH, 150); write_dev(IOEXPORTPATH, 156); write_dev(IOEXPORTPATH, 153); COM_BOOT0.setDirection(Gpio::out); spi_sck.setDirection(Gpio::out); spi_sda.setDirection(Gpio::out); spi_cs.setDirection(Gpio::out); spi_reset.setDirection(Gpio::out); spi_rs.setDirection(Gpio::out); COM_BOOT0.setValue(Gpio::Low); spi_sck.setValue(Gpio::High); spi_sda.setValue(Gpio::High); spi_cs.setValue(Gpio::High); spi_reset.setValue(Gpio::High); spi_rs.setValue(Gpio::High); } /*延时*/ void delay(int i) { int j,k; for(j=0;j>4)&0x0f)+0x10); //设置列地址的高4位 Lcd_Transfer_Command(column&0x0f); //设置列地址的低4位 } /*全屏清屏*/ /*void Lcd::Lcd_Clear_screen() { //COM_BOOT0.setValue(Gpio::Low); unsigned char i,j; spi_cs.setValue(Gpio::Low); for(i=0;i<9;i++) { Lcd_Address(1+i,1); for(j=0;j<132;j++) { Lcd_Transfer_data(0x00); } } spi_cs.setValue(Gpio::High); }*/ void Lcd::Lcd_Clear_screen() { unsigned char i,j; //spi_cs.setValue(Gpio::Low); for(i=0; i<4; i++) { Lcd_Transfer_Command(0xb0+i); Lcd_Transfer_Command(0x10); Lcd_Transfer_Command(0x00); for(j = 0;j<132;j++) { Lcd_Transfer_data(0x00); } } } //===显示测试画面:例如全显示,隔行显示,隔列显示,雪花显示===== void Lcd::Lcd_Test_Display(unsigned char data1, unsigned char data2) { int i,j; for(j=0;j<8;j++) { spi_cs.setValue(Gpio::Low); Lcd_Address(j+1,1); for(i=0;i<128;i++) { Lcd_Transfer_data(data1); Lcd_Transfer_data(data2); } } } /*显示128x64点阵图像*/ void Lcd::Lcd_Display_Graphic_128x64(unsigned char page, unsigned char column, unsigned char *dp) { int i,j; for(j=0;j<8;j++) { spi_cs.setValue(Gpio::Low); Lcd_Address(page+j,column); for(i=0;i<128;i++) { Lcd_Transfer_data(*dp); dp++; } } } /*显示32x32点阵图像、汉字、生僻字或32x32点阵的其他图标*/ void Lcd::Lcd_Display_graphic_32x32(unsigned char page, unsigned char column, unsigned char *dp) { unsigned char i,j; spi_cs.setValue(Gpio::Low); for(j=0;j<4;j++) { Lcd_Address(page+j,column); for (i=0;i<31;i++) { Lcd_Transfer_data(*dp); /*写数据到LCD,每写完一个8位的数据后列地址自动加1*/ dp++; } } } /*显示16x16点阵图像、汉字、生僻字或16x16点阵的其他图标*/ void Lcd::Lcd_Display_Graphic_16x16_2(unsigned char reverse,unsigned char page,unsigned char column,unsigned char *dp) { unsigned char i,j; spi_cs.setValue(Gpio::Low); for(j=0;j<2;j++) { Lcd_Address(page+j,column); for (i=0;i<16;i++) { if(reverse==1) Lcd_Transfer_data(*dp); /*写数据到LCD,每写完一个8位的数据后列地址自动加1*/ else Lcd_Transfer_data(~*dp); /*写数据到LCD,每写完一个8位的数据后列地址自动加1*/ dp++; } } spi_cs.setValue(Gpio::High); } /*显示16x16点阵图像、汉字、生僻字或16x16点阵的其他图标*/ void Lcd::Lcd_Display_Graphic_16x16(unsigned char page, unsigned char column, unsigned char *dp, unsigned int wordcount) { unsigned char i,j,k; spi_cs.setValue(Gpio::Low); for (k = 0; k < wordcount; k++) { for(j=0;j<2;j++) { Lcd_Address(page+j,column+16 * k); for (i=0;i<16;i++) { Lcd_Transfer_data(*dp); /*写数据到LCD,每写完一个8位的数据后列地址自动加1*/ dp++; } } } spi_cs.setValue(Gpio::High); } /*显示8x16点阵图像、ASCII, 或8x16点阵的自造字符、其他图标*/ void Lcd::Lcd_Display_Graphic_8x16(unsigned char page, unsigned char column,unsigned char *dp) { unsigned char i,j; spi_cs.setValue(Gpio::Low); for(j=0;j<2;j++) { Lcd_Address(page+j,column); for (i=0;i<8;i++) { Lcd_Transfer_data(*dp); /*写数据到LCD,每写完一个8位的数据后列地址自动加1*/ dp++; } } spi_cs.setValue(Gpio::High); } /*void Lcd::Lcd_Display_String_8x16(unsigned int page, unsigned int column, const char *text) { unsigned int i=0,j,k,n; //COM_BOOT0.setValue(Gpio::Low); spi_cs.setValue(Gpio::Low); while(text[i]>0x00) { if((text[i]>=0x20)&&(text[i]<=0x7e)) { j=text[i]-0x20; for(n=0;n<2;n++) { Lcd_Address(page+n,column); for(k=0;k<8;k++) { Lcd_Transfer_data(ascii_table_8x16[j][k+8*n]);//显示5x7的ASCII字到LCD上,y为页地址,x为列地址,最后为数据 } } i++; column+=8; } else i++; } } */ /*void Lcd::Lcd_Display_String_5x8(unsigned int page, unsigned int column, const char *text) { unsigned int i=0,j,k; spi_cs.setValue(Gpio::Low); while(text[i]>0x00) { if((text[i]>=0x20)&&(text[i]<0x7e)) { j=text[i]-0x20; Lcd_Address(page,column); for(k=0;k<5;k++) { Lcd_Transfer_data(ascii_table_5x8[j][k]);//显示5x7的ASCII字到LCD上,y为页地址,x为列地址,最后为数据 } i++; column+=6; } else i++; } } */ void Lcd::display_Selective(int selective) { COM_BOOT0.setValue(Gpio::Low); switch(selective) { case 1: Lcd_Display_Graphic_16x16(1, 1, Downloading, 5); Lcd_Display_Graphic_16x16(3, 1, Downloading, 5); break; case 2: Lcd_Display_Graphic_16x16(1, 1, downloadSuccess, 5); Lcd_Display_Graphic_16x16(3, 1, downloadSuccess, 5); break; case 3: Lcd_Display_Graphic_16x16(1, 1, downloadFailure, 5); Lcd_Display_Graphic_16x16(3, 1, downloadFailure, 5); break; case 4: Lcd_Display_Graphic_16x16(1, 1, ChooseAgain, 5); Lcd_Display_Graphic_16x16(3, 1, ChooseAgain, 5); break; default: printf("selective display is erro!\n"); break; } }