ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
max7219_8x8led_stc8g1k08.c File Reference
#include "fw_hal.h"

Go to the source code of this file.

Macros

#define MAX7219_CS   P55
 
#define DECODE_MODE   0x09
 
#define INTENSITY   0x0A
 
#define SCAN_LIMIT   0x0B
 
#define SHUT_DOWN   0x0C
 
#define DISPLAY_TEST   0x0F
 

Functions

void MAX7219_write (uint8_t addr, uint8_t dat)
 
void MAX7219_init (void)
 
void SPI_init (void)
 
void main ()
 

Variables

const uint8_t numbers []
 

Macro Definition Documentation

◆ DECODE_MODE

#define DECODE_MODE   0x09

Definition at line 54 of file max7219_8x8led_stc8g1k08.c.

◆ DISPLAY_TEST

#define DISPLAY_TEST   0x0F

Definition at line 58 of file max7219_8x8led_stc8g1k08.c.

◆ INTENSITY

#define INTENSITY   0x0A

Definition at line 55 of file max7219_8x8led_stc8g1k08.c.

◆ MAX7219_CS

#define MAX7219_CS   P55

Demo: MAX7219 8x8 LED Matrix Board: STC8G1K08, STC8G1K08A

P5.4 -> DIN P3.2 -> SCLK P5.5 -> CS

PlatformIO configuration example

[env:stc8g1k08] platform = intel_mcs51 board = stc8g1k08 build_flags = -D__CONF_FOSC=36864000UL -D__CONF_MCU_MODEL=MCU_MODEL_STC8G1K08 -D__CONF_CLKDIV=0x00 -D__CONF_IRCBAND=0x01 -D__CONF_VRTRIM=0x20 -D__CONF_IRTRIM=0xA3 -D__CONF_LIRTRIM=0x03 upload_protocol = custom upload_port = /dev/ttyUSB0 upload_speed = 115200 upload_flags = -p$UPLOAD_PORT -s$UPLOAD_SPEED -e upload_command = ${platformio.packages_dir}/tool-stc8prog/stc8prog $UPLOAD_FLAGS -f $SOURCE

Definition at line 52 of file max7219_8x8led_stc8g1k08.c.

◆ SCAN_LIMIT

#define SCAN_LIMIT   0x0B

Definition at line 56 of file max7219_8x8led_stc8g1k08.c.

◆ SHUT_DOWN

#define SHUT_DOWN   0x0C

Definition at line 57 of file max7219_8x8led_stc8g1k08.c.

Function Documentation

◆ main()

void main ( void  )

Definition at line 119 of file max7219_8x8led_stc8g1k08.c.

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
#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
void SYS_SetClock(void)
Definition: fw_sys.c:40
void SYS_Delay(uint16_t t)
Definition: fw_sys.c:65
unsigned char uint8_t
Definition: fw_types.h:18
void MAX7219_init(void)
const uint8_t numbers[]
void MAX7219_write(uint8_t addr, uint8_t dat)
void SPI_init(void)
uint8_t __XDATA i

◆ MAX7219_init()

void MAX7219_init ( void  )

Definition at line 90 of file max7219_8x8led_stc8g1k08.c.

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}
#define DECODE_MODE
#define SCAN_LIMIT
#define SHUT_DOWN
#define INTENSITY
#define DISPLAY_TEST

◆ MAX7219_write()

void MAX7219_write ( uint8_t  addr,
uint8_t  dat 
)

Definition at line 82 of file max7219_8x8led_stc8g1k08.c.

83{
84 MAX7219_CS = 0;
87 MAX7219_CS = 1;
88}
__CODE int8_t dat[20]
uint8_t SPI_TxRx(uint8_t dat)
Definition: fw_spi.c:20
uint8_t addr[8]
Definition: main.c:28
#define MAX7219_CS

◆ SPI_init()

void SPI_init ( void  )

Definition at line 99 of file max7219_8x8led_stc8g1k08.c.

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}
#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
#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
@ HAL_State_OFF
Definition: fw_types.h:70
@ HAL_State_ON
Definition: fw_types.h:71

Variable Documentation

◆ numbers

const uint8_t numbers[]
Initial value:
={
0x00,0x00,0x7C,0xC6,0xC6,0xCE,0xD6,0xD6,
0xE6,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x18,0x38,0x78,0x18,0x18,0x18,
0x18,0x18,0x18,0x7E,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0xC6,0x06,0x0C,0x18,0x30,
0x60,0xC0,0xC6,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0xC6,0x06,0x06,0x3C,0x06,
0x06,0x06,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x0C,0x1C,0x3C,0x6C,0xCC,0xFE,
0x0C,0x0C,0x0C,0x1E,0x00,0x00,0x00,0x00,
0x00,0x00,0xFE,0xC0,0xC0,0xC0,0xFC,0x0E,
0x06,0x06,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x38,0x60,0xC0,0xC0,0xFC,0xC6,
0xC6,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0xFE,0xC6,0x06,0x06,0x0C,0x18,
0x30,0x30,0x30,0x30,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0xC6,0xC6,0xC6,0x7C,0xC6,
0xC6,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0xC6,0xC6,0xC6,0x7E,0x06,
0x06,0x06,0x0C,0x78,0x00,0x00,0x00,0x00}

Definition at line 60 of file max7219_8x8led_stc8g1k08.c.