ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
st7567_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: ST7567 12864 LCD
17 * Board: STC8H3K32
18 *
19 * P37 -> RES, RESET 7 - 18
20 * P36 -> DC, A0 8 - 17
21 * P35 -> CSB, Chip Select 6 - 16
22 * P32 -> SCK, SCL, CLK, Clock 9 - 13
23 * P12 -> LED-A, Backlight 3 - 19
24 * P34 -> MOSI, SDA 10 - 15
25 * GND -> GND
26 * 3.3V -> VCC
27 */
28
29#include "fw_hal.h"
30#include "st7567.h"
31
32
33void SPI_Init(void)
34{
35 // ST7567 doesn't work if SPI frequency is too high
37 // Clock is low when idle
39 // Data transfer is driven by lower SS pin
41 // MSB first
43 // Define the output pins
45 // Ignore SS pin, use MSTR to swith between master/slave mode
47 // Master mode
49 // Start SPI
51}
52
53void GPIO_Init(void)
54{
55 // Configure GPIO pins before SPI and device
56 // DIN(P34)
58 // SCLK(P32)
61}
62
63int main(void)
64{
65 int y1, y2;
66 uint8_t d1, d2;
67
69 GPIO_Init();
70 SPI_Init();
72
73 while(1)
74 {
75 ST7567_DrawLine(0, 0, 127, 0, 1);
76 ST7567_DrawLine(0, 0, 0, 63, 1);
77 ST7567_DrawLine(127, 0, 127, 63, 1);
78 ST7567_DrawLine(0, 63, 127, 63, 1);
79
80 ST7567_GotoXY(3, 5);
81 ST7567_Puts("LCD:ST7567", &Font_5x7, 1);
82 ST7567_GotoXY(3, 13);
83 ST7567_Puts("STC8 FwLib Demo", &Font_5x7, 1);
84 ST7567_GotoXY(3, 21);
85 ST7567_Puts("It's a demo of ST7567 12864 LCD", &Font_3x5, 1);
86 ST7567_GotoXY(3, 27);
87 ST7567_Puts("Font size 3x5, nums:01234567890", &Font_3x5, 1);
88 ST7567_GotoXY(5, 52);
89 ST7567_Puts("Font size: 5x7", &Font_5x7, 1);
91 SYS_Delay(2000);
92
93 y1 = 10;
94 while (y1 <= 0x30)
95 {
97 SYS_Delay(100);
98 }
99 while (y1 >= 10)
100 {
101 ST7567_SetContrast(y1--);
102 SYS_Delay(100);
103 }
104 while (y1 <= 0x20)
105 {
106 ST7567_SetContrast(y1++);
107 SYS_Delay(100);
108 }
109 SYS_Delay(2000);
110
113 SYS_Delay(2000);
114
117 SYS_Delay(2000);
118
119 ST7567_Fill(0);
120 y1 = 64, y2 = 0;
121 while (y1 > 0)
122 {
123 ST7567_DrawLine(0, y1, 127, y2, 1);
125 y1 -= 2;
126 y2 += 2;
127 SYS_Delay(100);
128 }
129 SYS_Delay(1000);
130
131 ST7567_Fill(0);
132 y1 = 127, y2 = 0;
133 while (y1 > 0)
134 {
135 ST7567_DrawLine(y1, 0, y2, 63, 1);
137 y1 -= 2;
138 y2 += 2;
139 SYS_Delay(100);
140 }
141 SYS_Delay(1000);
142
143 ST7567_Fill(0);
145 SYS_Delay(2000);
146 }
147}
#define GPIO_P3_SetMode(__PINS__, __MODE__)
Definition: fw_gpio.h:89
@ GPIO_Pin_5
Definition: fw_gpio.h:50
@ GPIO_Pin_2
Definition: fw_gpio.h:47
@ GPIO_Pin_4
Definition: fw_gpio.h:49
@ GPIO_Pin_6
Definition: fw_gpio.h:51
@ GPIO_Pin_7
Definition: fw_gpio.h:52
#define GPIO_P1_SetMode(__PINS__, __MODE__)
Definition: fw_gpio.h:79
@ GPIO_Mode_Output_PP
Definition: fw_gpio.h:24
@ GPIO_Mode_InOut_QBD
Definition: fw_gpio.h:23
#define SPI_SetClockPrescaler(__PRE_SCALER__)
Definition: fw_spi.h:88
#define SPI_SetPort(__ALTER_PORT__)
Definition: fw_spi.h:92
#define SPI_SetDataOrder(__ORDER__)
Definition: fw_spi.h:70
@ SPI_ClockPreScaler_16
Definition: fw_spi.h:47
#define SPI_SetEnabled(__STATE__)
Definition: fw_spi.h:69
#define SPI_SetClockPolarity(__STATE__)
Definition: fw_spi.h:78
#define SPI_SetClockPhase(__PHASE__)
Definition: fw_spi.h:84
@ SPI_ClockPhase_LeadingEdge
Definition: fw_spi.h:53
#define SPI_IgnoreSlaveSelect(__STATE__)
Definition: fw_spi.h:68
#define SPI_SetMasterMode(__STATE__)
Definition: fw_spi.h:71
@ SPI_AlterPort_P35_P34_P33_P32
Definition: fw_spi.h:39
@ SPI_DataOrder_MSB
Definition: fw_spi.h:59
void SYS_SetClock(void)
Definition: fw_sys.c:40
void SYS_Delay(uint16_t t)
Definition: fw_sys.c:65
@ HAL_State_OFF
Definition: fw_types.h:70
@ HAL_State_ON
Definition: fw_types.h:71
unsigned char uint8_t
Definition: fw_types.h:18
__CODE FontDef_t Font_5x7
Definition: pcd8544.c:548
__CODE FontDef_t Font_3x5
Definition: pcd8544.c:547
void ST7567_SetContrast(uint8_t val)
Turn ST7567 LCD backlight off.
Definition: st7567.c:126
void ST7567_GotoXY(uint16_t x, uint16_t y)
Sets cursor pointer to desired location for strings.
Definition: st7567.c:183
void ST7567_Fill(uint8_t color)
Fills entire LCD with specified color.
Definition: st7567.c:158
void ST7567_DrawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_t c)
Draws line on LCD.
Definition: st7567.c:257
void ST7567_ToggleInvert(void)
Toggles pixels invertion inside internal RAM.
Definition: st7567.c:144
char ST7567_Puts(char *str, FontDef_t *Font, uint8_t color)
Puts string to internal RAM.
Definition: st7567.c:237
void ST7567_Init(void)
Initializes ST7567 LCD.
Definition: st7567.c:68
void ST7567_UpdateScreen(void)
Update LCD display with buffer changes.
Definition: st7567.c:132
void SPI_Init(void)
int main(void)
void GPIO_Init(void)