12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- #include "lcd-twi.h"
- const char symbols[8][8] = {{ 0x00, 0x0E, 0x1F, 0x1F, 0x1F, 0x0E, 0x00, 0x00 }, /* 0 Circle */
- { 0x08, 0x14, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* 1 DEGREE */
- { 0x00, 0x04, 0x0A, 0x11, 0x11, 0x11, 0x11, 0x11 }, /* 2 THERMOCOUPLE */
- { 0x04, 0x04, 0x1F, 0x04, 0x0A, 0x11, 0x1F, 0x04 }, /* 3 DIODE */
- { 0x04, 0x0E, 0x0A, 0x0A, 0x0A, 0x0A, 0x0E, 0x04 }, /* 4 RESISTOR */
- { 0x03, 0x0A, 0x08, 0x0B, 0x0A, 0x08, 0x1B, 0x02 }, /* 5 MOSFET */
- { 0x08, 0x08, 0x04, 0x02, 0x01, 0x08, 0x08, 0x08 }, /* 6 OPEN */
- { 0x08, 0x08, 0x04, 0x04, 0x02, 0x0F, 0x0A, 0x08 }};/* 7 SHORT */
-
- void I2C_SendByte(uint8_t byte)
- {
- cli();
- TWCR |= (1 << TWINT) | (1 << TWSTA);
- while(!(TWCR & (1 << TWINT)));
- TWDR = LCDI2CADDR;
- TWCR &= ~(1 << TWSTA);
- TWCR |= (1 << TWINT);
- while(!(TWCR & (1 << TWINT)));
- TWDR = byte;
- TWCR |= (1 << TWINT);
- while(!(TWCR & (1 << TWINT)));
- TWCR |= (1 << TWINT) | (1 << TWSTO);
- sei();
- }
- void LCD_SendData(uint8_t data)
- {
- I2C_SendByte((data & 0xF0) | LCD_RS | LCD_E);
- I2C_SendByte((data & 0xF0) | LCD_RS);
- I2C_SendByte((data << 4) | LCD_RS | LCD_E);
- I2C_SendByte((data << 4) | LCD_RS);
- _delay_us(4);
- }
- void LCD_SendCmd(uint8_t cmd)
- {
- I2C_SendByte(((cmd & 0xF0) & ~LCD_RS) | LCD_E);
- I2C_SendByte((cmd & 0xF0) & ~LCD_RS);
- I2C_SendByte(((cmd << 4) & ~LCD_RS) | LCD_E);
- I2C_SendByte((cmd << 4) & ~LCD_RS);
- if(cmd == LCD_CLR)
- {
- _delay_ms(6);
- }
- else
- {
- _delay_us(10);
- }
- }
- void LCD_SetPos(uint8_t x, uint8_t y)
- {
- y = ((y & 0x01) * 0x40);
- x &= 0x0F;
- LCD_SendCmd(LCD_DDRAM | (x + y));
- }
- void LoadSymbols()
- {
- for(uint8_t i = 0; i < 8; i++)
- {
- LCD_SendCmd(LCD_CGRAM | (0x08 * i));
- for(uint8_t j = 0; j < 8; j++)
- {
- LCD_SendData(symbols[i][j]);
- }
- }
- }
- void LCD_Init(void)
- {
- I2C_SendByte(0x00);
- _delay_ms(50);
- for(uint8_t i = 0; i < 5; i++)
- {
- I2C_SendByte(0x00 | LCD_E);
- I2C_SendByte(0x00 & ~LCD_E);
- }
- _delay_us(50);
-
- I2C_SendByte(LCD_WIDTH | LCD_E);
- I2C_SendByte(LCD_WIDTH & ~LCD_E);
- LCD_SendCmd(LCD_WIDTH | LCD_WIDTH_N | LCD_WIDTH_FT1);
- LCD_SendCmd(LCD_ONOFF);
- LCD_SendCmd(LCD_CLR);
- LCD_SendCmd(LCD_DIR | LCD_DIR_ID);
- LCD_SendCmd(LCD_ONOFF | LCD_ONOFF_D);
- LoadSymbols();
- }
|