ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
max7219_8x8led_stc8g1k08.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
50#include "fw_hal.h"
51
52#define MAX7219_CS P55
53
54#define DECODE_MODE 0x09
55#define INTENSITY 0x0A
56#define SCAN_LIMIT 0x0B
57#define SHUT_DOWN 0x0C
58#define DISPLAY_TEST 0x0F
59
610x00,0x00,0x7C,0xC6,0xC6,0xCE,0xD6,0xD6, // -0-.
620xE6,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00,
630x00,0x00,0x18,0x38,0x78,0x18,0x18,0x18, // -1-
640x18,0x18,0x18,0x7E,0x00,0x00,0x00,0x00,
650x00,0x00,0x7C,0xC6,0x06,0x0C,0x18,0x30, // -2-
660x60,0xC0,0xC6,0xFE,0x00,0x00,0x00,0x00,
670x00,0x00,0x7C,0xC6,0x06,0x06,0x3C,0x06, // -3-
680x06,0x06,0xC6,0x7C,0x00,0x00,0x00,0x00,
690x00,0x00,0x0C,0x1C,0x3C,0x6C,0xCC,0xFE, // -4-
700x0C,0x0C,0x0C,0x1E,0x00,0x00,0x00,0x00,
710x00,0x00,0xFE,0xC0,0xC0,0xC0,0xFC,0x0E, // -5-
720x06,0x06,0xC6,0x7C,0x00,0x00,0x00,0x00,
730x00,0x00,0x38,0x60,0xC0,0xC0,0xFC,0xC6, // -6-
740xC6,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00,
750x00,0x00,0xFE,0xC6,0x06,0x06,0x0C,0x18, // -7-
760x30,0x30,0x30,0x30,0x00,0x00,0x00,0x00,
770x00,0x00,0x7C,0xC6,0xC6,0xC6,0x7C,0xC6, // -8-
780xC6,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00,
790x00,0x00,0x7C,0xC6,0xC6,0xC6,0x7E,0x06, // -9-
800x06,0x06,0x0C,0x78,0x00,0x00,0x00,0x00};
81
83{
84 MAX7219_CS = 0;
87 MAX7219_CS = 1;
88}
89
90void MAX7219_init(void)
91{
92 MAX7219_write(SHUT_DOWN, 0x01); // 0x00:shutdown, 0x01:normal
93 MAX7219_write(DECODE_MODE, 0x00); // Bypass code B decoder, no-decode operation
94 MAX7219_write(SCAN_LIMIT, 0x07); // Scan-limit, 0:1-digit, 1:2-digits, ... 7:8-digits
95 MAX7219_write(INTENSITY, 0x01); // 0x00:min, 0xFF:max
96 MAX7219_write(DISPLAY_TEST, 0x00); // 0x00:normal, 0x01:test mode
97}
98
99void SPI_init(void)
100{
101 // MAX7219 can work with frequency up to 20MHz
103 // Clock idles low
105 // Data transfer is driven by lower SS pin
107 // MSB first
109 // Define the output pins
111 // Ignore SS pin, use MSTR to swith between master/slave mode
113 // Master mode
115 // Start SPI
117}
118
119void main()
120{
121 uint8_t pos = 0, size = sizeof(numbers), i, j;
122
123 SYS_SetClock();
124 // Configure GPIO pins before SPI and device
125 // SCLK(P32), CS(P55)
128 // MOSI(P54)
130 // Configure SPI and device
131 SPI_init();
132 MAX7219_init();
133
134 while(1)
135 {
136 for (i = 0; i < 8; i++)
137 {
138 j = (pos + i) % size;
139 MAX7219_write(i + 1, numbers[j]);
140 }
141 pos = (pos + 1) % size;
142 SYS_Delay(100);
143 }
144}
uint8_t pos
__CODE int8_t dat[20]
#define GPIO_P5_SetMode(__PINS__, __MODE__)
Definition: fw_gpio.h:99
#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_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_4
Definition: fw_spi.h:45
#define SPI_SetEnabled(__STATE__)
Definition: fw_spi.h:69
#define SPI_SetClockPolarity(__STATE__)
Definition: fw_spi.h:78
uint8_t SPI_TxRx(uint8_t dat)
Definition: fw_spi.c:20
#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_P12P54_P13_P14_P15
Definition: fw_spi.h:36
@ 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
uint8_t addr[8]
Definition: main.c:28
#define DECODE_MODE
#define SCAN_LIMIT
#define SHUT_DOWN
#define INTENSITY
#define DISPLAY_TEST
void MAX7219_init(void)
const uint8_t numbers[]
#define MAX7219_CS
void MAX7219_write(uint8_t addr, uint8_t dat)
void main()
void SPI_init(void)
uint8_t __XDATA i