text: #line 1 "D:/Projects/ATU-10/Firmware/oled_control.c"
  #line 1 "d:/projects/atu-10/firmware/oled_control.h"
  #line 1 "d:/projects/atu-10/firmware/font_5x8.h"
   static const code char font_5x8[] = {
  
  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, 0x55, 0x22, 0x50,
  0x00, 0x05, 0x03, 0x00, 0x00,
  0x00, 0x1C, 0x22, 0x41, 0x00,
  0x00, 0x41, 0x22, 0x1C, 0x00,
  0x08, 0x2A, 0x1C, 0x2A, 0x08,
  0x08, 0x08, 0x3E, 0x08, 0x08,
  0x00, 0x50, 0x30, 0x00, 0x00,
  0x08, 0x08, 0x08, 0x08, 0x08,
  0x00, 0x30, 0x30, 0x00, 0x00,
  0x20, 0x10, 0x08, 0x04, 0x02,
  0x3E, 0x51, 0x49, 0x45, 0x3E,
  0x00, 0x42, 0x7F, 0x40, 0x00,
  0x42, 0x61, 0x51, 0x49, 0x46,
  0x21, 0x41, 0x45, 0x4B, 0x31,
  0x18, 0x14, 0x12, 0x7F, 0x10,
  0x27, 0x45, 0x45, 0x45, 0x39,
  0x3C, 0x4A, 0x49, 0x49, 0x30,
  0x01, 0x71, 0x09, 0x05, 0x03,
  0x36, 0x49, 0x49, 0x49, 0x36,
  0x06, 0x49, 0x49, 0x29, 0x1E,
  0x00, 0x36, 0x36, 0x00, 0x00,
  0x00, 0x56, 0x36, 0x00, 0x00,
  0x00, 0x08, 0x14, 0x22, 0x41,
  0x14, 0x14, 0x14, 0x14, 0x14,
  0x41, 0x22, 0x14, 0x08, 0x00,
  0x02, 0x01, 0x51, 0x09, 0x06,
  0x32, 0x49, 0x79, 0x41, 0x3E,
  0x7E, 0x11, 0x11, 0x11, 0x7E,
  0x7F, 0x49, 0x49, 0x49, 0x36,
  0x3E, 0x41, 0x41, 0x41, 0x22,
  0x7F, 0x41, 0x41, 0x22, 0x1C,
  0x7F, 0x49, 0x49, 0x49, 0x41,
  0x7F, 0x09, 0x09, 0x01, 0x01,
  0x3E, 0x41, 0x41, 0x51, 0x32,
  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, 0x04, 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,
  0x46, 0x49, 0x49, 0x49, 0x31,
  0x01, 0x01, 0x7F, 0x01, 0x01,
  0x3F, 0x40, 0x40, 0x40, 0x3F,
  0x1F, 0x20, 0x40, 0x20, 0x1F,
  0x7F, 0x20, 0x18, 0x20, 0x7F,
  0x63, 0x14, 0x08, 0x14, 0x63,
  0x03, 0x04, 0x78, 0x04, 0x03,
  0x61, 0x51, 0x49, 0x45, 0x43,
  0x00, 0x00, 0x7F, 0x41, 0x41,
  0x02, 0x04, 0x08, 0x10, 0x20,
  0x41, 0x41, 0x7F, 0x00, 0x00,
  0x04, 0x02, 0x01, 0x02, 0x04,
  0x40, 0x40, 0x40, 0x40, 0x40,
  0x00, 0x01, 0x02, 0x04, 0x00,
  0x20, 0x54, 0x54, 0x54, 0x78,
  0x7F, 0x48, 0x44, 0x44, 0x38,
  0x38, 0x44, 0x44, 0x44, 0x20,
  0x38, 0x44, 0x44, 0x48, 0x7F,
  0x38, 0x54, 0x54, 0x54, 0x18,
  0x08, 0x7E, 0x09, 0x01, 0x02,
  0x08, 0x14, 0x54, 0x54, 0x3C,
  0x7F, 0x08, 0x04, 0x04, 0x78,
  0x00, 0x44, 0x7D, 0x40, 0x00,
  0x20, 0x40, 0x44, 0x3D, 0x00,
  0x00, 0x7F, 0x10, 0x28, 0x44,
  0x00, 0x41, 0x7F, 0x40, 0x00,
  0x7C, 0x04, 0x18, 0x04, 0x78,
  0x7C, 0x08, 0x04, 0x04, 0x78,
  0x38, 0x44, 0x44, 0x44, 0x38,
  0x7C, 0x14, 0x14, 0x14, 0x08,
  0x08, 0x14, 0x14, 0x18, 0x7C,
  0x7C, 0x08, 0x04, 0x04, 0x08,
  0x48, 0x54, 0x54, 0x54, 0x20,
  0x04, 0x3F, 0x44, 0x40, 0x20,
  0x3C, 0x40, 0x40, 0x20, 0x7C,
  0x1C, 0x20, 0x40, 0x20, 0x1C,
  0x3C, 0x40, 0x30, 0x40, 0x3C,
  0x44, 0x28, 0x10, 0x28, 0x44,
  0x0C, 0x50, 0x50, 0x50, 0x3C,
  0x44, 0x64, 0x54, 0x4C, 0x44,
  0x00, 0x08, 0x36, 0x41, 0x00,
  0x00, 0x00, 0x7F, 0x00, 0x00,
  0x00, 0x41, 0x36, 0x08, 0x00,
  0x08, 0x08, 0x2A, 0x1C, 0x08,
  0x08, 0x1C, 0x2A, 0x08, 0x08
  };
  #line 3 "d:/projects/atu-10/firmware/oled_control.h"
  static oled_addr = 0x78;
  static char shift_line = 64;
  static char oled_shift = 2;
  static char inversion = 1;
  
  void oled_init (void);
  void oled_clear(void);
  void send_command (char);
  void set_addressing (char, char);
  void oled_wr_str_s(char, char, char*, char);
  void oled_wr_str(char, char, char*, char);
  void oled_bat (void);
  void oled_voltage (int);
  void oled_clear (void);
  
  
  static const char batt[] = {
   0B11111000,
   0B11111000,
  
   0B00011111,
   0B00011111,
   0B00000011,
   0B00000011,
   0B00000011,
   0B00011111,
   0B00011111,
  
   0B11111000,
   0B11111000,
  
   0B11111111,
   0B11111111,
   0B00000000,
   0B00000000,
   0B00000000,
   0B00000000,
   0B00000000,
   0B00000000,
   0B00000000,
   0B11111111,
   0B11111111,
  
   0B11111111,
   0B11111111,
   0B00000000,
   0B00000000,
   0B00000000,
   0B00000000,
   0B00000000,
   0B00000000,
   0B00000000,
   0B11111111,
   0B11111111,
  
   0B11111111,
   0B11111111,
   0B11000000,
   0B11000000,
   0B11000000,
   0B11000000,
   0B11000000,
   0B11000000,
   0B11000000,
   0B11111111,
   0B11111111
   };
  #line 1 "d:/projects/atu-10/firmware/soft_i2c.h"
  
  void Soft_I2C_Init(void);
  void Soft_I2C_Start(void);
  char Soft_I2C_Write(char);
  char Soft_I2C_Read(void);
  void Soft_I2C_ACK(void);
  void Soft_I2C_NACK(void);
  void Soft_I2C_Stop(void);
  #line 4 "D:/Projects/ATU-10/Firmware/oled_control.c"
  void oled_disp_on() {
   send_command(0xAF);
  }
  
  void oled_disp_off() {
   send_command(0xAE);
  }
  
  void oled_init (void) {
   Soft_I2C_Start();
   Soft_I2C_Write(oled_addr);
   Soft_I2C_Write(0);
   Soft_I2C_Write (0xAE);
  
   Soft_I2C_Write (0xD5);
   Soft_I2C_Write (0x80);
  
   Soft_I2C_Write (0xA8);
   Soft_I2C_Write (63);
  
   Soft_I2C_Write (0xD3);
   Soft_I2C_Write (shift_line);
  
   Soft_I2C_Write (0x40);
  
   Soft_I2C_Write (0x8D);
   Soft_I2C_Write (0x14);
  
   Soft_I2C_Write (0x81);
   Soft_I2C_Write (255);
  
   Soft_I2C_Write (0xD9);
   Soft_I2C_Write (0xF1);
  
   Soft_I2C_Write (0x20);
   Soft_I2C_Write (0x02);
  
   Soft_I2C_Write (0x21);
   Soft_I2C_Write (0);
   Soft_I2C_Write (127);
  
   Soft_I2C_Write (0x2E);
  
   if(inversion) {
   Soft_I2C_Write (0xA0);
   Soft_I2C_Write (0xC0);
   }
   else {
   Soft_I2C_Write (0xA1);
   Soft_I2C_Write (0xC8);
   }
  
   Soft_I2C_Write (0xDA);
   Soft_I2C_Write (0x02);
  
   Soft_I2C_Write (0xDB);
   Soft_I2C_Write (0x40);
  
   Soft_I2C_Write (0xA4);
  
   Soft_I2C_Write (0xA6);
  
   Soft_I2C_Stop ();
  
   oled_clear();
   send_command (0xAF);
   return;
  }
  
  void oled_clear(void){
   char i, r;
  
   Soft_I2C_Start();
   Soft_I2C_Write(oled_addr);
   Soft_I2C_Write(64);
  
   for (r = 0; r <=7; r++) {
   set_addressing (r, 0);
   for (i = 0; i < 128; i++, Soft_I2C_Write(0x00));
   }
   Soft_I2C_Stop ();
  
   return;
  }
  
  void send_command (char oled_command) {
   Soft_I2C_Start();
   Soft_I2C_Write(oled_addr);
   Soft_I2C_Write(128);
   Soft_I2C_Write(oled_command);
   Soft_I2C_Stop();
   return;
  }
  
  void set_addressing (char pagenum, char c_start) {
   char a, b, c;
   c = c_start + oled_shift;
   Soft_I2C_Start();
   Soft_I2C_Write(oled_addr);
   Soft_I2C_Write(0);
   Soft_I2C_Write(0xB0 + pagenum);
  
   if (c <= 15) { a = c; b = 0; }
   else { b = c / 16; a = c - b * 16; }
   Soft_I2C_Write (a);
   Soft_I2C_Write (0x10 + b);
  
   Soft_I2C_Start();
   Soft_I2C_Write(oled_addr);
   Soft_I2C_Write(64);
   return;
  }
  
  void oled_wr_str_s(char page, char col, char str[], char len) {
   char i, h, g;
   set_addressing (page, col);
  
   for (i = 0; i < len; i++) {
   g = str[i] - 32;
   for (h = 0; h < 5; h++) {
   Soft_I2C_Write(font_5x8[g*5+h]);
   }
   Soft_I2C_Write (0);
   }
   Soft_I2C_Stop ();
   return;
  }
  
  
  void oled_wr_str (char page, char col, char str[], char leng ) {
   char i, h, g, w1, w2;
   Soft_I2C_Start();
   Soft_I2C_Write(oled_addr);
   Soft_I2C_Write(64);
  
   set_addressing (page, col);
  
   for (i = 0; i < leng; i++) {
   if (str[i] == 0) g = 0; else g = str[i] - 32;
   for (h = 0; h <= 4; h++) {
   w1 = font_5x8[g*5+h];
   if(page != 2) {
   w2.B7 = w1.B3;
   w2.B6 = w1.B3;
   w2.B5 = w1.B2;
   w2.B4 = w1.B2;
   w2.B3 = w1.B1;
   w2.B2 = w1.B1;
   w2.B1 = w1.B0;
   w2.B0 = w1.B0; }
   else {
   w2.B7 = w1.B2;
   w2.B6 = w1.B2;
   w2.B5 = w1.B1;
   w2.B4 = w1.B1;
   w2.B3 = w1.B0;
   w2.B2 = w1.B0;
   w2.B1 = 0;
   w2.B0 = 0;
   }
   Soft_I2C_Write(w2);
   Soft_I2C_Write(w2);
   }
   Soft_I2C_Write (0);
   Soft_I2C_Write (0);
   }
   set_addressing (page+1, col);
  
   for (i = 0; i < leng; i++) {
   if (str[i] == 0) g = 0; else g = str[i] - 32;
   for (h = 0; h <= 4; h++) {
   w1 = font_5x8[g*5+h];
   if(page != 2) {
   w2.B7 = w1.B7;
   w2.B6 = w1.B7;
   w2.B5 = w1.B6;
   w2.B4 = w1.B6;
   w2.B3 = w1.B5;
   w2.B2 = w1.B5;
   w2.B1 = w1.B4;
   w2.B0 = w1.B4; }
   else {
   w2.B7 = w1.B6;
   w2.B6 = w1.B6;
   w2.B5 = w1.B5;
   w2.B4 = w1.B5;
   w2.B3 = w1.B4;
   w2.B2 = w1.B4;
   w2.B1 = w1.B3;
   w2.B0 = w1.B3;
   }
   Soft_I2C_Write(w2);
   Soft_I2C_Write(w2);
   }
   Soft_I2C_Write (0);
   Soft_I2C_Write (0);
   }
   Soft_I2C_Stop ();
  }
  
  
  void oled_bat () {
   char i, g;
   Soft_I2C_Start();
   Soft_I2C_Write(oled_addr);
   Soft_I2C_Write(64);
  
  
   for(g=0; g<=3; g++) {
   set_addressing (g, 115);
   for(i=0; i<=10; i++) { Soft_I2C_Write(batt[g*11+i]); }
   }
   Soft_I2C_Stop ();
   return;
   }
  
  
  void oled_voltage(int Voltage) {
   char i, v, u0, u1, u2, u3, m;
   Soft_I2C_Start();
   Soft_I2C_Write(oled_addr);
   Soft_I2C_Write(64);
  
   Voltage /= 10;
   if(Voltage < 300) Voltage = 300;
   else if(Voltage > 420) Voltage = 420;
   Voltage = Voltage - 300;
   Voltage = Voltage * 32;
   v = Voltage / 120;
  
  
   if(v >= 25) { u0 = v - 24; u1 = 8; u2 = 8; u3 = 8; }
   else if(v >= 17) { u0 = 0; u1 = v - 16; u2 = 8; u3 = 8; }
   else if(v >= 9 ) { u0 = 0; u1 = 0; u2 = v - 8; u3 = 8; }
   else { u0 = 0; u1 = 0; u2 = 0; u3 = v ; }
  
   m = 128;
   m = 255 - (m >> (u0-1)) +1;
   m = m | 0b00000011;
   set_addressing (0, 119);
   Soft_I2C_Write(m);
   Soft_I2C_Write(m);
   Soft_I2C_Write(m);
   m = m | 0b00011111;
   set_addressing (0, 117);
   Soft_I2C_Write(m);
   Soft_I2C_Write(m);
   set_addressing (0, 122);
   Soft_I2C_Write(m);
   Soft_I2C_Write(m);
  
   m = 128;
   m = 255 - (m >> (u1-1)) + 1;
   set_addressing (1, 117);
   for(i=0; i<=6; i++) Soft_I2C_Write(m);
  
   m = 128;
   m = 255 - (m >> (u2-1)) + 1;
   set_addressing (2, 117);
   for(i=0; i<=6; i++) Soft_I2C_Write(m);
  
   m = 128;
   m = 255 - (m >> (u3-1)) +1;
   m = m | 0b11000000;
   set_addressing (3, 117);
   for(i=0; i<=6; i++) Soft_I2C_Write(m);
  
   Soft_I2C_Stop ();
   return;
  }
  