|
爱科技、爱创意、爱折腾、爱极致,我们都是技术控
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 amsl 于 2025-5-23 13:05 编辑
使用的STM32单片机,- //头文件内容
- #ifndef __TM1629D_H__
- #include "stm32f1xx_hal_gpio.h"
- #include "gpio.h"
- __inline void delayus(uint32_t us)
- {
- uint32_t i = 10;
- while(us--) {
- i=10;
- while(i--);
- }
- }
- __inline void tm1629_dio_0() { HAL_GPIO_WritePin(GPIOB, PIN11, 0); delayus(1); }
- __inline void tm1629_dio_1() { HAL_GPIO_WritePin(GPIOB, PIN11, 1); delayus(1); }
- __inline void tm1629_clk_0() { HAL_GPIO_WritePin(GPIOB, PIN12, 0); delayus(1); }
- __inline void tm1629_clk_1() { HAL_GPIO_WritePin(GPIOB, PIN12, 1); delayus(1); }
- __inline void tm1629_stb_0() { HAL_GPIO_WritePin(GPIOB, PIN13, 0); delayus(1); }
- __inline void tm1629_stb_1() { HAL_GPIO_WritePin(GPIOB, PIN13, 1); delayus(1); }
- #endif
- //C源代码内容
- #include "tm1629.h"
- #include "stm32f1xx_hal.h"
- const uint8_t DT[] = { //显示的数字编码
- //[0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [A], [-]
- 0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x40
- };
- //写入一个字节
- void tm1629_write_byte(uint8_t dat)
- {
- int i;
- for (i=0; i<8; i++)
- {
- tm1629_clk_0();
- if (dat & 0x01) {
- tm1629_dio_1();
- } else {
- tm1629_dio_0();
- }
- tm1629_clk_1();
- dat >>= 1;
- }
- }
- //设定LED数码管的显示亮度
- //libht: 0~7 //亮度取值范围
- void tm1629_light(uint8_t level)
- {
- if (level > 7)
- level = 7;
- tm1629_stb_0();
- tm1629_write_byte(0x88 + level);
- tm1629_stb_1();
- }
- //在指定的数码管上写入数据,8个数码管映射为映射为0~7
- //addr:0~7
- void tm1629_display(uint8_t addr, uint8_t dat, uint8_t dot)
- {
- tm1629_stb_0();
- tm1629_write_byte(0x44);
- tm1629_stb_1();
- tm1629_stb_0();
- tm1629_write_byte(0xC0 | (addr*2));
- if (dot) {
- tm1629_write_byte(DT[dat] | 0x80); //display decimal point
- } else {
- tm1629_write_byte(DT[dat]);
- }
- tm1629_stb_1();
- }
- //连续写8个数码管
- void tm1629_write_8byte(uint8_t *dats)
- {
- for (int i=0; i<8; i++) {
- tm1629_display(i, *dats++, 0);
- }
- }
复制代码
|
|