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

Go to the source code of this file.

Macros

#define MAX7219_CS   P17
 
#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 28 of file max7219_8x8led.c.

◆ DISPLAY_TEST

#define DISPLAY_TEST   0x0F

Definition at line 32 of file max7219_8x8led.c.

◆ INTENSITY

#define INTENSITY   0x0A

Definition at line 29 of file max7219_8x8led.c.

◆ MAX7219_CS

#define MAX7219_CS   P17

Demo: MAX7219 8x8 LED Matrix Board: STC8H1K08

P1.3 -> DIN P1.5 -> SCLK P1.7 -> CS

Definition at line 26 of file max7219_8x8led.c.

◆ SCAN_LIMIT

#define SCAN_LIMIT   0x0B

Definition at line 30 of file max7219_8x8led.c.

◆ SHUT_DOWN

#define SHUT_DOWN   0x0C

Definition at line 31 of file max7219_8x8led.c.

Function Documentation

◆ main()

void main ( void  )

Definition at line 93 of file max7219_8x8led.c.

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
@ 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
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 64 of file max7219_8x8led.c.

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}
#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 56 of file max7219_8x8led.c.

57{
58 MAX7219_CS = 0;
61 MAX7219_CS = 1;
62}
__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 73 of file max7219_8x8led.c.

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}
#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 34 of file max7219_8x8led.c.