欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: TM1640驅動按鍵/數碼管,親測好用 [打印本頁]

作者: lusx123    時間: 2018-12-15 14:06
標題: TM1640驅動按鍵/數碼管,親測好用
#include "TM1640.h"
#include "delay.h"

#define DEL  1   //宏定義 通信速率(默認為1,如不能通信可加大數值)

//地址模式的設置
//#define TM1640MEDO_ADD  0x40   //宏定義        自動加一模式
#define TM1640MEDO_ADD  0x44   //宏定義 固定地址模式(推薦)

//顯示亮度的設置
//#define TM1640MEDO_DISPLAY  0x88   //宏定義 亮度  最小
//#define TM1640MEDO_DISPLAY  0x89   //宏定義 亮度
//#define TM1640MEDO_DISPLAY  0x8a   //宏定義 亮度
//#define TM1640MEDO_DISPLAY  0x8b   //宏定義 亮度
#define TM1640MEDO_DISPLAY  0x8c   //宏定義 亮度(推薦)
//#define TM1640MEDO_DISPLAY  0x8d   //宏定義 亮度
//#define TM1640MEDO_DISPLAY  0x8f   //宏定義 亮度 最大

#define TM1640MEDO_DISPLAY_OFF  0x80   //宏定義 亮度 關



void TM1640_start(){ //通信時序 啟始(基礎GPIO操作)(低層)
        GPIO_WriteBit(TM1640_GPIOPORT,TM1640_DIN,(BitAction)(1)); //接口輸出高電平1       
        GPIO_WriteBit(TM1640_GPIOPORT,TM1640_SCLK,(BitAction)(1)); //接口輸出高電平1       
        delay_us(DEL);
        GPIO_WriteBit(TM1640_GPIOPORT,TM1640_DIN,(BitAction)(0)); //接口輸出0       
        delay_us(DEL);
        GPIO_WriteBit(TM1640_GPIOPORT,TM1640_SCLK,(BitAction)(0)); //接口輸出0       
        delay_us(DEL);
}
void TM1640_stop(){ //通信時序 結束(基礎GPIO操作)(低層)
        GPIO_WriteBit(TM1640_GPIOPORT,TM1640_DIN,(BitAction)(0)); //接口輸出0       
        GPIO_WriteBit(TM1640_GPIOPORT,TM1640_SCLK,(BitAction)(1)); //接口輸出高電平1       
        delay_us(DEL);
        GPIO_WriteBit(TM1640_GPIOPORT,TM1640_DIN,(BitAction)(1)); //接口輸出高電平1       
        delay_us(DEL);
}
void TM1640_write(u8 date){        //寫數據(低層)
        u8 i;
        u8 aa;
        aa=date;
        GPIO_WriteBit(TM1640_GPIOPORT,TM1640_DIN,(BitAction)(0)); //接口輸出0       
        GPIO_WriteBit(TM1640_GPIOPORT,TM1640_SCLK,(BitAction)(0)); //接口輸出0       
        for(i=0;i<8;i++){
                GPIO_WriteBit(TM1640_GPIOPORT,TM1640_SCLK,(BitAction)(0)); //接口輸出0       
                delay_us(DEL);

                if(aa&0x01){
                        GPIO_WriteBit(TM1640_GPIOPORT,TM1640_DIN,(BitAction)(1)); //接口輸出高電平1       
                        delay_us(DEL);
                }else{
                        GPIO_WriteBit(TM1640_GPIOPORT,TM1640_DIN,(BitAction)(0)); //接口輸出0       
                        delay_us(DEL);
                }
                GPIO_WriteBit(TM1640_GPIOPORT,TM1640_SCLK,(BitAction)(1)); //接口輸出高電平1       
                delay_us(DEL);
                aa=aa>>1;
   }
        GPIO_WriteBit(TM1640_GPIOPORT,TM1640_DIN,(BitAction)(0)); //接口輸出0       
        GPIO_WriteBit(TM1640_GPIOPORT,TM1640_SCLK,(BitAction)(0)); //接口輸出0       
}

void TM1640_Init(void){ //TM1640接口初始化
        GPIO_InitTypeDef  GPIO_InitStructure;        
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC,ENABLE);      
    GPIO_InitStructure.GPIO_Pin = TM1640_DIN | TM1640_SCLK; //選擇端口號(0~15或all)                        
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //選擇IO接口工作方式      
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //設置IO接口速度(2/10/50MHz)   
        GPIO_Init(TM1640_GPIOPORT, &GPIO_InitStructure);

        GPIO_WriteBit(TM1640_GPIOPORT,TM1640_DIN,(BitAction)(1)); //接口輸出高電平1       
        GPIO_WriteBit(TM1640_GPIOPORT,TM1640_SCLK,(BitAction)(1)); //接口輸出高電平1       
        TM1640_start();
        TM1640_write(TM1640MEDO_ADD); //設置數據,0x40,0x44分別對應地址自動加一和固定地址模式
        TM1640_stop();
        TM1640_start();
        TM1640_write(TM1640MEDO_DISPLAY); //控制顯示,開顯示,0x88,  0x89,  0x8a,  0x8b,  0x8c,  0x8d,  0x8e,  0x8f分別對應脈沖寬度為:
                                                                           //------------------1/16,  2/16,  4/16,  10/16, 11/16, 12/16, 13/16, 14/16         //0x80關顯示
        TM1640_stop();       
                               
}
void TM1640_led(u8 date){ //固定地址模式的顯示輸出8個LED控制
   TM1640_start();
   TM1640_write(TM1640_LEDPORT);                //傳顯示數據對應的地址
   TM1640_write(date);        //傳1BYTE顯示數據
   TM1640_stop();
}
void TM1640_display(u8 address,u8 date){ //固定地址模式的顯示輸出
        const u8 buff[21]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef,0x00};//數字0~9及0~9加點顯示段碼表
    //---------------   0    1    2    3    4    5    6    7    8    9    0.   1.   2.   3.   4.   5.   6.   7.   8.   9.   無   
   TM1640_start();
   TM1640_write(0xC0+address);                 //傳顯示數據對應的地址
   TM1640_write(buff[date]);                                 //傳1BYTE顯示數據
   TM1640_stop();
}
void TM1640_display_add(u8 address,u8 date){        //地址自動加一模式的顯示輸出
        u8 i;
        const u8 buff[21]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef,0x00};//數字0~9及0~9加點顯示段碼表
    //---------------   0    1    2    3    4    5    6    7    8    9    0.   1.   2.   3.   4.   5.   6.   7.   8.   9.   無   
  TM1640_start();
   TM1640_write(0xC0+address);                 //設置起始地址
   for(i=0;i<16;i++){
      TM1640_write(buff[date]);
   }
   TM1640_stop();
}


作者: admin    時間: 2018-12-15 15:13
補全頭文件原理圖詳細說明一下電路連接即可獲得100+黑幣




歡迎光臨 (http://m.raoushi.com/bbs/) Powered by Discuz! X3.1