|
proteus+stm32+tm1637顯示仿真,仿真時數(shù)碼管刷新率太低,數(shù)字一位一位顯示,哪位高手改進一下。
0.png (12.81 KB, 下載次數(shù): 76)
下載附件
2019-9-22 16:22 上傳
單片機源程序如下:
- #include "TM1640.h"
- #include "delay.h"
- #define DEL 1 //宏定義 通信速率(默認為1,如不能通信可加大數(shù)值)
- //地址模式的設(shè)置
- //#define TM1640MEDO_ADD 0x40 //宏定義 自動加一模式
- #define TM1640MEDO_ADD 0x44 //宏定義 固定地址模式(推薦)
- //顯示亮度的設(shè)置
- //#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 //宏定義 亮度 關(guān)
- void TM1640_start(){ //通信時序 啟始(基礎(chǔ)GPIO操作)(低層)
- DIO_1;
- delay_us(DEL);
- CLK_1 ;
- delay_us(DEL);
- DIO_0;
- delay_us(DEL);
- CLK_0 ;
- delay_us(DEL);
- }
- void TM1640_stop(){ //通信時序 結(jié)束(基礎(chǔ)GPIO操作)(低層)
- CLK_0 ;
- delay_us(DEL);
- DIO_0;
- delay_us(DEL);
- CLK_1 ;
- delay_us(DEL);
- DIO_1;
- delay_us(DEL);
- }
- void TM1640_write(u8 date){ //寫數(shù)據(jù)(低層)
- 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++){
- CLK_0 ;
- delay_us(DEL);
- if(aa&0x01){
- DIO_1;
- delay_us(DEL);
- }else{
- DIO_0;
- delay_us(DEL);
- }
- CLK_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
-
-
- CLK_0 ;
- delay_us(DEL);
- // DIO_1;
- // delay_us(DEL);
- CLK_1 ;
- delay_us(DEL);
- while(GPIO_ReadInputDataBit(TM1640_GPIOPORT ,TM1640_DIN) == 0x01);
- //delay_us(DEL);delay_us(DEL);delay_us(DEL);delay_us(DEL);delay_us(DEL);delay_us(DEL);delay_us(DEL);
- }
- 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; //設(shè)置IO接口速度(2/10/50MHz)
- GPIO_Init(TM1640_GPIOPORT, &GPIO_InitStructure);
- DIO_1; //接口輸出高電平1
- CLK_1 ; //接口輸出高電平1
- TM1640_start();
- TM1640_write(TM1640MEDO_ADD); //設(shè)置數(shù)據(jù),0x40,0x44分別對應(yīng)地址自動加一和固定地址模式
- TM1640_stop();
- TM1640_start();
- TM1640_write(TM1640MEDO_DISPLAY); //控制顯示,開顯示,0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f分別對應(yīng)脈沖寬度為:
- //------------------1/16, 2/16, 4/16, 10/16, 11/16, 12/16, 13/16, 14/16 //0x80關(guān)顯示
- TM1640_stop();
-
- }
- void TM1640_display(u8 address,u8 date){ //固定地址模式的顯示輸出
- const u8 buff[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//,0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef,0x00};//數(shù)字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); //傳顯示數(shù)據(jù)對應(yīng)的地址
- TM1640_write(buff[date]); //傳1BYTE顯示數(shù)據(jù)
- 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};//數(shù)字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); //設(shè)置起始地址
- for(i=0;i<4;i++){
- TM1640_write(buff[date]);
- }
- TM1640_stop();
- }
- /*********************************************************************************************
- * 杜洋工作室
- * 洋桃電子
- *********************************************************************************************/
復(fù)制代碼
所有資料51hei提供下載:
數(shù)碼管顯示程序.zip
(368.59 KB, 下載次數(shù): 246)
2019-9-22 10:48 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|
評分
-
查看全部評分
|