Created
July 19, 2015 02:52
-
-
Save postmodern/ed6e670999f456ad9f13 to your computer and use it in GitHub Desktop.
ILI9341
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ili9341.h" | |
volatile uint16_t LCD_W=ILI9341_TFTWIDTH; | |
volatile uint16_t LCD_H=ILI9341_TFTHEIGHT; | |
void ili9341_hard_init(void)//init hardware | |
{ | |
rstddr=0xFF;//output for reset | |
rstport |=(1<<rst);//pull high for normal operation | |
controlddr|=(1<<dc);//D/C as output | |
} | |
void ili9341_spi_init(void)//set spi speed and settings | |
{ | |
DDRB |=(1<<1)|(1<<2)|(1<<3)|(1<<5);//CS,SS,MOSI,SCK as output(although SS will be unused throughout the program) | |
SPCR=(1<<SPE)|(1<<MSTR);//mode 0,fosc/4 | |
SPSR |=(1<<SPI2X);//doubling spi speed.i.e final spi speed-fosc/2 | |
PORTB |=(1<<1);//cs off during startup | |
} | |
void ili9341_spi_send(unsigned char spi_data)//send spi data to display | |
{ | |
SPDR=spi_data;//move data into spdr | |
while(!(SPSR & (1<<SPIF)));//wait till the transmission is finished | |
} | |
void ili9341_writecommand8(uint8_t com)//command write | |
{ | |
controlport &=~((1<<dc)|(1<<cs));//dc and cs both low to send command | |
_delay_us(5);//little delay | |
ili9341_spi_send(com); | |
controlport |=(1<<cs);//pull high cs | |
} | |
void ili9341_writedata8(uint8_t data)//data write | |
{ | |
controlport |=(1<<dc);//set dc high for data | |
_delay_us(1);//delay | |
controlport &=~(1<<cs);//set cs low for operation | |
ili9341_spi_send(data); | |
controlport |=(1<<cs); | |
} | |
void ili9341_setaddress(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2)//set coordinate for print or other function | |
{ | |
ili9341_writecommand8(0x2A); | |
ili9341_writedata8(x1>>8); | |
ili9341_writedata8(x1); | |
ili9341_writedata8(x2>>8); | |
ili9341_writedata8(x2); | |
ili9341_writecommand8(0x2B); | |
ili9341_writedata8(y1>>8); | |
ili9341_writedata8(y1); | |
ili9341_writedata8(y2); | |
ili9341_writedata8(y2); | |
ili9341_writecommand8(0x2C);//meory write | |
} | |
void ili9341_hard_reset(void)//hard reset display | |
{ | |
rstport |=(1<<rst);//pull high if low previously | |
_delay_ms(200); | |
rstport &=~(1<<rst);//low for reset | |
_delay_ms(200); | |
rstport |=(1<<rst);//again pull high for normal operation | |
_delay_ms(200); | |
} | |
void ili9341_init(void)//set up display using predefined command sequence | |
{ | |
ili9341_hard_init(); | |
ili9341_spi_init(); | |
ili9341_hard_reset(); | |
ili9341_writecommand8(0x01);//soft reset | |
_delay_ms(1000); | |
//power control A | |
ili9341_writecommand8(0xCB); | |
ili9341_writedata8(0x39); | |
ili9341_writedata8(0x2C); | |
ili9341_writedata8(0x00); | |
ili9341_writedata8(0x34); | |
ili9341_writedata8(0x02); | |
//power control B | |
ili9341_writecommand8(0xCF); | |
ili9341_writedata8(0x00); | |
ili9341_writedata8(0xC1); | |
ili9341_writedata8(0x30); | |
//driver timing control A | |
ili9341_writecommand8(0xE8); | |
ili9341_writedata8(0x85); | |
ili9341_writedata8(0x00); | |
ili9341_writedata8(0x78); | |
//driver timing control B | |
ili9341_writecommand8(0xEA); | |
ili9341_writedata8(0x00); | |
ili9341_writedata8(0x00); | |
//power on sequence control | |
ili9341_writecommand8(0xED); | |
ili9341_writedata8(0x64); | |
ili9341_writedata8(0x03); | |
ili9341_writedata8(0x12); | |
ili9341_writedata8(0x81); | |
//pump ratio control | |
ili9341_writecommand8(0xF7); | |
ili9341_writedata8(0x20); | |
//power control,VRH[5:0] | |
ili9341_writecommand8(0xC0); | |
ili9341_writedata8(0x23); | |
//Power control,SAP[2:0];BT[3:0] | |
ili9341_writecommand8(0xC1); | |
ili9341_writedata8(0x10); | |
//vcm control | |
ili9341_writecommand8(0xC5); | |
ili9341_writedata8(0x3E); | |
ili9341_writedata8(0x28); | |
//vcm control 2 | |
ili9341_writecommand8(0xC7); | |
ili9341_writedata8(0x86); | |
//memory access control | |
ili9341_writecommand8(0x36); | |
ili9341_writedata8(0x48); | |
//pixel format | |
ili9341_writecommand8(0x3A); | |
ili9341_writedata8(0x55); | |
//frameration control,normal mode full colours | |
ili9341_writecommand8(0xB1); | |
ili9341_writedata8(0x00); | |
ili9341_writedata8(0x18); | |
//display function control | |
ili9341_writecommand8(0xB6); | |
ili9341_writedata8(0x08); | |
ili9341_writedata8(0x82); | |
ili9341_writedata8(0x27); | |
//3gamma function disable | |
ili9341_writecommand8(0xF2); | |
ili9341_writedata8(0x00); | |
//gamma curve selected | |
ili9341_writecommand8(0x26); | |
ili9341_writedata8(0x01); | |
//set positive gamma correction | |
ili9341_writecommand8(0xE0); | |
ili9341_writedata8(0x0F); | |
ili9341_writedata8(0x31); | |
ili9341_writedata8(0x2B); | |
ili9341_writedata8(0x0C); | |
ili9341_writedata8(0x0E); | |
ili9341_writedata8(0x08); | |
ili9341_writedata8(0x4E); | |
ili9341_writedata8(0xF1); | |
ili9341_writedata8(0x37); | |
ili9341_writedata8(0x07); | |
ili9341_writedata8(0x10); | |
ili9341_writedata8(0x03); | |
ili9341_writedata8(0x0E); | |
ili9341_writedata8(0x09); | |
ili9341_writedata8(0x00); | |
//set negative gamma correction | |
ili9341_writecommand8(0xE1); | |
ili9341_writedata8(0x00); | |
ili9341_writedata8(0x0E); | |
ili9341_writedata8(0x14); | |
ili9341_writedata8(0x03); | |
ili9341_writedata8(0x11); | |
ili9341_writedata8(0x07); | |
ili9341_writedata8(0x31); | |
ili9341_writedata8(0xC1); | |
ili9341_writedata8(0x48); | |
ili9341_writedata8(0x08); | |
ili9341_writedata8(0x0F); | |
ili9341_writedata8(0x0C); | |
ili9341_writedata8(0x31); | |
ili9341_writedata8(0x36); | |
ili9341_writedata8(0x0F); | |
//exit sleep | |
ili9341_writecommand8(0x11); | |
_delay_ms(120); | |
//display on | |
ili9341_writecommand8(0x29); | |
} | |
//set colour for drawing | |
void ili9341_pushcolour(uint16_t colour) | |
{ | |
ili9341_writedata8(colour>>8); | |
ili9341_writedata8(colour); | |
} | |
//clear lcd and fill with colour | |
void ili9341_clear(uint16_t colour) | |
{ | |
uint16_t i,j; | |
ili9341_setaddress(0,0,LCD_W-1,LCD_H-1); | |
for(i=0;i<LCD_W;i++) | |
{ | |
for(j=0;j<LCD_H;j++) | |
{ | |
ili9341_pushcolour(colour); | |
} | |
} | |
} | |
//draw pixel | |
void ili9341_drawpixel(uint16_t x3,uint16_t y3,uint16_t colour1) //pixels will always be counted from right side.x is representing LCD width which will always be less tha 240.Y is representing LCD height which will always be less than 320 | |
{ | |
if ((x3 < 0) ||(x3 >= LCD_W) || (y3 < 0) || (y3 >= LCD_H)) | |
{ | |
return; | |
} | |
ili9341_setaddress(x3,y3,x3+1,y3+1); | |
ili9341_pushcolour(colour1); | |
} | |
//draw vertical line | |
void ili9341_drawvline(uint16_t x,uint16_t y,uint16_t h,uint16_t colour)//basically we will see this line horizental if we see the display 320*240 | |
{ | |
if ((x >= LCD_W) || (y >= LCD_H)) | |
{ | |
return; | |
} | |
if((y+h-1) >= LCD_H) | |
{ | |
h=LCD_H-y; | |
} | |
ili9341_setaddress(x,y,x,y+h-1); | |
while (h--) | |
{ | |
ili9341_pushcolour(colour); | |
} | |
} | |
//draw horizental line | |
void ili9341_drawhline(uint16_t x,uint16_t y,uint16_t w,uint16_t colour) | |
{ | |
if((x >=LCD_W) || (y >=LCD_H)) | |
{ | |
return; | |
} | |
if((x+w-1) >= LCD_W) | |
{ | |
w=LCD_W-x; | |
} | |
ili9341_setaddress(x,y,x+w-1,y); | |
while(w--) | |
{ | |
ili9341_pushcolour(colour); | |
} | |
} | |
//draw colour filled rectangle | |
void ili9341_fillrect(uint16_t x,uint16_t y,uint16_t w,uint16_t h,uint16_t colour) | |
{ | |
if ((x >= LCD_W) || (y >= LCD_H)) | |
{ | |
return; | |
} | |
if ((x+w-1) >= LCD_W) | |
{ | |
w = LCD_W-x; | |
} | |
if ((y+h-1) >= LCD_H) | |
{ | |
h = LCD_H-y; | |
} | |
ili9341_setaddress(x, y, x+w-1, y+h-1); | |
for(y=h; y>0; y--) | |
{ | |
for(x=w; x>0; x--) | |
{ | |
ili9341_pushcolour(colour); | |
} | |
} | |
} | |
//rotate screen at desired orientation | |
void ili9341_setRotation(uint8_t m) | |
{ | |
uint8_t rotation; | |
ili9341_writecommand8(0x36); | |
rotation=m%4; | |
switch (rotation) | |
{ | |
case 0: | |
ili9341_writedata8(0x40|0x08); | |
LCD_W = 240; | |
LCD_H = 320; | |
break; | |
case 1: | |
ili9341_writedata8(0x20|0x08); | |
LCD_W = 320; | |
LCD_H = 240; | |
break; | |
case 2: | |
ili9341_writedata8(0x80|0x08); | |
LCD_W = 240; | |
LCD_H = 320; | |
break; | |
case 3: | |
ili9341_writedata8(0x40|0x80|0x20|0x08); | |
LCD_W = 320; | |
LCD_H = 240; | |
break; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _ILI9341_H_ | |
#define _ILI9341_H_ | |
#include <avr/io.h> | |
#include <util/delay.h> | |
#include <avr/pgmspace.h> | |
#include <limits.h> | |
#include <inttypes.h> | |
#define controlport PORTB | |
#define controlddr DDRB | |
#define controlpin PINB | |
#define rstport PORTD | |
#define rstddr DDRD | |
#define rstpin PIND | |
#define dc 0 | |
#define cs 1 | |
#define rst 7 | |
#define ILI9341_TFTHEIGHT 240 | |
#define ILI9341_TFTWIDTH 320 | |
#define BLACK 0x0000 | |
#define NAVY 0x000F | |
#define DARKGREEN 0x03E0 | |
#define DARKCYAN 0x03EF | |
#define MAROON 0x7800 | |
#define PURPLE 0x780F | |
#define OLIVE 0x7BE0 | |
#define LIGHTGREY 0xC618 | |
#define DARKGREY 0x7BEF | |
#define BLUE 0x001F | |
#define GREEN 0x07E0 | |
#define CYAN 0x07FF | |
#define RED 0xF800 | |
#define MAGENTA 0xF81F | |
#define YELLOW 0xFFE0 | |
#define WHITE 0xFFFF | |
#define ORANGE 0xFD20 | |
#define GREENYELLOW 0xAFE5 | |
#define PINK 0xF81F | |
void ili9341_hard_init(void); | |
void ili9341_spi_init(void); | |
void ili9341_spi_send(unsigned char spi_data); | |
void ili9341_writecommand8(uint8_t com); | |
void ili9341_writedata8(uint8_t data); | |
void ili9341_setaddress(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2); | |
void ili9341_hard_reset(void); | |
void ili9341_init(void); | |
void ili9341_pushcolour(uint16_t colour); | |
void ili9341_clear(uint16_t colour); | |
void ili9341_drawpixel(uint16_t x3,uint16_t y3,uint16_t colour1); | |
void ili9341_drawvline(uint16_t x,uint16_t y,uint16_t h,uint16_t colour); | |
void ili9341_drawhline(uint16_t x,uint16_t y,uint16_t w,uint16_t colour); | |
void ili9341_fillrect(uint16_t x,uint16_t y,uint16_t w,uint16_t h,uint16_t colour); | |
void ili9341_setRotation(uint8_t x); | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ili9341.h" | |
#include "ili9341gfx.h" | |
volatile uint16_t cursor_x; | |
volatile uint16_t cursor_y; | |
volatile uint16_t textcolour; | |
volatile uint16_t textbgcolour; | |
volatile uint8_t textsize; | |
uint16_t vsetx,vsety,vactualx,vactualy,isetx,isety,iactualx,iactualy; | |
static FILE mydata = FDEV_SETUP_STREAM(ili9341_putchar_printf, NULL, _FDEV_SETUP_WRITE);//mydata declaration and converting it into stream | |
int16_t ili9341_putchar_printf(char var, FILE *stream)//this function will be called whenever printf is used | |
{ | |
ili9341_write(var); | |
return 0; | |
} | |
void backuplocationvset(void)//backing up vset data start location to print next vset data in exact location | |
{ | |
vsetx=cursor_x; | |
vsety=cursor_y; | |
} | |
void backuplocationvactual(void)//backing up vactual data start location to print next vactual data in exact location | |
{ | |
vactualx=cursor_x; | |
vactualy=cursor_y; | |
} | |
void backuplocationiset(void)//backing up iset data start location to print next iset data in exact location | |
{ | |
isetx=cursor_x; | |
isety=cursor_y; | |
} | |
void backuplocationiactual(void)//backing up iactual data start location to print next iactual data in exact location | |
{ | |
iactualx=cursor_x; | |
iactualy=cursor_y; | |
} | |
//array for font | |
static const unsigned char font[] PROGMEM = { | |
0x00, 0x00, 0x00, 0x00, 0x00, | |
0x3E, 0x5B, 0x4F, 0x5B, 0x3E, | |
0x3E, 0x6B, 0x4F, 0x6B, 0x3E, | |
0x1C, 0x3E, 0x7C, 0x3E, 0x1C, | |
0x18, 0x3C, 0x7E, 0x3C, 0x18, | |
0x1C, 0x57, 0x7D, 0x57, 0x1C, | |
0x1C, 0x5E, 0x7F, 0x5E, 0x1C, | |
0x00, 0x18, 0x3C, 0x18, 0x00, | |
0xFF, 0xE7, 0xC3, 0xE7, 0xFF, | |
0x00, 0x18, 0x24, 0x18, 0x00, | |
0xFF, 0xE7, 0xDB, 0xE7, 0xFF, | |
0x30, 0x48, 0x3A, 0x06, 0x0E, | |
0x26, 0x29, 0x79, 0x29, 0x26, | |
0x40, 0x7F, 0x05, 0x05, 0x07, | |
0x40, 0x7F, 0x05, 0x25, 0x3F, | |
0x5A, 0x3C, 0xE7, 0x3C, 0x5A, | |
0x7F, 0x3E, 0x1C, 0x1C, 0x08, | |
0x08, 0x1C, 0x1C, 0x3E, 0x7F, | |
0x14, 0x22, 0x7F, 0x22, 0x14, | |
0x5F, 0x5F, 0x00, 0x5F, 0x5F, | |
0x06, 0x09, 0x7F, 0x01, 0x7F, | |
0x00, 0x66, 0x89, 0x95, 0x6A, | |
0x60, 0x60, 0x60, 0x60, 0x60, | |
0x94, 0xA2, 0xFF, 0xA2, 0x94, | |
0x08, 0x04, 0x7E, 0x04, 0x08, | |
0x10, 0x20, 0x7E, 0x20, 0x10, | |
0x08, 0x08, 0x2A, 0x1C, 0x08, | |
0x08, 0x1C, 0x2A, 0x08, 0x08, | |
0x1E, 0x10, 0x10, 0x10, 0x10, | |
0x0C, 0x1E, 0x0C, 0x1E, 0x0C, | |
0x30, 0x38, 0x3E, 0x38, 0x30, | |
0x06, 0x0E, 0x3E, 0x0E, 0x06, | |
0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x5F, 0x00, 0x00, | |
0x00, 0x07, 0x00, 0x07, 0x00, | |
0x14, 0x7F, 0x14, 0x7F, 0x14, | |
0x24, 0x2A, 0x7F, 0x2A, 0x12, | |
0x23, 0x13, 0x08, 0x64, 0x62, | |
0x36, 0x49, 0x56, 0x20, 0x50, | |
0x00, 0x08, 0x07, 0x03, 0x00, | |
0x00, 0x1C, 0x22, 0x41, 0x00, | |
0x00, 0x41, 0x22, 0x1C, 0x00, | |
0x2A, 0x1C, 0x7F, 0x1C, 0x2A, | |
0x08, 0x08, 0x3E, 0x08, 0x08, | |
0x00, 0x80, 0x70, 0x30, 0x00, | |
0x08, 0x08, 0x08, 0x08, 0x08, | |
0x00, 0x00, 0x60, 0x60, 0x00, | |
0x20, 0x10, 0x08, 0x04, 0x02, | |
0x3E, 0x51, 0x49, 0x45, 0x3E, | |
0x00, 0x42, 0x7F, 0x40, 0x00, | |
0x72, 0x49, 0x49, 0x49, 0x46, | |
0x21, 0x41, 0x49, 0x4D, 0x33, | |
0x18, 0x14, 0x12, 0x7F, 0x10, | |
0x27, 0x45, 0x45, 0x45, 0x39, | |
0x3C, 0x4A, 0x49, 0x49, 0x31, | |
0x41, 0x21, 0x11, 0x09, 0x07, | |
0x36, 0x49, 0x49, 0x49, 0x36, | |
0x46, 0x49, 0x49, 0x29, 0x1E, | |
0x00, 0x00, 0x14, 0x00, 0x00, | |
0x00, 0x40, 0x34, 0x00, 0x00, | |
0x00, 0x08, 0x14, 0x22, 0x41, | |
0x14, 0x14, 0x14, 0x14, 0x14, | |
0x00, 0x41, 0x22, 0x14, 0x08, | |
0x02, 0x01, 0x59, 0x09, 0x06, | |
0x3E, 0x41, 0x5D, 0x59, 0x4E, | |
0x7C, 0x12, 0x11, 0x12, 0x7C, | |
0x7F, 0x49, 0x49, 0x49, 0x36, | |
0x3E, 0x41, 0x41, 0x41, 0x22, | |
0x7F, 0x41, 0x41, 0x41, 0x3E, | |
0x7F, 0x49, 0x49, 0x49, 0x41, | |
0x7F, 0x09, 0x09, 0x09, 0x01, | |
0x3E, 0x41, 0x41, 0x51, 0x73, | |
0x7F, 0x08, 0x08, 0x08, 0x7F, | |
0x00, 0x41, 0x7F, 0x41, 0x00, | |
0x20, 0x40, 0x41, 0x3F, 0x01, | |
0x7F, 0x08, 0x14, 0x22, 0x41, | |
0x7F, 0x40, 0x40, 0x40, 0x40, | |
0x7F, 0x02, 0x1C, 0x02, 0x7F, | |
0x7F, 0x04, 0x08, 0x10, 0x7F, | |
0x3E, 0x41, 0x41, 0x41, 0x3E, | |
0x7F, 0x09, 0x09, 0x09, 0x06, | |
0x3E, 0x41, 0x51, 0x21, 0x5E, | |
0x7F, 0x09, 0x19, 0x29, 0x46, | |
0x26, 0x49, 0x49, 0x49, 0x32, | |
0x03, 0x01, 0x7F, 0x01, 0x03, | |
0x3F, 0x40, 0x40, 0x40, 0x3F, | |
0x1F, 0x20, 0x40, 0x20, 0x1F, | |
0x3F, 0x40, 0x38, 0x40, 0x3F, | |
0x63, 0x14, 0x08, 0x14, 0x63, | |
0x03, 0x04, 0x78, 0x04, 0x03, | |
0x61, 0x59, 0x49, 0x4D, 0x43, | |
0x00, 0x7F, 0x41, 0x41, 0x41, | |
0x02, 0x04, 0x08, 0x10, 0x20, | |
0x00, 0x41, 0x41, 0x41, 0x7F, | |
0x04, 0x02, 0x01, 0x02, 0x04, | |
0x40, 0x40, 0x40, 0x40, 0x40, | |
0x00, 0x03, 0x07, 0x08, 0x00, | |
0x20, 0x54, 0x54, 0x78, 0x40, | |
0x7F, 0x28, 0x44, 0x44, 0x38, | |
0x38, 0x44, 0x44, 0x44, 0x28, | |
0x38, 0x44, 0x44, 0x28, 0x7F, | |
0x38, 0x54, 0x54, 0x54, 0x18, | |
0x00, 0x08, 0x7E, 0x09, 0x02, | |
0x18, 0xA4, 0xA4, 0x9C, 0x78, | |
0x7F, 0x08, 0x04, 0x04, 0x78, | |
0x00, 0x44, 0x7D, 0x40, 0x00, | |
0x20, 0x40, 0x40, 0x3D, 0x00, | |
0x7F, 0x10, 0x28, 0x44, 0x00, | |
0x00, 0x41, 0x7F, 0x40, 0x00, | |
0x7C, 0x04, 0x78, 0x04, 0x78, | |
0x7C, 0x08, 0x04, 0x04, 0x78, | |
0x38, 0x44, 0x44, 0x44, 0x38, | |
0xFC, 0x18, 0x24, 0x24, 0x18, | |
0x18, 0x24, 0x24, 0x18, 0xFC, | |
0x7C, 0x08, 0x04, 0x04, 0x08, | |
0x48, 0x54, 0x54, 0x54, 0x24, | |
0x04, 0x04, 0x3F, 0x44, 0x24, | |
0x3C, 0x40, 0x40, 0x20, 0x7C, | |
0x1C, 0x20, 0x40, 0x20, 0x1C, | |
0x3C, 0x40, 0x30, 0x40, 0x3C, | |
0x44, 0x28, 0x10, 0x28, 0x44, | |
0x4C, 0x90, 0x90, 0x90, 0x7C, | |
0x44, 0x64, 0x54, 0x4C, 0x44, | |
0x00, 0x08, 0x36, 0x41, 0x00, | |
0x00, 0x00, 0x77, 0x00, 0x00, | |
0x00, 0x41, 0x36, 0x08, 0x00, | |
0x02, 0x01, 0x02, 0x04, 0x02, | |
0x3C, 0x26, 0x23, 0x26, 0x3C, | |
0x1E, 0xA1, 0xA1, 0x61, 0x12, | |
0x3A, 0x40, 0x40, 0x20, 0x7A, | |
0x38, 0x54, 0x54, 0x55, 0x59, | |
0x21, 0x55, 0x55, 0x79, 0x41, | |
0x22, 0x54, 0x54, 0x78, 0x42, // a-umlaut | |
0x21, 0x55, 0x54, 0x78, 0x40, | |
0x20, 0x54, 0x55, 0x79, 0x40, | |
0x0C, 0x1E, 0x52, 0x72, 0x12, | |
0x39, 0x55, 0x55, 0x55, 0x59, | |
0x39, 0x54, 0x54, 0x54, 0x59, | |
0x39, 0x55, 0x54, 0x54, 0x58, | |
0x00, 0x00, 0x45, 0x7C, 0x41, | |
0x00, 0x02, 0x45, 0x7D, 0x42, | |
0x00, 0x01, 0x45, 0x7C, 0x40, | |
0x7D, 0x12, 0x11, 0x12, 0x7D, // A-umlaut | |
0xF0, 0x28, 0x25, 0x28, 0xF0, | |
0x7C, 0x54, 0x55, 0x45, 0x00, | |
0x20, 0x54, 0x54, 0x7C, 0x54, | |
0x7C, 0x0A, 0x09, 0x7F, 0x49, | |
0x32, 0x49, 0x49, 0x49, 0x32, | |
0x3A, 0x44, 0x44, 0x44, 0x3A, // o-umlaut | |
0x32, 0x4A, 0x48, 0x48, 0x30, | |
0x3A, 0x41, 0x41, 0x21, 0x7A, | |
0x3A, 0x42, 0x40, 0x20, 0x78, | |
0x00, 0x9D, 0xA0, 0xA0, 0x7D, | |
0x3D, 0x42, 0x42, 0x42, 0x3D, // O-umlaut | |
0x3D, 0x40, 0x40, 0x40, 0x3D, | |
0x3C, 0x24, 0xFF, 0x24, 0x24, | |
0x48, 0x7E, 0x49, 0x43, 0x66, | |
0x2B, 0x2F, 0xFC, 0x2F, 0x2B, | |
0xFF, 0x09, 0x29, 0xF6, 0x20, | |
0xC0, 0x88, 0x7E, 0x09, 0x03, | |
0x20, 0x54, 0x54, 0x79, 0x41, | |
0x00, 0x00, 0x44, 0x7D, 0x41, | |
0x30, 0x48, 0x48, 0x4A, 0x32, | |
0x38, 0x40, 0x40, 0x22, 0x7A, | |
0x00, 0x7A, 0x0A, 0x0A, 0x72, | |
0x7D, 0x0D, 0x19, 0x31, 0x7D, | |
0x26, 0x29, 0x29, 0x2F, 0x28, | |
0x26, 0x29, 0x29, 0x29, 0x26, | |
0x30, 0x48, 0x4D, 0x40, 0x20, | |
0x38, 0x08, 0x08, 0x08, 0x08, | |
0x08, 0x08, 0x08, 0x08, 0x38, | |
0x2F, 0x10, 0xC8, 0xAC, 0xBA, | |
0x2F, 0x10, 0x28, 0x34, 0xFA, | |
0x00, 0x00, 0x7B, 0x00, 0x00, | |
0x08, 0x14, 0x2A, 0x14, 0x22, | |
0x22, 0x14, 0x2A, 0x14, 0x08, | |
0xAA, 0x00, 0x55, 0x00, 0xAA, | |
0xAA, 0x55, 0xAA, 0x55, 0xAA, | |
0x00, 0x00, 0x00, 0xFF, 0x00, | |
0x10, 0x10, 0x10, 0xFF, 0x00, | |
0x14, 0x14, 0x14, 0xFF, 0x00, | |
0x10, 0x10, 0xFF, 0x00, 0xFF, | |
0x10, 0x10, 0xF0, 0x10, 0xF0, | |
0x14, 0x14, 0x14, 0xFC, 0x00, | |
0x14, 0x14, 0xF7, 0x00, 0xFF, | |
0x00, 0x00, 0xFF, 0x00, 0xFF, | |
0x14, 0x14, 0xF4, 0x04, 0xFC, | |
0x14, 0x14, 0x17, 0x10, 0x1F, | |
0x10, 0x10, 0x1F, 0x10, 0x1F, | |
0x14, 0x14, 0x14, 0x1F, 0x00, | |
0x10, 0x10, 0x10, 0xF0, 0x00, | |
0x00, 0x00, 0x00, 0x1F, 0x10, | |
0x10, 0x10, 0x10, 0x1F, 0x10, | |
0x10, 0x10, 0x10, 0xF0, 0x10, | |
0x00, 0x00, 0x00, 0xFF, 0x10, | |
0x10, 0x10, 0x10, 0x10, 0x10, | |
0x10, 0x10, 0x10, 0xFF, 0x10, | |
0x00, 0x00, 0x00, 0xFF, 0x14, | |
0x00, 0x00, 0xFF, 0x00, 0xFF, | |
0x00, 0x00, 0x1F, 0x10, 0x17, | |
0x00, 0x00, 0xFC, 0x04, 0xF4, | |
0x14, 0x14, 0x17, 0x10, 0x17, | |
0x14, 0x14, 0xF4, 0x04, 0xF4, | |
0x00, 0x00, 0xFF, 0x00, 0xF7, | |
0x14, 0x14, 0x14, 0x14, 0x14, | |
0x14, 0x14, 0xF7, 0x00, 0xF7, | |
0x14, 0x14, 0x14, 0x17, 0x14, | |
0x10, 0x10, 0x1F, 0x10, 0x1F, | |
0x14, 0x14, 0x14, 0xF4, 0x14, | |
0x10, 0x10, 0xF0, 0x10, 0xF0, | |
0x00, 0x00, 0x1F, 0x10, 0x1F, | |
0x00, 0x00, 0x00, 0x1F, 0x14, | |
0x00, 0x00, 0x00, 0xFC, 0x14, | |
0x00, 0x00, 0xF0, 0x10, 0xF0, | |
0x10, 0x10, 0xFF, 0x10, 0xFF, | |
0x14, 0x14, 0x14, 0xFF, 0x14, | |
0x10, 0x10, 0x10, 0x1F, 0x00, | |
0x00, 0x00, 0x00, 0xF0, 0x10, | |
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | |
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, | |
0xFF, 0xFF, 0xFF, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0xFF, 0xFF, | |
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, | |
0x38, 0x44, 0x44, 0x38, 0x44, | |
0xFC, 0x4A, 0x4A, 0x4A, 0x34, // sharp-s or beta | |
0x7E, 0x02, 0x02, 0x06, 0x06, | |
0x02, 0x7E, 0x02, 0x7E, 0x02, | |
0x63, 0x55, 0x49, 0x41, 0x63, | |
0x38, 0x44, 0x44, 0x3C, 0x04, | |
0x40, 0x7E, 0x20, 0x1E, 0x20, | |
0x06, 0x02, 0x7E, 0x02, 0x02, | |
0x99, 0xA5, 0xE7, 0xA5, 0x99, | |
0x1C, 0x2A, 0x49, 0x2A, 0x1C, | |
0x4C, 0x72, 0x01, 0x72, 0x4C, | |
0x30, 0x4A, 0x4D, 0x4D, 0x30, | |
0x30, 0x48, 0x78, 0x48, 0x30, | |
0xBC, 0x62, 0x5A, 0x46, 0x3D, | |
0x3E, 0x49, 0x49, 0x49, 0x00, | |
0x7E, 0x01, 0x01, 0x01, 0x7E, | |
0x2A, 0x2A, 0x2A, 0x2A, 0x2A, | |
0x44, 0x44, 0x5F, 0x44, 0x44, | |
0x40, 0x51, 0x4A, 0x44, 0x40, | |
0x40, 0x44, 0x4A, 0x51, 0x40, | |
0x00, 0x00, 0xFF, 0x01, 0x03, | |
0xE0, 0x80, 0xFF, 0x00, 0x00, | |
0x08, 0x08, 0x6B, 0x6B, 0x08, | |
0x36, 0x12, 0x36, 0x24, 0x36, | |
0x06, 0x0F, 0x09, 0x0F, 0x06, | |
0x00, 0x00, 0x18, 0x18, 0x00, | |
0x00, 0x00, 0x10, 0x10, 0x00, | |
0x30, 0x40, 0xFF, 0x01, 0x01, | |
0x00, 0x1F, 0x01, 0x01, 0x1E, | |
0x00, 0x19, 0x1D, 0x17, 0x12, | |
0x00, 0x3C, 0x3C, 0x3C, 0x3C, | |
0x00, 0x00, 0x00, 0x00, 0x00 | |
}; | |
extern uint16_t LCD_W,LCD_H; | |
void ili9341_drawchar(int16_t x, int16_t y, unsigned char c,uint16_t color, uint16_t bg, uint8_t size) //draw a char like a,b or 1,2 | |
{ | |
if ((x >=LCD_W) || // Clip right | |
(y >=LCD_H) || // Clip bottom | |
((x + 6 * size - 1) < 0) || // Clip left | |
((y + 8 * size - 1) < 0)) // Clip top | |
{ | |
return; | |
} | |
for (int8_t i=0; i<6; i++ ) | |
{ | |
uint8_t line; | |
if (i == 5) | |
{ | |
line = 0x0; | |
} | |
else | |
{ | |
line = pgm_read_byte(font+(c*5)+i); | |
} | |
for (int8_t j = 0; j<8; j++) | |
{ | |
if (line & 0x1) | |
{ | |
if (size == 1) // default size | |
{ | |
ili9341_drawpixel(x+i, y+j, color); | |
} | |
else { // big size | |
ili9341_fillrect(x+(i*size), y+(j*size), size, size, color); | |
} | |
} else if (bg != color) | |
{ | |
if (size == 1) // default size | |
{ | |
ili9341_drawpixel(x+i, y+j, bg); | |
} | |
else | |
{ // big size | |
ili9341_fillrect(x+i*size, y+j*size, size, size, bg); | |
} | |
} | |
line >>= 1; | |
} | |
} | |
} | |
void ili9341_setcursor(uint16_t x,uint16_t y)//set cursor at desired location to print data | |
{ | |
cursor_x=x; | |
cursor_y=y; | |
} | |
void ili9341_settextcolour(uint16_t x,uint16_t y)//set text colour and text background colour | |
{ | |
textcolour=x; | |
textbgcolour=y; | |
} | |
void ili9341_settextsize(uint8_t s) | |
{ | |
if(s>8) return; | |
textsize=(s>0) ? s: 1;//this operation means if s0 greater than 0,then s=s,else s=1 | |
} | |
void ili9341_write(uint8_t c)//write a character at setted coordinates after setting location and colour | |
{ | |
if (c == '\n') | |
{ | |
cursor_y += textsize*8; | |
cursor_x = 0; | |
} | |
else if (c == '\r') | |
{ | |
// skip em | |
} | |
else | |
{ | |
ili9341_drawchar(cursor_x, cursor_y, c, textcolour, textbgcolour, textsize); | |
cursor_x += textsize*6; | |
} | |
} | |
void display_init(void)//display initial data regarding my power supply | |
{ | |
stdout = & mydata;//it is used for printf function and must be declared locally | |
ili9341_setcursor(4,4); | |
_delay_ms(2); | |
ili9341_settextcolour(GREEN,BLACK); | |
_delay_ms(2); | |
ili9341_settextsize(2); | |
_delay_ms(2); | |
printf("mode - "); | |
_delay_ms(2); | |
ili9341_settextcolour(RED,BLACK); | |
_delay_ms(2); | |
ili9341_settextsize(2); | |
_delay_ms(2); | |
printf("constant voltage"); | |
_delay_ms(2); | |
ili9341_setcursor(4,40); | |
_delay_ms(2); | |
ili9341_settextcolour(CYAN,BLACK); | |
_delay_ms(2); | |
ili9341_settextsize(4); | |
_delay_ms(2); | |
ili9341_write('V'); | |
_delay_ms(2); | |
cursor_y=cursor_y+6; | |
ili9341_settextsize(3); | |
_delay_ms(2); | |
printf("set\n"); | |
_delay_ms(2); | |
cursor_y=cursor_y+12; | |
backuplocationvset(); | |
printf("00.00v"); | |
_delay_ms(2); | |
ili9341_setcursor(4,120); | |
_delay_ms(2); | |
ili9341_settextsize(4); | |
_delay_ms(2); | |
ili9341_write('V'); | |
_delay_ms(2); | |
cursor_y=cursor_y+6; | |
ili9341_settextsize(3); | |
_delay_ms(2); | |
printf("actual\n\n"); | |
_delay_ms(2); | |
backuplocationvactual(); | |
ili9341_settextsize(5); | |
printf("00.00"); | |
_delay_ms(2); | |
ili9341_setcursor(164,40); | |
_delay_ms(2); | |
ili9341_settextcolour(YELLOW,BLACK); | |
_delay_ms(2); | |
ili9341_settextsize(4); | |
_delay_ms(2); | |
ili9341_write('I'); | |
_delay_ms(2); | |
cursor_y=cursor_y+6; | |
ili9341_settextsize(3); | |
_delay_ms(2); | |
printf("set"); | |
_delay_ms(2); | |
cursor_x=164; | |
cursor_y=(cursor_y+36); | |
backuplocationiset(); | |
ili9341_settextsize(3); | |
printf("00.00a"); | |
_delay_ms(2); | |
ili9341_setcursor(164,120); | |
_delay_ms(2); | |
ili9341_settextsize(4); | |
_delay_ms(2); | |
ili9341_write('I'); | |
_delay_ms(2); | |
cursor_y=cursor_y+6; | |
ili9341_settextsize(3); | |
_delay_ms(2); | |
printf("actual"); | |
_delay_ms(2); | |
cursor_x=164; | |
backuplocationiactual(); | |
cursor_y=cursor_y+48; | |
ili9341_settextsize(5); | |
printf("00.00"); | |
_delay_ms(2000); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _ILI9341GFX_H_ | |
#define _ILI9341GFX_H_ | |
#include <avr/io.h> | |
#include <avr/pgmspace.h> | |
#include <stdio.h> | |
#include <stdbool.h> | |
#include <inttypes.h> | |
int16_t ili9341_putchar_printf(char var, FILE *stream); | |
void ili9341_drawchar(int16_t x, int16_t y, unsigned char c,uint16_t color, uint16_t bg, uint8_t size); | |
void ili9341_setcursor(uint16_t x,uint16_t y); | |
void ili9341_settextcolour(uint16_t x,uint16_t y); | |
void ili9341_settextsize(uint8_t s); | |
void ili9341_write(uint8_t c); | |
void backuplocationvset(void); | |
void backuplocationvactual(void); | |
void backuplocationiset(void); | |
void backuplocationiactual(void); | |
void display_init(void); | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/io.h> | |
#include <util/delay.h> | |
#include "ili9341.h" | |
#include "ili9341gfx.h" | |
extern uint16_t vsetx,vsety,vactualx,vactualy,isetx,isety,iactualx,iactualy; | |
static FILE mydata = FDEV_SETUP_STREAM(ili9341_putchar_printf, NULL, _FDEV_SETUP_WRITE); | |
int main() | |
{ | |
stdout = & mydata; | |
ili9341_init(); //initial driver setup to drive ili9341 | |
ili9341_clear(BLACK); //fill screen with black colour | |
_delay_ms(1000); | |
ili9341_setRotation(3); //rotate screen | |
_delay_ms(2); | |
display_init(); //display initial data | |
while (1) | |
{ | |
ili9341_settextcolour(CYAN,BLACK); | |
ili9341_setcursor(vsetx,vsety); | |
_delay_ms(2); | |
ili9341_settextsize(3); | |
ili9341_write('1'); | |
_delay_ms(2); | |
ili9341_write('0'); | |
_delay_ms(2); | |
ili9341_write('.'); | |
_delay_ms(2); | |
ili9341_write('2'); | |
_delay_ms(2); | |
ili9341_write('3'); | |
_delay_ms(2); | |
ili9341_setcursor(vactualx,vactualy); | |
_delay_ms(2); | |
ili9341_settextsize(5); | |
ili9341_write('1'); | |
_delay_ms(2); | |
ili9341_write('0'); | |
_delay_ms(2); | |
ili9341_write('.'); | |
_delay_ms(2); | |
ili9341_write('2'); | |
_delay_ms(2); | |
ili9341_write('3'); | |
_delay_ms(2); | |
_delay_ms(2000); | |
ili9341_setcursor(vsetx,vsety); | |
_delay_ms(2); | |
ili9341_settextsize(3); | |
ili9341_write('9'); | |
_delay_ms(2); | |
ili9341_write('0'); | |
_delay_ms(2); | |
ili9341_write('.'); | |
_delay_ms(2); | |
ili9341_write('4'); | |
_delay_ms(2); | |
ili9341_write('5'); | |
_delay_ms(2); | |
ili9341_setcursor(vactualx,vactualy); | |
_delay_ms(2); | |
ili9341_settextsize(5); | |
ili9341_write('9'); | |
_delay_ms(2); | |
ili9341_write('0'); | |
_delay_ms(2); | |
ili9341_write('.'); | |
_delay_ms(2); | |
ili9341_write('4'); | |
_delay_ms(2); | |
ili9341_write('5'); | |
_delay_ms(2); | |
_delay_ms(2000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment