TM1616 驱动

http://www.51hei.com/bbs/dpj-168066-1.html

 

https://blog.csdn.net/ccy764417301/article/details/84955918

 

http://www.mcuzx.net/thread-1728-1-1.html

 

#include "stm32f10x.h"
#include "stdio.h"
#include "tm1620.h"
#include "delay.h"
extern u8 tab[];
int main(void)
{
  u8 i;
        TM1616_init();
        Write_Cmd(0x88);
        while(1)
        {
    for(i=0;i<10;i++)
                {
                Write_Data(0x00,tab[i]); 
           Write_Data(0x02,tab[i]);
                delay_ms(500);
                }
        }
        
        
}
#include "tm1620.h"
#include "stdio.h"
#include "stdlib.h"
#include "delay.h"



 u8 tab[]={0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00,0x30};      

void TM1620port_init(void)   
{   
    GPIO_InitTypeDef  GPIO_InitStructure;
        
          RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);//?????   
    
          GPIO_InitStructure.GPIO_Pin =TM1620_CLK|TM1620_DIN|TM1620_STB;
          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
          GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
          GPIO_Init(GPIOB, &GPIO_InitStructure); 
}   

void TM1620_Write(u8 data)
{
  u8 i;
        for(i=0;i<8;i++)
        {
          TM1620_CLK_L;  //2us   复位CLK口
    if(data & 0x01)   //将低位数据传入
    TM1620_DIN_H;   
    else   
    TM1620_DIN_L;   
    data >>=1;     //右移一位
    TM1620_CLK_H;   //  捕获上升沿
        }
}
 
void Write_Cmd(u8 cmd)
{
   TM1620_STB_L;
         TM1620_Write(cmd);
         TM1620_STB_H;
}        

void Write_Data(u8 add,u8 data)
{
         Write_Cmd(0x44);
   TM1620_STB_L;
         TM1620_Write(0xc0|add);
         TM1620_Write(data);
         TM1620_STB_H;
}


void TM1616_init(void)
{
   u8 i;
         TM1620port_init();
         delay_ms(10);
         Write_Cmd(0x8f);       //亮度 (0x88-0x8f)8级亮度可调
         Write_Cmd(0x40);
         TM1620_STB_L;
         TM1620_Write(0xc0);
         for(i=0;i<16;i++)
         TM1620_Write(0x00);
         TM1620_STB_H;
}

 

你可能感兴趣的:(单片机开发教程)