久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 5528|回復: 2
收起左側

基于STM32F103zet6的TM1638驅動

[復制鏈接]
ID:223425 發表于 2017-7-30 19:33 | 顯示全部樓層 |閱讀模式
  • /**********************************************************************************************
  • **Program Assignment: Driver for TM1638 digital tube
  • **Author        : Wuwang
  • **Date              : 2014.8.26 9:00
  • **Description       : This is a driver for the board which is controled by thechip of tm1638.  
  •               The board has eight digital tubes which have eight segments and eight keys.
  • ***********************************************************************************************/  
  • #include "main.h"                              //#include "stm32f10x.h"   
  •   
  • /*********************define and global variables*********************************************/  
  • #define STB GPIO_Pin_0                          //chip-select line  
  • #define CLK GPIO_Pin_1                                      //clock line  
  • #define DIO GPIO_Pin_2                                                                      //data line  
  • #define Set(x) GPIO_SetBits(GPIOA,(x))              //Sets the selected data port bits  
  • #define Reset(x) GPIO_ResetBits(GPIOA,(x))          //Resets the selected data port bits  
  • #define Get(x) GPIO_ReadInputDataBit(GPIOA,(x))==SET        //Read the specified input port pin  
  •   
  •   
  • uint16_t const tm_dat[2][14]={{'0','1','2','3','4','5',     //the char and its segment code   
  •             '6','7','8','9','.','-','_',' '},  
  •             {0x3F,0x06,0x5B,0x4F,0x66,0x6D,  
  •             0x7D,0x07,0x7F,0x6F,0x80,0x40,  
  •             0x08,0x00}};  
  •   
  • /***********************************************************************************************
  • *Function Name: RCC_Config      
  • *Purpose      : Configration Clock
  • ***********************************************************************************************/  
  • void RCC_Config(){  
  •     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);  
  • }  
  •   
  • /***********************************************************************************************
  • *Function Name: GPIO_Config      
  • *Purpose      : Configration GPIO
  • ***********************************************************************************************/  
  • void GPIO_Config(){  
  •     GPIO_InitTypeDef GPIO_InitStructure;  
  •     GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_OD;  
  •     GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;  
  •     GPIO_InitStructure.GPIO_Pin=STB|CLK|DIO;  
  •     GPIO_Init(GPIOA,&GPIO_InitStructure);  
  • }  
  • /***********************************************************************************************
  • *Function Name: Write_Byte      
  • *Purpose      : Write one byte to the data port
  • *params       : byte  -------8-bits byte   
  • *return       : none
  • ***********************************************************************************************/  
  • void Write_Byte(uint8_t byte){  
  •     uint8_t i=0;  
  •     for(i=0;i<8;i++){  
  •         Reset(CLK);  
  •         if(byte&0x01){  
  •             Set(DIO);  
  •         }else{  
  •             Reset(DIO);  
  •         }  
  •         Set(CLK);  
  •         byte>>=1;  
  •     }  
  • }  
  •   
  • /***********************************************************************************************
  • *Function Name: Read_Byte        
  • *Purpose      : Read one byte from data port
  • *params       : none
  • *return       : the 8-bits byte which is read from data port
  • ***********************************************************************************************/  
  • int8_t Read_Byte(){  
  •     uint8_t i=0;  
  •     uint8_t temp=0x00;  
  •     for(i=0;i<8;i++){  
  •         Set(CLK);  
  •         temp>>=1;  
  •         if(Get(DIO)){  
  •             temp|=0x80;  
  •         }  
  •         Reset(CLK);  
  •     }  
  •     return temp;  
  • }  
  •   
  • /***********************************************************************************************
  • *Function Name: Write_Cmd        
  • *Purpose      : Write a conmand to the data port
  • *params       : cmd  -------8-bits byte,the conmand,check the data sheet to find the conmand  
  • *return       : none
  • ***********************************************************************************************/  
  • void Write_Cmd(uint8_t cmd){  
  •     Set(STB);  
  •     Reset(STB);  
  •     Write_Byte(cmd);  
  • }  
  •   
  • /***********************************************************************************************
  • *Function Name: Read_Key         
  • *Purpose      : Read the key number which has been pressed
  • *params       : none
  • *return       : the number of the key. 0-8.  "return 0" represents no key has been pressed.
  • ***********************************************************************************************/  
  • int8_t Read_Key(){  
  •     uint8_t i=0;  
  •     uint8_t key1=0x00;  
  •     uint16_t key2=0x00;  
  •     Write_Cmd(0x42);  
  •     Set(DIO);                       //this is obligatory, check the data sheet,GPIO  
  •     for(i=0;i<4;i++){  
  •         key1=Read_Byte();  
  •         key2|=(key1<<i);  
  •     }  
  •     key2>>=1;  
  •     for(i=0;i<8;i++){  
  •         if(0x01<<i==key2)return i+1;  
  •     }  
  •     return 0;  
  • }  
  •   
  • /***********************************************************************************************
  • *Function Name: Write_Dat        
  • *Purpose      : Write data to the location specified
  • *params       : addr  ------the address,0x00 to 0x0f
  •         dat   ------the data,segment code
  • *return       : none
  • ***********************************************************************************************/  
  • void Write_Dat(uint8_t addr,uint8_t dat){  
  •     Write_Cmd(0x44);  
  •     Write_Cmd(0xc0|addr);  
  •     Write_Byte(dat);  
  • }  
  •   
  • /***********************************************************************************************
  • *Function Name: TM1638_SendData      
  • *Purpose      : Write data to the location specified
  • *params       : i     ------the bit code of digtal tube,0 to 7
  •         str   ------the string,the char which was not in tm_data will be replace with "''".
  • *return       : none
  • ***********************************************************************************************/  
  • void TM1638_SendData(uint8_t i,char * str){  
  •     int j=0,k=0;  
  •     unsigned char chr;  
  •     for(;i<8;i++){  
  •         k=0;  
  •         for(j=0;j<14;j++){  
  •             if(*str==tm_dat[0][j]){  
  •                 chr=tm_dat[1][j];  
  •                 k=1;  
  •                 break;  
  •             }  
  •         }  
  •          
  •         if(k==0){  
  •             chr=0x00;  
  •         }  
  •          
  •         if(*(str+1)=='.'){  
  •             chr|=0x80;  
  •             Write_Dat(i*2,chr);  
  •             str++;  
  •         }else{  
  •             Write_Dat(i*2,chr);  
  •         }  
  •         str++;  
  •         if(*str=='\0')break;  
  •     }  
  • }  
  •   
  • /***********************************************************************************************
  • *Function Name: TM1638_Init      
  • *Purpose      : the initialization of tm1638
  • *params       : none
  • *return       : none
  • ***********************************************************************************************/  
  • void TM1638_Init(){  
  •     int i=0;  
  •     RCC_Config();  
  •     GPIO_Config();  
  •     Write_Cmd(0x8a);  
  •     Write_Cmd(0x40);  
  •     for(i=0;i<16;i++){  
  •         Write_Byte(0x00);  
  •     }  
  • }  

回復

使用道具 舉報

ID:199141 發表于 2017-10-12 09:51 | 顯示全部樓層
調用格式 請告知最好寫個測試程序。感謝你
回復

使用道具 舉報

ID:344623 發表于 2019-8-4 09:59 | 顯示全部樓層
多謝分享,我下載來試
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 日韩色图视频 | 欧美日韩精品一区 | 欧美日韩国产免费 | 天天操操 | 成人免费视频网站在线看 | 欧美aⅴ片 | 欧美xxxx日本 | 精品一区av | 亚洲区一区二 | 色网站入口 | 成人免费网站www网站高清 | 中文亚洲视频 | 一区二区三区视频在线观看 | 日本黄色大片免费 | 日韩欧美日韩在线 | 久久久久亚洲精品国产 | 精精国产xxxx视频在线播放7 | 精品91久久久| 久久亚洲国产 | 成人在线免费视频观看 | 成人午夜在线 | 国产精品精品视频一区二区三区 | 国产女人与拘做受免费视频 | 日韩一区二区在线视频 | 亚洲一区二区三区免费在线观看 | 国产1区2区 | 91深夜福利视频 | 日韩国产免费观看 | 大学生a级毛片免费视频 | 狠狠操狠狠 | 美女黄网站视频免费 | 国产精品亚洲综合 | 亚洲二区视频 | 国际精品鲁一鲁一区二区小说 | 国产99久久精品一区二区永久免费 | 羞羞视频免费观看入口 | 国产日韩电影 | 搞av.com| 精品国产一区二区三区在线观看 | 日韩精彩视频 | 欧美高清一级片 |