亚洲春色中文字幕久久久-三上亚,91精品国产亚一区二区三区,久久久九色综合亚洲成色777,涩涩视频下载,国产午夜亚洲精品午夜鲁丝片,国产精品A一区二区三区腾讯导航,影音先锋色情AV在线看片,蜜臀国产在线视频,极品少妇高潮啪啪无码吴梦梦 ,精品人妻无码一区二区三区手机版

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 1008|回復(fù): 2
打印 上一主題 下一主題
收起左側(cè)

請(qǐng)?jiān)敿?xì)講解一下不同時(shí)鐘下延時(shí)、定時(shí)自適配問(wèn)題

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:33548 發(fā)表于 2025-8-27 21:39 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
請(qǐng)高手們?cè)敿?xì)講解一下,STC單片機(jī),在不同時(shí)鐘頻率下,不用改代碼,有關(guān)延時(shí)函數(shù)、定時(shí)時(shí)間、波特率等自適配問(wèn)題,代碼怎么寫?最好出一期詳細(xì)的視頻講解。
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:1073939 發(fā)表于 2025-8-29 16:11 | 只看該作者
本帖最后由 ydatou 于 2025-8-30 08:48 編輯

我的做法·是定義3個(gè)常量。
系統(tǒng)時(shí)鐘頻率
指令機(jī)器周期數(shù)
定時(shí)器機(jī)器周期數(shù)
有了這3個(gè)常量可以適配任何51mcu,不用改代碼,只改這3個(gè)常量。
下面的配置是十速的51mcu。
  1. #define FOSC                7.3728//11.0592        //
  2. #define MACHINE_NUM 2                //定時(shí)器
  3. #define M_NUM       2                //程序  SH88F2051 程序是1T,定時(shí)器1T/12T可選
  4. #define COVERT(T) ( (T*FOSC+M_NUM) / (M_NUM*2) -1 )

  5. #define _COUNT_560uS_ ((uint16)(-560L*FOSC/MACHINE_NUM))//560uS
  6.         #define _COUNT_560uS_LO        (_COUNT_560uS_ & 0x00FF)
  7.         #define _COUNT_560uS_HI        (_COUNT_560uS_ >> 8)
  8. #define _COUNT_1mS_ ((uint16)(-1000L*FOSC/MACHINE_NUM))//1000uS
  9.         #define _COUNT_1mS_LO        (_COUNT_1mS_ & 0x00FF)
  10.         #define _COUNT_1mS_HI        (_COUNT_1mS_ >> 8)

  11. #define DELAY_uS(DlyTime) do{uint8 nCount;nCount=MIN(MAX(COVERT(DlyTime),1),256);do{}while(--nCount);}while(0)
  12.         //Note:實(shí)際延時(shí)效果C51                12M         4<= DlyTime <= 514(uS)
  13.         //Note:實(shí)際延時(shí)效果88F54        16.6M        1<= DlyTime <= 31(uS)
  14. //#if (M_NUM==1)
  15. //        #define delay_1mS() do{ uint8 x=30; do{ DELAY_uS(33.0); }while(--x);        }while(0)
  16. //#else
  17. //        #if(M_NUM==12)
  18. //                #define delay_1mS() do{ DELAY_uS(333.0);DELAY_uS(333.0); DELAY_uS(333.0); }while(0)
  19. //        #else
  20. //                #define delay_1mS() do{ uint8 x=10; do{ DELAY_uS(99.0); }while(--x); }while(0)
  21. //        #endif
  22. //#endif
  23. //#define delay_mS(mSEC) do{uint16 ms=mSEC; do{delay_1mS();WDT_reset();T2CON=0x04;}while(--ms);                }while(0)
復(fù)制代碼




回復(fù)

使用道具 舉報(bào)

板凳
ID:1133081 發(fā)表于 2025-8-29 22:14 | 只看該作者
  1. /*********************************************
  2.    程序名稱:延時(shí)函數(shù)
  3. *********************************************/

  4. //#define MAIN_Fosc 48000000L        //定義主時(shí)鐘
  5. //#define MAIN_Fosc 44236800L        //定義主時(shí)鐘
  6. //#define MAIN_Fosc 40000000L        //定義主時(shí)鐘
  7. //#define MAIN_Fosc 36864000L        //定義主時(shí)鐘
  8. //#define MAIN_Fosc 35000000L        //定義主時(shí)鐘
  9. //#define MAIN_Fosc 33177600L        //定義主時(shí)鐘
  10. //#define MAIN_Fosc 30000000L        //定義主時(shí)鐘
  11. //#define MAIN_Fosc 27000000L        //定義主時(shí)鐘
  12. //#define MAIN_Fosc 24000000L        //定義主時(shí)鐘
  13. //#define MAIN_Fosc 22118400L        //定義主時(shí)鐘
  14. //#define MAIN_Fosc 20000000L        //定義主時(shí)鐘
  15. //#define MAIN_Fosc 18432000L        //定義主時(shí)鐘
  16. #define MAIN_Fosc 12000000L        //定義主時(shí)鐘
  17. //#define MAIN_Fosc 11059200L        //定義主時(shí)鐘
  18. //#define MAIN_Fosc 6000000L        //定義主時(shí)鐘
  19. //#define MAIN_Fosc 5529600L        //定義主時(shí)鐘

  20. void Delay(unsigned int ms)//注:ms_max=65536
  21. {
  22.         unsigned int i;
  23.         do
  24.         {
  25. //                i=MAIN_Fosc/96000L; //STC89_12T
  26. //                i=MAIN_Fosc/48000L; //STC89_6T
  27. //                i=MAIN_Fosc/14000;  //STC12
  28. //                i=MAIN_Fosc/13000;  //STC15
  29.                 i=MAIN_Fosc/10000;  //STC8
  30. //                i=MAIN_Fosc/6030;   //STC32
  31.                 while(--i);
  32.         }
  33.         while(--ms);
  34. }
復(fù)制代碼
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表