| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- /**
- * @file OLED_SSD1306_ATY.h
- *
- * @param Project DEVICE_GENERAL_ATY_LIB
- *
- * @author ATY
- *
- * @copyright
- * - Copyright 2017 - 2023 MZ-ATY
- * - This code follows:
- * - MZ-ATY Various Contents Joint Statement -
- * <a href="https://mengze.top/MZ-ATY_VCJS">
- * https://mengze.top/MZ-ATY_VCJS</a>
- * - CC 4.0 BY-NC-SA -
- * <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
- * https://creativecommons.org/licenses/by-nc-sa/4.0/</a>
- * - Your use will be deemed to have accepted the terms of this statement.
- *
- * @brief Base functions of GP22 for all embedded device
- *
- * @version
- * - 1_01_220901 > ATY
- * -# Preliminary version, first Release
- ********************************************************************************
- */
- #ifndef __OLED_SSD1306_ATY_C
- #define __OLED_SSD1306_ATY_C
- #include "OLED_SSD1306_ATY.h"
- void OLED_WriteData(uint8_t oledData)
- {
- I2C_Start();
- I2C_WriteByte(0x78); //Slave address,SA0=0
- I2C_WriteByte(0x40);
- I2C_WriteByte(oledData);
- I2C_Stop();
- }
- void OLED_WriteCmd(uint8_t oledCmd)
- {
- I2C_Start();
- I2C_WriteByte(0x78); //Slave address,SA0=0
- I2C_WriteByte(0x00);
- I2C_WriteByte(oledCmd);
- I2C_Stop();
- }
- void OLED_SetPos(uint8_t x, uint8_t y)
- {
- OLED_WriteCmd(0xb0 + y);
- OLED_WriteCmd(((x & 0xf0) >> 4) | 0x10);
- OLED_WriteCmd((x & 0x0f) | 0x01);
- }
- void OLED_FillScreen(uint8_t fillData)
- {
- uint8_t y, x;
- for(y = 0; y < 8; y++)
- {
- OLED_WriteCmd(0xb0 + y);
- OLED_WriteCmd(0x01);
- OLED_WriteCmd(0x10);
- for(x = 0; x < X_WIDTH; x++)
- OLED_WriteData(fillData);
- }
- }
- void OLED_Init(void)
- {
- // uint16_t i = 0;
- // for(i = 0; i < 5000; i++){}
- // DelayNms(50);
- // OLED_WriteCmd(0xae); // Turn off oled panel
- // OLED_WriteCmd(0x00); // Set low column address
- // OLED_WriteCmd(0x10); // Set high column address
- // OLED_WriteCmd(0x40); // Set start line address, Set Mapping RAM Display Start Line (0x00~0x3F)
- // OLED_WriteCmd(0x81); // Set contrast control register
- // OLED_WriteCmd(BRIGHTNESS); // Set SEG Output Current Brightness
- // OLED_WriteCmd(0xa1); // Set SEG/Column Mapping, 0xa0 reverse x, 0xa1 normal x
- // OLED_WriteCmd(0xc8); // Set COM/Row Scan Direction, 0xc0 reverse y, 0xc8 normal y
- // OLED_WriteCmd(0xa6); // Set normal display
- // OLED_WriteCmd(0xa8); // Set multiplex ratio(1 to 64)
- // OLED_WriteCmd(0x3f); // 1/64 duty
- // OLED_WriteCmd(0xd3); // Set display offset Shift Mapping RAM Counter (0x00~0x3F)
- // OLED_WriteCmd(0x00); // Not offset
- // OLED_WriteCmd(0xd5); // Set display clock divide ratio/oscillator frequency
- // OLED_WriteCmd(0x80); // Set divide ratio, Set Clock as 100 Frames/Sec
- // OLED_WriteCmd(0xd9); // Set pre-charge period
- // OLED_WriteCmd(0xf1); // Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
- // OLED_WriteCmd(0xda); // Set com pins hardware configuration
- // OLED_WriteCmd(0x12);
- // OLED_WriteCmd(0xdb); // Set vcomh
- // OLED_WriteCmd(0x40); // Set VCOM Deselect Level
- // OLED_WriteCmd(0x20); // Set Page Addressing Mode (0x00/0x01/0x02)
- // OLED_WriteCmd(0x02); //
- // OLED_WriteCmd(0x8d); // Set Charge Pump enable/disable
- // OLED_WriteCmd(0x14); // Set(0x10) disable
- // OLED_WriteCmd(0xa4); // Disable Entire Display On (0xa4/0xa5)
- // OLED_WriteCmd(0xa6); // Disable Inverse Display On (0xa6/a7)
- // OLED_WriteCmd(0xaf); // Turn on oled panel
- // OLED_FillScreen(0x00); // Clear screen
- // OLED_SetPos(0, 0); // Reset origin
- // 0.91
- OLED_WriteCmd(0xAE);
- OLED_WriteCmd(0x20);
- OLED_WriteCmd(0x00);
- OLED_WriteCmd(0xb0);
- OLED_WriteCmd(0xc8);
- OLED_WriteCmd(0x00);
- OLED_WriteCmd(0x10);
- OLED_WriteCmd(0x40);
- OLED_WriteCmd(0x81);
- OLED_WriteCmd(0xdf);
- OLED_WriteCmd(0xa1);
- OLED_WriteCmd(0xa6);
- OLED_WriteCmd(0xa8);
- OLED_WriteCmd(0x1F);
- OLED_WriteCmd(0xa4);
- OLED_WriteCmd(0xd3);
- OLED_WriteCmd(0x00);
- OLED_WriteCmd(0xd5);
- OLED_WriteCmd(0xf0);
- OLED_WriteCmd(0xd9);
- OLED_WriteCmd(0x22);
- OLED_WriteCmd(0xda);
- OLED_WriteCmd(0x12);
- OLED_WriteCmd(0xdb);
- OLED_WriteCmd(0x20);
- OLED_WriteCmd(0x8d);
- OLED_WriteCmd(0x14);
- OLED_WriteCmd(0xDA);
- OLED_WriteCmd(0x02);
- OLED_WriteCmd(0xaf);
- OLED_FillScreen(0x00); // Clear screen
- OLED_SetPos(0, 0); // Reset origin
- }
- void OLED_DrawChar8x16(uint8_t x, uint8_t y, uint8_t symbol[])
- {
- uint8_t i = 0;
- if(x > 120) // If x large than max width, then move to next line begining
- {
- x = 0;
- y += 2;
- }
- OLED_SetPos(x, y);
- for(i = 0; i < 8; i++)
- {
- OLED_WriteData(symbol[i]);
- }
- OLED_SetPos(x, y + 1);
- for(i = 0; i < 8; i++)
- {
- OLED_WriteData(symbol[i + 8]);
- }
- }
- void OLED_DrawChar16x16(uint8_t x, uint8_t y, uint8_t symbol[])
- {
- uint8_t i = 0;
- if(x > 120) // If x large than max width, then move to next line begining
- {
- x = 0;
- y += 2;
- }
- OLED_SetPos(x, y);
- for(i = 0; i < 16; i++)
- {
- OLED_WriteData(symbol[i]);
- }
- OLED_SetPos(x, y + 1);
- for(i = 0; i < 16; i++)
- {
- OLED_WriteData(symbol[i + 16]);
- }
- }
- // void OLED_DrawString8x16(uint8_t x, uint8_t y, uint8_t* str, uint8_t len, uint8_t* font)
- // {
- // uint8_t i = 0;
- // for(i = 0; i < len; i++)
- // {
- // if(x > 120)
- // {
- // x = 0;
- // y += 2;
- // }
- // if(y > 6)
- // break;
- // OLED_DrawChar8x16(x, y, font + ((str[i] - 32) * 16));
- // x += 8;
- // }
- // }
- uint8_t NumToChar(uint8_t num)
- {
- if(num >= 0 && num <= 9)
- return num + 32 + 16;
- return num; // Not a number between 0-9
- }
- void OLED_DisNumber(uint8_t x, uint8_t y, uint8_t disData)
- {
- OLED_SetPos(x, y);
- OLED_DrawChar8x16(x, y, FontSongTi8x16 + ((NumToChar(disData) - 32) * 16));
- }
- void OLED_DisValue(uint8_t x, uint8_t y, uint8_t* disData, uint8_t disLength)
- {
- uint8_t i = 0;
- for(i = 0; i < disLength; i++)
- {
- OLED_SetPos(x, y);
- OLED_DrawChar8x16(x, y, FontSongTi8x16 + ((NumToChar(disData[i]) - 32) * 16));
- x += 8;
- }
- }
- void OLED_Dis_Welcom(void)
- {
- uint8_t beginX = 28, beginY = 2;
- OLED_DrawString8x16(0, 0, "I. Astrol", FontSongTi8x16);
- // OLED_DrawString8x16(0, 16, "HT", 2, FontSongTi8x16);
- }
- #endif /* __OLED_SSD1306_ATY_C */
|