ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
ssd1306_stc8h3k.c
Go to the documentation of this file.
1// Copyright 2021 IOsetting <iosetting(at)outlook.com>
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/***
16 * Demo: SSD1306/SSD1315 12864 OLED
17 * Board: STC8H3K32
18 *
19 * P32 -> SCL
20 * P33 -> SDA
21 * GND -> GND
22 * 3.3V -> VCC
23 */
24
25#include "fw_hal.h"
26#include "ssd1306.h"
27
28void I2C_Init(void)
29{
30 // Master mode
37 // Switch alternative port
39 // Start I2C
41}
42
43void GPIO_Init(void)
44{
45 // SDA
47 // SCL
49}
50
51int main(void)
52{
53 int y1, y2;
54 uint8_t d1, d2;
55
57 GPIO_Init();
58 I2C_Init();
60
61 while(1)
62 {
63 SSD1306_DrawLine(0, 0, 127, 0, 1);
64 SSD1306_DrawLine(0, 0, 0, 63, 1);
65 SSD1306_DrawLine(127, 0, 127, 63, 1);
66 SSD1306_DrawLine(0, 63, 127, 63, 1);
67 SSD1306_UpdateScreen(); // display
68 SYS_Delay(1000);
69
70 SSD1306_Fill(0);
71
72 SSD1306_ToggleInvert(); // Invert display
74 SYS_Delay(1000);
75
76 SSD1306_ToggleInvert(); // Invert display
78 SYS_Delay(1000);
79
80 y1 = 64, y2 = 0;
81 while (y1 > 0)
82 {
83 SSD1306_DrawLine(0, y1, 127, y2, 1);
85 y1 -= 2;
86 y2 += 2;
87 }
88 SYS_Delay(1000);
89
90 SSD1306_Fill(0);
91 y1 = 127, y2 = 0;
92 while (y1 > 0)
93 {
94 SSD1306_DrawLine(y1, 0, y2, 63, 1);
96 y1 -= 2;
97 y2 += 2;
98 }
99 SYS_Delay(1000);
100 }
101}
#define GPIO_P3_SetMode(__PINS__, __MODE__)
Definition: fw_gpio.h:89
@ GPIO_Pin_2
Definition: fw_gpio.h:47
@ GPIO_Pin_3
Definition: fw_gpio.h:48
@ GPIO_Mode_Output_PP
Definition: fw_gpio.h:24
@ GPIO_Mode_InOut_QBD
Definition: fw_gpio.h:23
#define I2C_SetClockPrescaler(__DIV__)
Definition: fw_i2c.h:71
@ I2C_WorkMode_Master
Definition: fw_i2c.h:24
#define I2C_SetWorkMode(__MODE__)
Definition: fw_i2c.h:65
#define I2C_SetEnabled(__STATE__)
Definition: fw_i2c.h:64
@ I2C_AlterPort_P32_P33
Definition: fw_i2c.h:51
#define I2C_SetPort(__ALTER_PORT__)
Definition: fw_i2c.h:121
void SYS_SetClock(void)
Definition: fw_sys.c:40
void SYS_Delay(uint16_t t)
Definition: fw_sys.c:65
@ HAL_State_ON
Definition: fw_types.h:71
unsigned char uint8_t
Definition: fw_types.h:18
void SSD1306_Fill(uint8_t color)
Fills entire LCD with desired color.
Definition: ssd1306.c:181
void SSD1306_ToggleInvert(void)
Toggles pixels invertion inside internal RAM.
Definition: ssd1306.c:167
void SSD1306_Init(void)
Definition: ssd1306.c:44
void SSD1306_UpdateScreen(void)
Updates buffer from internal RAM to LCD.
Definition: ssd1306.c:162
void SSD1306_DrawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_t c)
Draws line on LCD.
Definition: ssd1306.c:223
int main(void)
void I2C_Init(void)
void GPIO_Init(void)