/* * Before, sysTick must be initialized. * It use delay_ms function! */ void LCD5110_Initialize() { LCD5110_GPIO_Config(); delay_ms(10); LCD5110_RST(0); //LCD_RST = 0; delay_ms(1); LCD5110_RST(1); //LCD_RST = 1; LCD5110_CS(0); //SPI_CS = 0; delay_ms(1); LCD5110_CS(1); //SPI_CS = 1; delay_ms(1); #define LCD5110_BIAS_1x24 0x15 #define LCD5110_BIAS_1x40_1x34 0x14 #define LCD5110_BIAS_1x100 0x10 //n=7 1:100 #define LCD5110_BIAS_1x80 0x11 //n=6 1:80 #define LCD5110_BIAS_1x65 0x12 //n=5 1:65/1:65 #define LCD5110_BIAS_1x48 0x13 //n=4 1:48 #define LCD5110_BIAS_1x40_1x34 0x14 //n=3 1:40/1:34 #define LCD5110_BIAS_1x24 0x15 //n=2 1:24 #define LCD5110_BIAS_1x18_1x16 0x16 //n=1 1:18/1:16 #define LCD5110_BIAS_1x10_1x9_1x8 0x17 //n=0 1:10/1:9/1:8 //Must be adjusted to the temperature of ambient. #define LCD5110_TEMPERATURE_COEFFICIENT0 0x04 #define LCD5110_TEMPERATURE_COEFFICIENT1 0x05 #define LCD5110_TEMPERATURE_COEFFICIENT2 0x06 #define LCD5110_TEMPERATURE_COEFFICIENT3 0x07 #define LCD5110_CommandSet_Extended 0x21 //H = 1 #define LCD5110_CommandSet_Basic 0x20 //H = 0 #define LCD5110_NormalMode 0x0C //H = 0 LCD5110_LCD_write_byte(LCD5110_CommandSet_Extended, 0); LCD5110_LCD_write_byte(0xC0, 0);//Value of Vop(controls contrast) = (0x80 | 7-bit Vop value ) LCD5110_LCD_write_byte(LCD5110_TEMPERATURE_COEFFICIENT2, 0); LCD5110_LCD_write_byte(LCD5110_BIAS_1x40_1x34, 0); LCD5110_LCD_write_byte(LCD5110_CommandSet_Basic, 0); LCD5110_Clear(); //Clear LCD LCD5110_LCD_write_byte(LCD5110_NormalMode, 0); //enable normal display (dark on light), horizontal addressing LCD5110_CS(0); //SPI_CS = 0; }
static void LCD5110_LCD_write_byte(uint8_t dat, uint8_t command) { uint8_t i; LCD5110_CS(0); //SPI_CS = 0; delay_us(20); if (command == 0) LCD5110_DC(0); //LCD_DC = 0; else LCD5110_DC(1); //LCD_DC = 1; - write data to RAM delay_us(20); for (i = 0; i < 8; i++) { LCD5110_MO(dat & 0x80); //SPI_MO = dat & 0x80; dat = dat << 1; LCD5110_SCK(0); //SPI_SCK = 0; delay_us(1); LCD5110_SCK(1); //SPI_SCK = 1; delay_us(1); } LCD5110_CS(1); //SPI_CS = 1; }
void LCD5110_LCD_write_byte(unsigned char dat,unsigned char mode) { unsigned char i; LCD5110_CS(0);//SPI_CS = 0; if (0 == mode) LCD5110_DC(0);//LCD_DC = 0; else LCD5110_DC(1);//LCD_DC = 1; for(i=0;i<8;i++) { LCD5110_MO(dat & 0x80);//SPI_MO = dat & 0x80; dat = dat<<1; LCD5110_SCK(0);//SPI_SCK = 0; LCD5110_SCK(1);//SPI_SCK = 1; } LCD5110_CS(1);//SPI_CS = 1; }
void LCD5110_init() { LCD5110_GPIO_Config(); LCD5110_DC(1);//LCD_DC = 1; LCD5110_MO(1);//SPI_MO = 1; LCD5110_SCK(1);//SPI_SCK = 1; LCD5110_CS(1);//SPI_CS = 1; LCD5110_LCD_delay_ms(70); LCD5110_LCD_write_byte(0x21,0); //21 LCD5110_LCD_write_byte(0xC2,0); //C2 LCD5110_LCD_write_byte(0x06,0); //06 LCD5110_LCD_write_byte(0x13,0); //13 LCD5110_LCD_write_byte(0x20,0); //20 LCD5110_clear(); LCD5110_LCD_write_byte(0x0C,0); // 0X0D positive }