void st7565Init(FONT_DEF_STRUCT * font) { // Note: This can be optimised to set all pins to output and high // in two commands by manipulating the registers directly (assuming // that the pins are located in the same GPIO bank). The code is left // as is for clarity sake in case the pins are not all located in the // same bank. ST7565_CS_DIR = OUTPUT; ST7565_RST_DIR = OUTPUT; ST7565_A0_DIR = OUTPUT; ST7565_SCL_DIR = OUTPUT; ST7565_SDA_DIR = OUTPUT; ST7565_SDA = 1; ST7565_SCL = 1; ST7565_A0 = 1; ST7565_RST = 1; ST7565_CS = 1; // Reset ST7565_CS = 0; ST7565_RST = 0; _delay_ms(500); ST7565_RST = 1; currentFont = font; // Configure Display //CMD(ST7565_CMD_SET_BIAS_7); // LCD Bias Select 0xA3 0xA2 CMD(ST7565_CMD_SET_BIAS_9); // LCD Bias Select 0xA3 0xA2 CMD(ST7565_CMD_SET_ADC_NORMAL); // ADC Select 0xA0 0xA6 CMD(ST7565_CMD_SET_COM_NORMAL); // SHL Select 0xC0 0xc8 //CMD(ST7565_CMD_SET_COM_REVERSE); // SHL Select 0xC0 0xc8 CMD(ST7565_CMD_SET_DISP_START_LINE); // Initial Display Line 0x40 0x40 CMD(ST7565_CMD_SET_POWER_CONTROL | 0x04); // Turn on voltage converter (VC=1, VR=0, VF=0) 0x28 0x24 _delay_ms(50); // Wait 50mS CMD(ST7565_CMD_SET_POWER_CONTROL | 0x06); // Turn on voltage regulator (VC=1, VR=1, VF=0) _delay_ms(50); // Wait 50mS CMD(ST7565_CMD_SET_POWER_CONTROL | 0x07); // Turn on voltage follower _delay_ms(10); // Wait 10mS CMD(ST7565_CMD_SET_RESISTOR_RATIO | 0x6); // Set LCD operating voltage // Turn display on CMD(ST7565_CMD_DISPLAY_ON); // 0xAF CMD(ST7565_CMD_SET_ALLPTS_NORMAL); // 0xA4 st7565SetBrightness(0x11); // 0x18 }
int main() { int i, last_led_update = 0; initWiring(); st7565Init(Font5x7); st7565ClearScreen(); st7565SetBrightness(12); st7565DrawString(1, 5, "Test"); for(i = 0; i < 100; i++) { st7565DrawPixel(1+i,14); } st7565Refresh(); #if KKVER == 21 Fastwire::setup(100, true); MPU6050 mpu; mpu.initialize(); #endif DDRB &= _BV(LED_PIN); // Set pin 3 of port B to output (LED pin) for(;;) { char buff[512]; if(millis() - last_led_update > 1000) { PORTB ^= _BV(LED_PIN); last_led_update = millis(); } st7565ClearScreen(); #if KKVER == 21 if(mpu.testConnection()) { st7565DrawString(1,20, "Connected"); } else { st7565DrawString(1,20, "Not connected"); } sprintf(buff, "acc_x = %d\n", mpu.getAccelerationX()); st7565DrawString(1,30, buff); #else st7565DrawString(1,20, "No ACC available"); #endif st7565Refresh(); delay(50); } return 0; }