找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2320|回复: 0
打印 上一主题 下一主题
收起左侧

TM1629D显示驱动程序

[复制链接]
跳转到指定楼层
楼主
ID:370149 发表于 2022-1-26 11:02 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#define        CMD_TM1629_READ                        0x42

#define        TM1629_STB_HIGH()                GPIO_WriteBit(GPIOC,GPIO_Pin_15,Bit_SET)//SetBits(GPIOC,GPIO_Pin_15)                        
#define        TM1629_STB_LOW()                GPIO_WriteBit(GPIOC,GPIO_Pin_15,Bit_RESET)//ResetBits(GPIOC,GOIO_Pin_15)                        

#define        TM1629_CLK_HIGH()                GPIO_WriteBit(GPIOC,GPIO_Pin_13,Bit_SET)//SetBits(GPIOB,GPIO_Pin_4)               
#define        TM1629_CLK_LOW()                GPIO_WriteBit(GPIOC,GPIO_Pin_13,Bit_RESET)//ResetBits(GPIOB,GOIO_Pin_4)                                 

#define        TM1629_DIO_HIGH()                GPIO_WriteBit(GPIOC,GPIO_Pin_14,Bit_SET)//SetBits(GPIOB,GPIO_Pin_3)                                
#define        TM1629_DIO_LOW()                GPIO_WriteBit(GPIOC,GPIO_Pin_14,Bit_RESET)//ResetBits(GPIOB,GOIO_Pin_3)

void Delay1(vu32 nCount)
{
  for(; nCount!= 0;nCount--);
}

void        TM1629_OutByte(u8 dat)
{
        u8 i;

        for(i=0;i<8;i++)
        {
                TM1629_CLK_LOW();                 
                if((dat & 0x01) == 0x01)
                    TM1629_DIO_HIGH();
                else
                    TM1629_DIO_LOW();
                Delay1(10);                        //        
                TM1629_CLK_HIGH();                //
                dat >>= 1;
    }
}


u8        TM1629_InByte(void)
{
        u8 i;
        u8 dat = 0;
        
        TM1629_DIO_HIGH();                //
        for(i = 0; i < 8; i++)
        {               
                TM1629_CLK_LOW();
                dat >>= 1;                        //
                //if(TM1629_DIO) dat += 0x80;GPIO_ReadInputDataBit
                if(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_14)) dat += 0x80;
                TM1629_CLK_HIGH();
        }
        return(dat);
}

void        TM1629_SendCmd(u8 cmd)
{
        TM1629_STB_HIGH();                        //

        TM1629_CLK_HIGH();

        TM1629_STB_LOW();                        //
        Delay1(10);                //
        TM1629_OutByte(cmd);

        TM1629_STB_HIGH();
        
}

void        TM1629_SendAddr(u8 addr)
{
        TM1629_STB_HIGH();                        //

        TM1629_CLK_HIGH();

        TM1629_STB_LOW();                        //
        Delay1(10);                                //
        TM1629_OutByte(addr);
}


void        TM1629_WriteBlock( u8 addr, u8 len, u8* buf )
{
        TM1629_SendAddr( addr );
        while ( len -- ) TM1629_OutByte( *buf++ );

        TM1629_STB_HIGH();

}

void        TM1629_ReadKey( u8 len, u8* buf )
{
        TM1629_SendAddr(CMD_TM1629_READ);//
        while ( len -- ) *buf++ = TM1629_InByte();        
        TM1629_STB_HIGH();         
}

void        TM1629_Config(void)
{
        TM1629_CLK_HIGH();

        TM1629_DIO_HIGH();

        TM1629_STB_HIGH();        
        //TM1629_SendCmd(0x03);               
        //TM1629_SendCmd(0x40);               
        //clear ram        
        
        //TM1629_SendCmd(0x88);//

}

评分

参与人数 1黑币 +20 收起 理由
admin + 20 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表