共阳数码管是指将所有发光二极管的阳极接到一起,形成公共阳极(COM)的数码管,共阳数码管在应用的时候,应该将 COM 端口接到正极,当某一段发光二极管的阴极为低电平的时候,相对应的段就点亮,当某一字段的阴极为高电平的时候,相对应段就不亮。
74HC595 是一款 8 位 CMOS 移位寄存器。8 位并行输出端口为可控的三态输出,一 个串行输入端口,可以实现多级芯片串行控制,组成 8n 位(n 为芯片数量)并行输出 。
- #include "main.h"
- #include "Board.h"
- #include "NIXIE.h"
- #include "systick.h"
- int main(void)
- {
- NVIC_ConfigPriorityGroup(NVIC_PRIORITY_GROUP_2);
- systick_config();
- /* Initialization */
- NIXIE_init();
-
- while(1)
- {
- NIXIE_display(0,0);
- delay_1ms(1);
- NIXIE_display(1,1);
- delay_1ms(1);
- NIXIE_display(2,2);
- delay_1ms(1);
- NIXIE_display(3,3);
- delay_1ms(1);
- NIXIE_display(4,4);
- delay_1ms(1);
- NIXIE_display(5,5);
- delay_1ms(1);
- NIXIE_display(6,6);
- delay_1ms(1);
- NIXIE_display(7,7);
- delay_1ms(1);
- NIXIE_display(8,8);
- delay_1ms(1);
- }
- }
NIXIE.h
- #ifndef __NIXIE_H__
- #define __NIXIE_H__
- #include "Board.h"
- #ifndef u8
- #define u8 uint8_t
- #endif
- #ifndef u16
- #define u16 uint16_t
- #endif
- #ifndef u32
- #define u32 uint32_t
- #endif
- #define NIXIE_DI_RCU RCM_AHB1_PERIPH_GPIOA
- #define NIXIE_DI_PORT GPIOA
- #define NIXIE_DI_PIN GPIO_PIN_1
- #define NIXIE_SCK_RCU RCM_AHB1_PERIPH_GPIOC
- #define NIXIE_SCK_PORT GPIOC
- #define NIXIE_SCK_PIN GPIO_PIN_1
- #define NIXIE_RCK_RCU RCM_AHB1_PERIPH_GPIOA
- #define NIXIE_RCK_PORT GPIOA
- #define NIXIE_RCK_PIN GPIO_PIN_2
- #define NIXIE_DI(bit) GPIO_WriteBitValue(NIXIE_DI_PORT, NIXIE_DI_PIN, bit ? BIT_SET : BIT_RESET)
- #define NIXIE_SCK(bit) GPIO_WriteBitValue(NIXIE_SCK_PORT, NIXIE_SCK_PIN, bit ? BIT_SET : BIT_RESET)
- #define NIXIE_RCK(bit) GPIO_WriteBitValue(NIXIE_RCK_PORT, NIXIE_RCK_PIN, bit ? BIT_SET : BIT_RESET)
- #define NIXIE_GPIO_CONFIG(gpio_rcu, gpio_port, gpio_pin,configStruct) \
- RCM_EnableAHB1PeriphClock(gpio_rcu); \
- GPIO_ConfigStructInit(&configStruct); \
- configStruct.pin = gpio_pin; \
- configStruct.mode = GPIO_MODE_OUT; \
- configStruct.speed = GPIO_SPEED_50MHz; \
- GPIO_Config(gpio_port, &configStruct); \
- void NIXIE_init(void);
- void NIXIE_show(u8 a_dat, u8 b_idx);
- void NIXIE_display(u8 num, u8 id);
- #endif
NIXIE.c
- #include "NIXIE.h"
- #include <stdio.h>
- #define GET_BIT_VAL(byte, pos) (byte & (1 << pos))
- #define NOP_TIME() __NOP();__NOP()
- #define RCK_ACTION() \
- NIXIE_RCK(0); \
- NOP_TIME(); \
- NIXIE_RCK(1); \
- NOP_TIME();
- u8 LED_TABLE[] =
- {
- // 0 1 2 -> 9
- 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,
- // 0. 1. 2. -> 9.
- 0x64,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,
- // . -
- 0x7F, 0xBF,
- // AbCdEFHJLPqU
- 0x88,0x83,0xC6,0xA1,0x86,0x8E,0x89,0xF1,0xC7,0x8C,0x98,0xC1
- };
- void NIXIE_init(){
- GPIO_Config_T configStruct;
- // NIXIE_DI
- NIXIE_GPIO_CONFIG(NIXIE_DI_RCU, NIXIE_DI_PORT, NIXIE_DI_PIN,configStruct);
- // NIXIE_SCK
- NIXIE_GPIO_CONFIG(NIXIE_SCK_RCU, NIXIE_SCK_PORT, NIXIE_SCK_PIN,configStruct);
- // NIXIE_RCK
- NIXIE_GPIO_CONFIG(NIXIE_RCK_RCU, NIXIE_RCK_PORT,NIXIE_RCK_PIN ,configStruct);
- }
- static void NIXIE_out(u8 dat){
- int8_t i;
- for(i = 7; i >= 0; i--){
- NIXIE_DI(GET_BIT_VAL(dat, i));
- NIXIE_SCK(0);
- NOP_TIME();
- NIXIE_SCK(1);
- NOP_TIME();
- }
- }
- void NIXIE_display(u8 num, u8 id){
- u8 a_dat = LED_TABLE[num]; // 0001 0010
- u8 b_idx = 1 << id; // 0010 0000
- NIXIE_show(a_dat, b_idx);
- }
- void NIXIE_show(u8 a_dat, u8 b_idx){
- NIXIE_out(a_dat);
- NIXIE_out(b_idx);
- RCK_ACTION();
- }
效果如下:
https://m.youku.com/mid_video/id_XNjM5NzE5MDI4MA==.html?scene=short&playMode=pugv&sharekey=531f61f73a5e258d15ad9abeae5c593d9