ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
max7219_8x8led.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
24#include "fw_hal.h"
25
26#define MAX7219_CS P17
27
28#define DECODE_MODE 0x09
29#define INTENSITY 0x0A
30#define SCAN_LIMIT 0x0B
31#define SHUT_DOWN 0x0C
32#define DISPLAY_TEST 0x0F
33
350x00,0x00,0x7C,0xC6,0xC6,0xCE,0xD6,0xD6, // -0-.
360xE6,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00,
370x00,0x00,0x18,0x38,0x78,0x18,0x18,0x18, // -1-
380x18,0x18,0x18,0x7E,0x00,0x00,0x00,0x00,
390x00,0x00,0x7C,0xC6,0x06,0x0C,0x18,0x30, // -2-
400x60,0xC0,0xC6,0xFE,0x00,0x00,0x00,0x00,
410x00,0x00,0x7C,0xC6,0x06,0x06,0x3C,0x06, // -3-
420x06,0x06,0xC6,0x7C,0x00,0x00,0x00,0x00,
430x00,0x00,0x0C,0x1C,0x3C,0x6C,0xCC,0xFE, // -4-
440x0C,0x0C,0x0C,0x1E,0x00,0x00,0x00,0x00,
450x00,0x00,0xFE,0xC0,0xC0,0xC0,0xFC,0x0E, // -5-
460x06,0x06,0xC6,0x7C,0x00,0x00,0x00,0x00,
470x00,0x00,0x38,0x60,0xC0,0xC0,0xFC,0xC6, // -6-
480xC6,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00,
490x00,0x00,0xFE,0xC6,0x06,0x06,0x0C,0x18, // -7-
500x30,0x30,0x30,0x30,0x00,0x00,0x00,0x00,
510x00,0x00,0x7C,0xC6,0xC6,0xC6,0x7C,0xC6, // -8-
520xC6,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00,
530x00,0x00,0x7C,0xC6,0xC6,0xC6,0x7E,0x06, // -9-
540x06,0x06,0x0C,0x78,0x00,0x00,0x00,0x00};
55
57{
58 MAX7219_CS = 0;
61 MAX7219_CS = 1;
62}
63
64void MAX7219_init(void)
65{
66 MAX7219_write(SHUT_DOWN, 0x01); // 0x00:shutdown, 0x01:normal
67 MAX7219_write(DECODE_MODE, 0x00); // Bypass code B decoder, no-decode operation
68 MAX7219_write(SCAN_LIMIT, 0x07); // Scan-limit, 0:1-digit, 1:2-digits, ... 7:8-digits
69 MAX7219_write(INTENSITY, 0x01); // 0x00:min, 0xFF:max
70 MAX7219_write(DISPLAY_TEST, 0x00); // 0x00:normal, 0x01:test mode
71}
72
73void SPI_init(void)
74{
75 // MAX7219 can work with frequency up to 20MHz
77 // Clock idles low
79 // Data transfer is driven by lower SS pin
81 // MSB first
83 // Define the output pins
85 // Ignore SS pin, use MSTR to swith between master/slave mode
87 // Master mode
89 // Start SPI
91}
92
93void main()
94{
95 uint8_t pos = 0, size = sizeof(numbers), i, j;
96
98 // Configure GPIO pins before SPI and device
101 // Configure SPI and device
102 SPI_init();
103 MAX7219_init();
104
105 while(1)
106 {
107 for (i = 0; i < 8; i++)
108 {
109 j = (pos + i) % size;
110 MAX7219_write(i + 1, numbers[j]);
111 }
112 pos = (pos + 1) % size;
113 SYS_Delay(100);
114 }
115}
uint8_t pos
__CODE int8_t dat[20]
@ GPIO_Pin_5
Definition: fw_gpio.h:50
@ GPIO_Pin_3
Definition: fw_gpio.h:48
@ 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_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