资源简介
这个软件是基于STM32F1系列的驱动程序,TM1637驱动芯片,,能够实现6位数码管显示和16个按键的扫描。已经在项目中稳定使用。
代码片段和文件信息
/******************************Copyright (c)***********************************
* Jiangsu Zhihai Electronic Technology Co. Ltd.
* Research & Development Department
*
* www.smarthealth-tech.com
*
-------------------------------------------------------------------------------
* @file TM1637.h
* @author GU DONGDONG
* @date 2015-11-25
*******************************************************************************/
#include “TM1637.h“
#include “sys.h“
#include “delay.h“
#include “led.h“
/** Write multiple bits in an 8-bit device register.
* @param slaveAddr I2C slave device address
* @param regAddr Register regAddr to write to
* @param bitStart First bit position to write (0-7)
* @param length Number of bits to write (not more than 8)
* @param data Right-aligned value to write
*/
//unsigned char dis_buff[]={0x3f0x060x5b0x4f0x660x6d0x7d0x070x7f0x6f0x770xff};
//unsigned char display_buff[6]={0xff0xff0xff0xff0xff0xff};
unsigned char temp=0xCF;//显示跳动的冒号
unsigned char NumDis[25]={0x3F0x060x5B0x4F0x660x6D0x7D0x070x7F0X6F\
0x770x7C0x390x5E0x790x71\
0x080x480x49\
0x760x380x0E0x500x370x00}; //0123456789ABCDEF一二三HLJRS
void TM1637_Delay_us(unsigned int Nus)
{
for(;Nus>0;Nus--)
{
__nop();
__nop();
__nop();
__nop();
__nop();
__nop();
__nop();
__nop();
__nop();
__nop();
__nop();
}
}
void TM1637_Start(void)
{
TM1637_DIO_OUT();
TM1637_CLK = 1;
TM1637_DIO = 1;
delay_us(2);
TM1637_DIO = 0;
}
void TM1637_Ack(void)
{
TM1637_DIO_IN();
TM1637_CLK = 0;
TM1637_Delay_us(5);
// while(TM1637_READ_DIO);
TM1637_CLK = 1;
delay_us(2);
TM1637_CLK = 0;
}
void TM1637_Stop(void)
{
TM1637_DIO_OUT();
TM1637_CLK = 0;
delay_us(2);
TM1637_DIO = 0;
delay_us(2);
TM1637_CLK = 1;
delay_us(2);
TM1637_DIO = 1;
}
void TM1637_WriteByte(unsigned char oneByte)
{
unsigned char i;
TM1637_DIO_OUT();
for(i=0;i<8;i++)
{
TM1637_CLK = 0;
if(oneByte&0x01)
{
TM1637_DIO = 1;
}
else
{
TM1637_DIO = 0;
}
delay_us(3);
oneByte=oneByte>>1;
TM1637_CLK = 1;
delay_us(3);
}
}
unsigned char TM1637_ScanKey(void)
{
unsigned char reKeyi;
TM1637_Start();
TM1637_WriteByte(0x42);
TM1637_Ack();
TM1637_DIO = 1;
TM1637_DIO_IN();
for(i=0;i<8;i++)
{
TM1637_CLK = 0;
reKey=reKey>>1;
delay_us(20);
TM1637_CLK = 1;
if(TM1637_READ_DIO)
{
reKey=reKey|0x80;
}
else
{
reKey=reKey|0x00;
}
delay_us(20);
}
TM1637_Ack();
TM1637_Stop();
return(reKey);
}
//void TM1637_NixieTubeDisplay(void)
//{
// unsigned char i;
// TM1637_Start();
// TM1637_WriteByte(0x40);
// TM1637_Ack();
// TM1637_Stop();
// TM1637_Start();
// TM1637_WriteByte(0xC0);
// TM1637_Ack();
//
// for(i=0;i<6;i++)
// {
//
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4863 2019-07-31 20:43 基于STM32的TM1637数码管显示和按键扫描驱动\TM1637.c
文件 1256 2019-07-27 07:58 基于STM32的TM1637数码管显示和按键扫描驱动\TM1637.h
目录 0 2019-08-04 18:20 基于STM32的TM1637数码管显示和按键扫描驱动
----------- --------- ---------- ----- ----
6119 3
- 上一篇:STM32F1XX_TM1637.rar
- 下一篇:TM1637中文手册以及程序
评论
共有 条评论