void SendLcd(unsigned char type, unsigned char dat) { byte i; LCD_DATA(type); // set up first bit as command or data LCD_CS(0); // Enable device CS LCD_CLK(0); // Pull Clock LOW LCD_CLK(1); // Pul Clock HIGH if(dat == 0x0){ // spi cannot transfer zero?? LCD_DATA(0); for(i=0; i<8; i++){ LCD_CLK(0); // Pull Clock LOW LCD_CLK(1); } } else{ SPCR |=0x50; // Enable Hardware SPI SPSR |= 0x1; SPDR = dat; // send data while(!(SPSR & 0x80)); // wait until send complete } SPCR &=~0x50; // Disable Hardware SPI, this releases the SPI pins // for general IO use. which is used to send the 1'st LCD_CS(1); // disable device CS // bit out }
void LCD_LINE(char line){ switch(line){ case 0: case 1: LCD_DATA(0x80,0); break; case 2: LCD_DATA(0xC0,0); break; } }
//--------------------------------------------------------------------------------// void LCD_LINE(char line){ switch(line){ case 0: case 1: LCD_DATA(LINE1,0); break; case 2: LCD_DATA(LINE2,0); break; } }
void LCD_IN_INTER(unsigned int d) { unsigned i,j,k,l; l=d/1000;//nghin k=(d%1000)/100;//tram j=((d%1000)%100)/10;//chuc i=((d%1000)%100)%10;//donvi LCD_DATA(0x30+l); LCD_DATA(0x30+k); LCD_DATA(0x30+j); LCD_DATA(0x30+i); }
void showCalendar_time(uint8_t hour, uint8_t min, uint8_t sec) { vTaskDelay(5); LCD_CMD(0xC1); //(row,column)=(2,2) vTaskDelay(5); LCD_DATA(table[hour/10]); vTaskDelay(5); LCD_DATA(table[hour%10]); vTaskDelay(5); LCD_CMD(0xC5); //(row,column)=(2,6) vTaskDelay(5); LCD_DATA(table[min/10]); vTaskDelay(5); LCD_DATA(table[min%10]); vTaskDelay(5); LCD_CMD(0xC9); //(row,column)=(2,10) vTaskDelay(5); LCD_DATA(table[sec/10]); vTaskDelay(5); LCD_DATA(table[sec%10]); vTaskDelay(5); LCD_CMD(0xC3); //(row,column)=(2,4) vTaskDelay(5); LCD_DATA(0x3A); //':' vTaskDelay(5); LCD_CMD(0xC7); //(row,column)=(2,8) vTaskDelay(5); LCD_DATA(0x3A); //':' vTaskDelay(5); }
//=======giu so thuc len lcd============================= void LCD_IN_FLOAT( float d) { char ch[]="."; unsigned int e, i,j,k,l; // d=round(d,1); e=(int)(d*10); l=e/1000;//nghin k=(e%1000)/100;//tram j=((e%1000)%100)/10;//chuc i=((e%1000)%100)%10;//donvi LCD_DATA(0x30+l); LCD_DATA(0x30+k); LCD_DATA(0x30+j); lcd_putstr(ch); LCD_DATA(0x30+i); }
void ili9163_write_pixel(int x, int y, int c) { ili9163_set_window(x,y,1,1);//设置光标位置 LCD_COM(0x2C); LCD_DATA(c>>8); LCD_DATA(c); }
void ili9163_set_window(int x, int y, int xlen, int ylen) { xlen--; ylen--; LCD_COM(0x2A); LCD_DATA(x>>8); LCD_DATA(x); LCD_DATA((x+xlen)>>8); LCD_DATA((x+xlen)); LCD_COM(0x2B); LCD_DATA(y>>8); LCD_DATA(y); LCD_DATA((y+ylen)>>8); LCD_DATA((y+ylen)); }
//--------------------------------------------------------------------------------// void LCD_STR(unsigned char *text, char clear){ unsigned char x=0; while(*text) { LCD_DATA(*text++,1); x++; } if(clear == 1) { while(x<16) { LCD_DATA(0x20,1); x++; } } }
void LCD_CHAR(unsigned char data) { LCD_E_LOW(); LCD_RS_HIGH(); LCD_DATA(data); LCD_E_HIGH(); tme_tempo(1); LCD_E_LOW(); }
void initLCD(void){ GPIO_DeInit(LCD_PORT); GPIO_Init(LCD_PORT, GPIO_PIN_ALL, GPIO_MODE_OUT_PP_LOW_FAST); GPIO_WriteLow(LCD_PORT,LCD_E); //clear enable GPIO_WriteLow(LCD_PORT,LCD_RS); //going to write command DelayMS(30); //delay for LCD to initialise. LCD_NYB(0x03,0); //Required for initialisation DelayMS(5); //required delay LCD_NYB(0x03,0); //Required for initialisation DelayMS(1); //required delay LCD_DATA(0x02,0); //set to 4 bit interface, 1 line and 5*7 font LCD_DATA(0x28,0); //set to 4 bit interface, 2 line and 5*10 font LCD_DATA(0x0c,0); //set to 4 bit interface, 2 line and 5*7 font LCD_DATA(0x01,0); //clear display LCD_DATA(0x06,0); //move cursor right after write }
void lcd_putstr(char *buffer) { while(*buffer != '\0') { LCD_DATA(*buffer); /* calling another function */ /* to write each char to the lcd module */ buffer++; Delay1KTCYx(2); }; }
void ili9163_clear(uint16_t c) { uint32_t i=0; ili9163_set_window(0,0,LCD_X_MAX,LCD_Y_MAX); LCD_COM(0x2C); //开始写入GRAM for(i = 0 ;i < LCD_X_MAX*LCD_Y_MAX; i++) { LCD_DATA(c>>8); LCD_DATA(c); } }
void LCD_Init(void) { LCD_CS(1); LCD_CLK(0); LCD_DATA(0); LCD_RESET(1); delay(50); LCD_RESET(0); delay(50); LCD_RESET(1); delay(50); LCD_CS(1); LCD_CLK(1); LCD_DATA(1); delay(10); SendLcd(LCDCommand,SWRESET); delay(10); SendLcd(LCDCommand,SLEEPOUT); // Sleepout // SendLcd(LCDCommand,INVON); // Invert display mode // SendLcd(LCDCommand,BSTRON); // BoostON SendLcd(LCDCommand,MADCTL); // memory access control SendLcd(LCDData,0xe0); SendLcd(LCDCommand,SETCON); // Set Contrast SendLcd(LCDData,0x40); delay(10); SendLcd(LCDCommand,DISPON); // Display On SendLcd(LCDCommand,COLMOD); // Set Color Mode SendLcd(LCDData,0x03); // 12bit per pixel SendLcd(LCDCommand,NOP); // Set Color Mode }
void LCD_Init(void){ //Setai pini pt LCD LCD_PORT->MODER = 0x5055; //Setaea pinilo pentu output PD0:PD3(DB4:DB7),PD6(E),PD7(RS) LCD_PORT->OTYPER = 0x00; //Setae de tip PUSH-PULL pentu toti LCD_PORT->OSPEEDR = 0xA0AA; //50 MHz Fecventa potului pentu LCD LCD_PORT->PUPDR = 0x00; //PULL-UP/PULL-DOWN Dezactivate BitClr(LCD_E); //clear enable - pin PD6 BitClr(LCD_RS); //going to write command - pin PD7 DelayMS(30); //delay for LCD to initialise. LCD_NYB(0x30,0); //Required for initialisation DelayMS(5); //required delay LCD_NYB(0x30,0); //Required for initialisation DelayMS(1); //required delay LCD_DATA(0x02,0); //set to 4 bit interface, 1 line and 5*7 font LCD_DATA(0x28,0); //set to 4 bit interface, 2 line and 5*10 font LCD_DATA(0x0c,0); //set to 4 bit interface, 2 line and 5*7 font LCD_DATA(0x01,0); //clear display LCD_DATA(0x06,0); //move cursor right after write }
//--------------------------------------------------------------------------------// void LCD_POS(unsigned char line){ unsigned char myDat; unsigned char pos = 18; LCD_LINE(line); switch(line){ case 0: case 1: myDat = LINE1 + pos; break; case 2: myDat = LINE2 + pos; break; } myDat |= 0x80; LCD_DATA(myDat,0); }
void lcd_puts_b(uint8_t c) { if (c == '\r') return; else if (c == '\n') lcdinfo.pos = (lcdinfo.pos ^ 0x10) & 0x10; else { LCD_DATA(c); CLOCK_BUSYWAIT_US(43); lcdinfo.pos++; lcdinfo.pos &= 0x1f; } if (lcdinfo.pos == 0x10) { LCD_COMMAND(LCD_CHANGE_CURSOR(1, 0)); } else if (lcdinfo.pos == 0x00) { LCD_COMMAND(LCD_CHANGE_CURSOR(0, 0)); } }
void SendLcd_color(unsigned char color){ LCD_DATA(LCDData); // set up first bit as command or data LCD_CLK(0); // Pull Clock LOW LCD_CLK(1); // Pul Clock HIGH LCD_CLK(0); SPCR |=0x50; // Enable Hardware SPI SPSR |=0x1; SPDR = color; // send data while(!(SPSR & 0x80)); // wait until send complete // disable device CS SPCR &=~0x50; // Disable Hardware SPI, this releases the SPI pins LCD_CLK(0); // for general IO use. which is used to send the 1'st // bit out }
void lcd_int(unsigned int a) { unsigned int x,y, z; x=a/100; y=(a/10)%10; z = a%10; if(x>=1) { LCD_DATA(0x30 +x); LCD_DATA(0x30+y); LCD_DATA(0x30+z); } else { LCD_DATA(0); LCD_DATA(0x30+y); LCD_DATA(0x30+z); } }
int ili9163_init(spi_bus_t bus, uint32_t cs) { uint32_t ret; device.csn = cs; device.config.baudrate = 50*1000*1000; device.config.data_width = 8; device.config.mode = SPI_MODE_0 | SPI_MASTER | SPI_MSB; ret = spi_bus_attach_device(bus, &device); if(ret) { return ret; } else { ret = spi_config(&device); } GPIO_QuickInit(RST_PORT, RST_PIN, kGPIO_Mode_OPP); GPIO_QuickInit(RS_PORT, RS_PIN, kGPIO_Mode_OPP); LCD_RST_LOW(); DelayMs(1); LCD_RST_HIGH(); DelayMs(1); LCD_COM(0x11); //关闭睡眠,振荡器工作 DelayMs(1); LCD_COM(0x3a); //每次传送16位数据(VIPF3-0=0101),每个像素16位(IFPF2-0=101) LCD_DATA(0x55); LCD_COM(0x26); LCD_DATA(0x04); LCD_COM(0xf2); //Driver Output Control(1) LCD_DATA(0x01); LCD_COM(0xe0); //Driver Output Control(1) LCD_DATA(0x3f); LCD_DATA(0x25); LCD_DATA(0x1c); LCD_DATA(0x1e); LCD_DATA(0x20); LCD_DATA(0x12); LCD_DATA(0x2a); LCD_DATA(0x90); LCD_DATA(0x24); LCD_DATA(0x11); LCD_DATA(0x00); LCD_DATA(0x00); LCD_DATA(0x00); LCD_DATA(0x00); LCD_DATA(0x00); LCD_COM(0xe1); //Driver Output Control(1) LCD_DATA(0x20); LCD_DATA(0x20); LCD_DATA(0x20); LCD_DATA(0x20); LCD_DATA(0x05); LCD_DATA(0x00); LCD_DATA(0x15); LCD_DATA(0xa7); LCD_DATA(0x3d); LCD_DATA(0x18); LCD_DATA(0x25); LCD_DATA(0x2a); LCD_DATA(0x2b); LCD_DATA(0x2b); LCD_DATA(0x3a); LCD_COM(0xb1); //设置屏幕刷新频率 LCD_DATA(0x08); //DIVA=8 LCD_DATA(0x08); //VPA =8,约90Hz LCD_COM(0xb4); //LCD Driveing control LCD_DATA(0x07); //NLA=1,NLB=1,NLC=1 LCD_COM(0xc0); //LCD Driveing control LCD_DATA(0x0a); LCD_DATA(0x02); LCD_COM(0xc1); //LCD Driveing control LCD_DATA(0x02); LCD_COM(0xc5); //LCD Driveing control LCD_DATA(0x4f); LCD_DATA(0x5a); LCD_COM(0xc7); //LCD Driveing control LCD_DATA(0x40); LCD_COM(0x2a); //配置MCU可操作的LCD内部RAM横坐标起始、结束参数 LCD_DATA(0x00); //横坐标起始地址0x0000 LCD_DATA(0x00); LCD_DATA(0x00); //横坐标结束地址0x007f(127) LCD_DATA(0x7f); LCD_COM(0x2b); //配置MCU可操作的LCD内部RAM纵坐标起始结束参数 LCD_DATA(0x00); //纵坐标起始地址0x0000 LCD_DATA(0x00); LCD_DATA(0x00); //纵坐标结束地址0x009f(159) LCD_DATA(0x9f); LCD_COM(0x36); //配置MPU和DDRAM对应关系 LCD_DATA(0xc0); //MX=1,MY=1 LCD_COM(0xb7); //LCD Driveing control LCD_DATA(0x00); //CRL=0 LCD_COM(0x29); //开启屏幕显示 LCD_COM(0x2c); //设置为LCD接收数据/命令模式 ili9163_clear(0x0000); return 0; }
void LCD_STR(const unsigned char *text){ while(*text){ LCD_DATA(*text++,1); } }
void lcd_putch(char data) { LCD_DATA(data); }