[应用方案] TM1650模块单片机源程序(子函数)

[复制链接]
4937|46
 楼主| kmzuaz 发表于 2023-10-26 13:00 | 显示全部楼层 |阅读模式

[color=rgb(51, 51, 51) !important]单片机源程序如下:



[color=rgb(51, 51, 51) !important]#include"tm1650.h"

[color=rgb(51, 51, 51) !important]void Delay_us(uint i) //us延时

[color=rgb(51, 51, 51) !important]{

[color=rgb(51, 51, 51) !important]        for(;i>0;i--)

[color=rgb(51, 51, 51) !important]        {

[color=rgb(51, 51, 51) !important]        _nop_();

[color=rgb(51, 51, 51) !important]//        _nop_();

[color=rgb(51, 51, 51) !important]//        _nop_();

[color=rgb(51, 51, 51) !important]        }

[color=rgb(51, 51, 51) !important]}

[color=rgb(51, 51, 51) !important]void I2CStart(void)        //开始信号

[color=rgb(51, 51, 51) !important]{

[color=rgb(51, 51, 51) !important]        CLK_H;

[color=rgb(51, 51, 51) !important]        DIO_H;

[color=rgb(51, 51, 51) !important]        Delay_us(5);

[color=rgb(51, 51, 51) !important]        DIO_L;


[color=rgb(51, 51, 51) !important]}


[color=rgb(51, 51, 51) !important]void I2Cask(void) //ACK信号

[color=rgb(51, 51, 51) !important]{

[color=rgb(51, 51, 51) !important]        uchar timeout = 1;

[color=rgb(51, 51, 51) !important]        CLK_H;

[color=rgb(51, 51, 51) !important]        Delay_us(5);

[color=rgb(51, 51, 51) !important]        CLK_L;

[color=rgb(51, 51, 51) !important]        while((DIO)&&(timeout<=100))

[color=rgb(51, 51, 51) !important]        {

[color=rgb(51, 51, 51) !important]          timeout++;        

[color=rgb(51, 51, 51) !important]        }

[color=rgb(51, 51, 51) !important]        Delay_us(5);

[color=rgb(51, 51, 51) !important]        CLK_L;

[color=rgb(51, 51, 51) !important]}


[color=rgb(51, 51, 51) !important]void I2CStop(void) //停止信号

[color=rgb(51, 51, 51) !important]{

[color=rgb(51, 51, 51) !important]        CLK_H;

[color=rgb(51, 51, 51) !important]        DIO_L;

[color=rgb(51, 51, 51) !important]        Delay_us(5);

[color=rgb(51, 51, 51) !important]        DIO_H;

[color=rgb(51, 51, 51) !important]}


[color=rgb(51, 51, 51) !important]void I2CWrByte(uchar oneByte) //写一个字节高位在前,低位在后

[color=rgb(51, 51, 51) !important]{

[color=rgb(51, 51, 51) !important]        uchar i;

[color=rgb(51, 51, 51) !important]        CLK_L;

[color=rgb(51, 51, 51) !important]        Delay_us(1);

[color=rgb(51, 51, 51) !important]        for(i=0;i<8;i++)

[color=rgb(51, 51, 51) !important]        {        

[color=rgb(51, 51, 51) !important]                oneByte = oneByte<<1;

[color=rgb(51, 51, 51) !important]                DIO = CY;

[color=rgb(51, 51, 51) !important]                CLK_L;

[color=rgb(51, 51, 51) !important]                Delay_us(5);

[color=rgb(51, 51, 51) !important]                CLK_H;

[color=rgb(51, 51, 51) !important]                Delay_us(5);

[color=rgb(51, 51, 51) !important]                CLK_L;

[color=rgb(51, 51, 51) !important]        }

[color=rgb(51, 51, 51) !important]}


[color=rgb(51, 51, 51) !important]uchar Scan_Key(void)          // 按键扫描

[color=rgb(51, 51, 51) !important]{

[color=rgb(51, 51, 51) !important]        uchar i;

[color=rgb(51, 51, 51) !important]        uchar rekey;

[color=rgb(51, 51, 51) !important]        I2CStart();

[color=rgb(51, 51, 51) !important]        I2CWrByte(0x49);//读按键命令

[color=rgb(51, 51, 51) !important]        I2Cask();

[color=rgb(51, 51, 51) !important]        //DIO_H;

[color=rgb(51, 51, 51) !important]        for(i=0;i<8;i++)

[color=rgb(51, 51, 51) !important]        {

[color=rgb(51, 51, 51) !important]           CLK_H;

[color=rgb(51, 51, 51) !important]           rekey = rekey<<1;

[color=rgb(51, 51, 51) !important]           if(DIO)

[color=rgb(51, 51, 51) !important]           {

[color=rgb(51, 51, 51) !important]                   rekey++;

[color=rgb(51, 51, 51) !important]           }

[color=rgb(51, 51, 51) !important]           Delay_us(5);

[color=rgb(51, 51, 51) !important]           CLK_L;        

[color=rgb(51, 51, 51) !important]        }

[color=rgb(51, 51, 51) !important]        I2Cask();

[color=rgb(51, 51, 51) !important]        I2CStop();

[color=rgb(51, 51, 51) !important]        return(rekey);

[color=rgb(51, 51, 51) !important]}



[color=rgb(51, 51, 51) !important]void TM1650_Set(uchar add,uchar dat) //数码管显示

[color=rgb(51, 51, 51) !important]{

[color=rgb(51, 51, 51) !important]        //写显存必须从高地址开始写

[color=rgb(51, 51, 51) !important]        I2CStart();

[color=rgb(51, 51, 51) !important]        I2CWrByte(add); //第一个显存地址

[color=rgb(51, 51, 51) !important]        I2Cask();

[color=rgb(51, 51, 51) !important]        I2CWrByte(dat);

[color=rgb(51, 51, 51) !important]        I2Cask();

[color=rgb(51, 51, 51) !important]        I2CStop();

[color=rgb(51, 51, 51) !important]}



jackcat 发表于 2023-11-5 11:14 | 显示全部楼层
在操作TM1650模块时,需要注意芯片的版本问题。TM1650目前有两个版本,即在丝印的批号中以1开头的旧版和以2开头的新版。在实际使用中,需要确保使用的芯片是与程序相匹配的版本。
nomomy 发表于 2023-11-5 11:38 | 显示全部楼层
需要注意功耗的问题。因为TM1650模块功耗较大
mickit 发表于 2023-11-5 15:19 | 显示全部楼层
在使用TM1650模块时,需要注意电源的管理,例如避免长时间的点亮,以防止电源的消耗过快。
claretttt 发表于 2023-11-5 16:03 | 显示全部楼层
初始化TM1650模块时,需要按照模块的要求进行操作
bestwell 发表于 2023-11-5 17:19 | 显示全部楼层
可能会遇到TM1650模块出现的异常情况,如通信错误、显示异常等
claretttt 发表于 2023-11-5 17:53 | 显示全部楼层
确保所有的引脚都正确地连接到单片机和TM1650模块上。特别是VCC、GND、DATA这三个引脚,必须保证正确的连接。
yeates333 发表于 2023-11-5 20:29 | 显示全部楼层
在单片机和TM1650模块之间进行数据传输时,需要注意数据的格式和顺序。通常,单片机需要先发送命令字,然后再发送数据字。
uptown 发表于 2023-11-5 20:38 | 显示全部楼层
模块的每个段都有一个唯一的地址,应根据模块的具体情况选择正确的地址进行操作
albertaabbot 发表于 2023-11-5 20:52 | 显示全部楼层
在发送完命令字或数据字之后,通常需要等待一段时间,让TM1650模块有足够的时间来处理这些数据。这个时间通常由TM1650模块的工作速度和单片机的处理速度决定。
pentruman 发表于 2023-11-5 22:20 | 显示全部楼层
TM1650模块通常包括电源引脚、时钟引脚、数据引脚和控制引脚等。确保连接正确,以保证模块正常工作。
linfelix 发表于 2023-11-6 20:01 | 显示全部楼层
单片机与TM1650模块之间的信号电平需要匹配,以避免因电平不匹配而导致通信失败或损坏模块。
zwsam 发表于 2023-11-8 08:55 | 显示全部楼层
bartonalfred 发表于 2023-11-8 10:32 | 显示全部楼层
根据TM1650模块的datasheet设置正确的寄存器参数,例如时钟源、波特率等。
tabmone 发表于 2023-11-8 12:51 | 显示全部楼层
单片机程序需要正确编写,以实现与TM1650模块的通信和控制。需要注意数据的格式和传输协议的约定,以及正确的读写操作。
lzbf 发表于 2023-11-8 14:27 | 显示全部楼层
在设计过程中,注意降低功耗,避免单片机长时间运行在高速模式。
pl202 发表于 2023-11-8 14:42 | 显示全部楼层
在操作TM1650模块时,需要配置适当的通信参数来确保通信的稳定和正确性。
adolphcocker 发表于 2023-11-8 14:54 | 显示全部楼层
编写程序时,注意模块的状态机和工作原理,确保控制逻辑的正确性。
phoenixwhite 发表于 2023-11-8 15:41 | 显示全部楼层
为确保TM1650模块的正常工作,需要提供稳定的电源,同时确保电源与地线连接的正确性
updownq 发表于 2023-11-8 15:51 | 显示全部楼层
单片机与TM1650模块之间采用2线串行传输协议通讯,需要注意遵循该协议的规范,以保证数据传输的正确性。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

20

主题

3437

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部