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

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

QQ登錄

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

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

51單片機(jī)的一個(gè)多線程編程模型

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:88762 發(fā)表于 2021-10-28 18:14 | 只看該作者 |只看大圖 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
Protothread 一個(gè)非常巧妙的輪詢式多線程模型,也是 contiki 系統(tǒng)的內(nèi)核,uip 和 lwip 作者 adam 的杰作

proteus8.12.SP0 居然都支持 STC 51 單片機(jī)和 STM32 模擬了。。可以去百度下載

常見(jiàn)問(wèn)題:
一、proteus 8.12_sp0和proteus_8.9sp2存在相同的問(wèn)題,如果安裝在非C盤目錄下,打開(kāi)后則會(huì)顯示密鑰錯(cuò)誤和未注冊(cè)的灰色字體;點(diǎn)擊幫助后也是未注冊(cè)。
這是因?yàn)槠平馄髂J(rèn)是你安裝在C盤。
解決方法如下:
[1]、卸載后重裝在C盤
[2]、1.先在C盤安裝,破解.
        2.打開(kāi)軟件,發(fā)現(xiàn)有注冊(cè)信息,則注冊(cè)成功
        3.此時(shí)軟件復(fù)制根目錄的bin文件夾。
        4.卸載剛才安裝的proteus
        注意:不要用第三方的卸載軟件,在控制面版里卸載就行,更不要用everything之類的把殘余文件刪的干干凈凈
        5.重新安裝,選擇D盤。破解
        6.把剛才復(fù)制bin文件夾覆蓋到D盤軟件的根目錄下,選擇全部替換
        7.再打開(kāi)proteus就顯示注冊(cè)成功了
-- 雖然有點(diǎn)脫褲子放屁的感覺(jué),但能用就行


Protesu 仿真測(cè)試,兩個(gè)線程控制 LED 閃爍,另外還有 mutex timer 等,可以參考 contiki 的內(nèi)核實(shí)現(xiàn)。



示例工程:
STCxx_Projects.rar (169.57 KB, 下載次數(shù): 17)

單片機(jī)源程序如下:
  1. /**
  2.   ******************************************************************************
  3.   * @file    main.c
  4.   * @author  Iron
  5.   * @date    2021-01-01
  6.   * @version v1.0
  7.   * @brief   main c file
  8.   */

  9. /* Private includes ----------------------------------------------------------*/
  10. #include "board.h"
  11. #include "pt.h"
  12. #include "delay.h"

  13. /* Private define ------------------------------------------------------------*/
  14. /* Private macro -------------------------------------------------------------*/
  15. /* Private typedef -----------------------------------------------------------*/
  16. /* Private variables ---------------------------------------------------------*/

  17. /* Two flags that the two protothread functions use. */
  18. static int protothread1_flag, protothread2_flag;

  19. /* Private function prototypes -----------------------------------------------*/


  20. /**
  21. * The first protothread function. A protothread function must always
  22. * return an integer, but must never explicitly return - returning is
  23. * performed inside the protothread statements.
  24. *
  25. * The protothread function is driven by the main loop further down in
  26. * the code.
  27. */
  28. static int protothread1(struct pt *pt)
  29. {
  30.     /* A protothread function must begin with PT_BEGIN() which takes a
  31.        pointer to a struct pt. */
  32.     PT_BEGIN(pt);

  33.     /* We loop forever here. */
  34.     while (1)
  35.     {
  36.         /* Wait until the other protothread has set its flag. */
  37.         PT_WAIT_UNTIL(pt, protothread2_flag != 0);

  38.         /* thread code... */
  39.         led_togger(LED0);
  40.         delay_ms(100);

  41.         /* We then reset the other protothread's flag, and set our own
  42.            flag so that the other protothread can run. */
  43.         protothread2_flag = 0;
  44.         protothread1_flag = 1;

  45.         /* And we loop. */
  46.     }

  47.     /* All protothread functions must end with PT_END() which takes a
  48.        pointer to a struct pt. */
  49.     PT_END(pt);
  50. }

  51. /**
  52. * The second protothread function. This is almost the same as the
  53. * first one.
  54. */
  55. static int protothread2(struct pt *pt)
  56. {
  57.     PT_BEGIN(pt);

  58.     while (1)
  59.     {
  60.         /* Let the other protothread run. */
  61.         protothread2_flag = 1;

  62.         /* Wait until the other protothread has set its flag. */
  63.         PT_WAIT_UNTIL(pt, protothread1_flag != 0);

  64.         /* thread code... */
  65.         led_togger(LED1);
  66.         delay_ms(100);

  67.         /* We then reset the other protothread's flag. */
  68.         protothread1_flag = 0;

  69.         /* And we loop. */
  70.     }
  71.     PT_END(pt);
  72. }


  73. /**
  74. * Finally, we have the main loop. Here is where the protothreads are
  75. * initialized and scheduled. First, however, we define the
  76. * protothread state variables pt1 and pt2, which hold the state of
  77. * the two protothreads.
  78. */
  79. static struct pt pt1, pt2;

  80. int main(void)
  81. {
  82.     board_init();

  83.     /* Initialize the protothread state variables with PT_INIT(). */
  84.     PT_INIT(&pt1);
  85.     PT_INIT(&pt2);

  86.     /*
  87.      * Then we schedule the two protothreads by repeatedly calling their
  88.      * protothread functions and passing a pointer to the protothread
  89.      * state variables as arguments.
  90.      */
  91.     while (1)
  92.     {
  93.         protothread1(&pt1);
  94.         protothread2(&pt2);
  95.     }
  96. }

  97. /**
  98.   * @}
  99.   */

  100. /******************* (C)COPYRIGHT 2021 ***** END OF FILE *********************/

復(fù)制代碼



評(píng)分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏4 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:646477 發(fā)表于 2021-10-29 18:39 | 只看該作者
贊一個(gè),Protothread 用了幾年了,大大小小的項(xiàng)目,感覺(jué)都比較不錯(cuò)。除非有搶占式的需求,才會(huì)用上RTOS,總體來(lái)說(shuō),還是對(duì)它比較親切
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 日韩欧美一区二区三区免费观看 | 日韩一二区 | 亚洲字幕在线观看 | 欧美黑人巨大videos精品 | 亚洲一区不卡 | 日本粉嫩一区二区三区视频 | 亚洲综合大片69999 | 日日摸日日碰夜夜爽亚洲精品蜜乳 | 免费一级做a爰片久久毛片潮喷 | 色先锋影音 | 久草欧美视频 | 日韩欧美三级电影 | 亚洲成人一二区 | 91tv在线观看| av网站免费观看 | 日韩精品一区二区三区免费观看 | 成人免费视频7777777 | 完全免费在线视频 | 日韩欧美一区二区三区 | www.黄色网| 97精品超碰一区二区三区 | 国产欧美精品一区二区 | 日本二区在线观看 | 蜜臀久久99精品久久久久野外 | 91精品国产一区二区三区 | 九九久久国产精品 | 日韩一区在线视频 | 久久久精品一区二区 | 黄色大片免费播放 | 日韩精品在线看 | 老子午夜影院 | 久久av影院 | 国产精品久久亚洲7777 | 日本免费视频在线观看 | 日本一区二区在线视频 | 美女网站视频免费黄 | 一区二区三区高清在线观看 | 国产一级影片 | 搞黄网站在线观看 | 国产日韩视频在线 | 国产精品久久久久久婷婷天堂 |