編輯語:
芯片開放社區(OCC)面向廣大開發者推出應用實戰系列內容,通過分享開發者實戰開發案例,總結應用開發經驗,梳理開發中的常見問題及解決方案,為后續參與的開發者提供更多參考與借鑒。
本文是關于開發者 swzswz基于BL606P-DVK開發板實戰開發的系列文章中的一篇,主要介紹了驅動led數碼管,后面還會持續更新社區開發者的測評內容,敬請期待!
01接線原理圖
TM1638模塊主要由三根線進行控制,分別是STB,CLK和DIO三個接口。現在用GPIO3,GPIO4以及GPIO5來進行控制。
02程序
程序由兩部分組成,tm1638和main主程序組成。
TM1638由頭文件和c文件,分別如下:
tm1638頭文件,主要定義三個接口控制以及log打印
tm1638頭文件,主要定義三個接口控制以及log打印
#ifndef TM1638_H_ #define TM1638_H_ #define dio_l() hal_gpio_output_low(&gpio_dio) #define dio_h() hal_gpio_output_high(&gpio_dio) #define clk_l() hal_gpio_output_low(&gpio_clk) #define clk_h() hal_gpio_output_high(&gpio_clk) #define stb_l() hal_gpio_output_low(&gpio_stb) #define stb_h() hal_gpio_output_high(&gpio_stb) void init_tm1638(void); void disp_led(uint8_t *dat); void disp_log(void); #endif
tm1638.c文件,主要定義主板和tm163模塊進行控制,以及數碼顯示。
#include#include #include #include "app_main.h" #include #include #include #include "tm1638.h" gpio_dev_t gpio_stb = { GPIO_PIN_3, OUTPUT_PUSH_PULL, NULL }; gpio_dev_t gpio_clk= { GPIO_PIN_4, OUTPUT_PUSH_PULL, NULL }; gpio_dev_t gpio_dio = { GPIO_PIN_5, OUTPUT_PUSH_PULL, NULL }; uint8_t const tab[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71}; uint8_t ds_log[8]={0x40,0x7c,0x38,0x7d,0x3f,0x7d,0x73,0x40}; void tm1638_WriteDat(uint8_t dat) { uint8_t i; for(i=0;i<8;i++) { clk_l(); if(dat&0X01) { dio_h(); } else { dio_l(); } dat>>=1; clk_h(); } } void tm1638_WriteCmd(uint8_t cmd) { stb_l(); tm1638_WriteDat(cmd); stb_h(); } void tm1638_Write_Addr(uint8_t addr,uint8_t dat) { tm1638_WriteCmd(0x44); stb_l(); tm1638_WriteDat(0xc0|addr); tm1638_WriteDat(dat); stb_h(); } void tm1638_Write_LED(uint8_t LED_flag) { uint8_t i; for(i=0;i<8;i++) { if(LED_flag&(1<
main.c文件,給定程序主控制。
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include#include #include #include "app_main.h" #include #include "led.h" #include "tm1638.h" int main(int argc, char *argv[]) { int i=0; uint8_t dispbuf[8]; uint32_t cnt=0; board_yoc_init(); init_led(); init_tm1638(); printf(" app start core clock %d........ ", soc_get_cur_cpu_freq()); disp_log(); aos_msleep(2000); //codec_output_init(); //codec_input_init(); //codec_loop_init(); for(i=0;i<8;i++) { dispbuf=0; } while(1) { i++; printf("zhanghui %d ",i); set_ledr(); clr_ledg(); clr_ledb(); aos_msleep(100); clr_ledr(); set_ledg(); clr_ledb(); aos_msleep(100); clr_ledr(); clr_ledg(); set_ledb(); aos_msleep(100); clr_ledr(); clr_ledg(); clr_ledb(); aos_msleep(100); if(cnt>999) { cnt=0; } cnt++; dispbuf[4]=cnt/1000; dispbuf[5]=(cnt%1000)/100; dispbuf[6]=((cnt%1000)%100)/10; dispbuf[7]=((cnt%1000)%100)%10; disp_led(dispbuf); } return 0; }
03效果
總體感覺還是很不錯!
審核編輯:湯梓紅
-
led
+關注
關注
242文章
23356瀏覽量
663202 -
接口
+關注
關注
33文章
8691瀏覽量
151919 -
數碼管
+關注
關注
32文章
1887瀏覽量
91408 -
音視頻
+關注
關注
4文章
485瀏覽量
29981 -
開發板
+關注
關注
25文章
5121瀏覽量
98195
原文標題:應用速遞 | 博流BL606P音視頻開發板+驅動led數碼管
文章出處:【微信號:芯片開放社區,微信公眾號:芯片開放社區】歡迎添加關注!文章轉載請注明出處。
發布評論請先 登錄
相關推薦
評論