1272 views|2 replies

75

Posts

1

Resources
The OP
 

[Boliu BL606P audio and video development board] + driving LED digital tube [Copy link]

 

1. Wiring schematic diagram.

The TM1638 module is mainly controlled by three wires, namely STB, CLK and DIO. Now use GPIO3, GPIO4 and GPIO5 for control.

2. Procedure

The program consists of two parts, tm1638 and main program.

TM1638 consists of header files and c files, as follows:

tm1638 header file, mainly defines three interface controls and log printing


#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

The tm1638.c file mainly defines the control of the mainboard and the tm163 module, as well as the digital display.

#include <aos/aos.h>
#include <stdio.h>
#include <sys_clk.h>
#include "app_main.h"
#include <drv/gpio.h>

#include <aos/hal/gpio.h>
#include <drv/pin.h>
#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<<i))
		{
			tm1638_Write_Addr(2*i+1,1);
		}
		else
		{
			tm1638_Write_Addr(2*i+1,0);
		}
	}
}

void init_tm1638(void)
{
	uint8_t i;
	csi_pin_set_mux( GPIO_PIN_3, PIN_FUNC_GPIO);
	csi_pin_set_mux( GPIO_PIN_4, PIN_FUNC_GPIO);
	csi_pin_set_mux( GPIO_PIN_5, PIN_FUNC_GPIO);
	hal_gpio_init(&gpio_stb);
	hal_gpio_init(&gpio_clk);
	hal_gpio_init(&gpio_dio);
	
	hal_gpio_output_low(&gpio_stb);
	hal_gpio_output_low(&gpio_clk);
	hal_gpio_output_low(&gpio_dio);
        

	tm1638_WriteCmd(0x8b);
	tm1638_WriteCmd(0x40);
	stb_l();
	tm1638_WriteDat(0xc0);   
	for(i=0;i<16;i++)           
	{
		tm1638_WriteDat(0x00);
	}
	stb_h();
	for(i=0;i<8;i++)
	{
        tm1638_Write_Addr(i<<1,tab[0]);                       
	}
}

 void disp_led(uint8_t *dat)
 {
	uint8_t i;
	for(i=0;i<8;i++)
	{
		tm1638_Write_Addr(i<<1,tab[dat]);                        
	} 
 }

 void disp_log(void)
 {
	uint8_t i;
	for(i=0;i<8;i++)
	{
		tm1638_Write_Addr(i<<1,ds_log);                        
	} 
 }

The main.c file gives the main control of the program.


/*
 * Copyright (C) 2015-2020 Alibaba Group Holding Limited
 */

#include <aos/aos.h>
#include <stdio.h>
#include <sys_clk.h>
#include "app_main.h"
#include <drv/gpio.h>
#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("\r\napp start core clock %d........\r\n", 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\r\n",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;
}

3 Effects

Overall, I feel it is very good!

Latest reply

STB, CLK and DIO three interfaces, and then use GPIO3, GPIO4 and GPIO5 to control, the result is OK   Details Published on 2023-3-12 09:56
 
 

6570

Posts

0

Resources
2
 

STB, CLK and DIO three interfaces, and then use GPIO3, GPIO4 and GPIO5 to control, the result is OK

Comments

Yes, the basic control effect has been achieved  Details Published on 2023-3-13 09:34
 
 
 

75

Posts

1

Resources
3
 
Jacktang posted on 2023-3-12 09:56 STB, CLK and DIO three interfaces, and then use GPIO3, GPIO4 and GPIO5 to control, the result is OK

Yes, the basic control effect has been achieved

 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list