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)。
STC15W_LED_Blink.gif (52.23 KB, 下載次數(shù): 40)
下載附件
2021-10-28 18:15 上傳
示例工程:
STCxx_Projects.rar
(169.57 KB, 下載次數(shù): 17)
2021-10-28 18:21 上傳
點(diǎn)擊文件名下載附件
pt-test 下載積分: 黑幣 -5
單片機(jī)源程序如下:
- /**
- ******************************************************************************
- * @file main.c
- * @author Iron
- * @date 2021-01-01
- * @version v1.0
- * @brief main c file
- */
- /* Private includes ----------------------------------------------------------*/
- #include "board.h"
- #include "pt.h"
- #include "delay.h"
- /* Private define ------------------------------------------------------------*/
- /* Private macro -------------------------------------------------------------*/
- /* Private typedef -----------------------------------------------------------*/
- /* Private variables ---------------------------------------------------------*/
- /* Two flags that the two protothread functions use. */
- static int protothread1_flag, protothread2_flag;
- /* Private function prototypes -----------------------------------------------*/
- /**
- * The first protothread function. A protothread function must always
- * return an integer, but must never explicitly return - returning is
- * performed inside the protothread statements.
- *
- * The protothread function is driven by the main loop further down in
- * the code.
- */
- static int protothread1(struct pt *pt)
- {
- /* A protothread function must begin with PT_BEGIN() which takes a
- pointer to a struct pt. */
- PT_BEGIN(pt);
- /* We loop forever here. */
- while (1)
- {
- /* Wait until the other protothread has set its flag. */
- PT_WAIT_UNTIL(pt, protothread2_flag != 0);
- /* thread code... */
- led_togger(LED0);
- delay_ms(100);
- /* We then reset the other protothread's flag, and set our own
- flag so that the other protothread can run. */
- protothread2_flag = 0;
- protothread1_flag = 1;
- /* And we loop. */
- }
- /* All protothread functions must end with PT_END() which takes a
- pointer to a struct pt. */
- PT_END(pt);
- }
- /**
- * The second protothread function. This is almost the same as the
- * first one.
- */
- static int protothread2(struct pt *pt)
- {
- PT_BEGIN(pt);
- while (1)
- {
- /* Let the other protothread run. */
- protothread2_flag = 1;
- /* Wait until the other protothread has set its flag. */
- PT_WAIT_UNTIL(pt, protothread1_flag != 0);
- /* thread code... */
- led_togger(LED1);
- delay_ms(100);
- /* We then reset the other protothread's flag. */
- protothread1_flag = 0;
- /* And we loop. */
- }
- PT_END(pt);
- }
- /**
- * Finally, we have the main loop. Here is where the protothreads are
- * initialized and scheduled. First, however, we define the
- * protothread state variables pt1 and pt2, which hold the state of
- * the two protothreads.
- */
- static struct pt pt1, pt2;
- int main(void)
- {
- board_init();
- /* Initialize the protothread state variables with PT_INIT(). */
- PT_INIT(&pt1);
- PT_INIT(&pt2);
- /*
- * Then we schedule the two protothreads by repeatedly calling their
- * protothread functions and passing a pointer to the protothread
- * state variables as arguments.
- */
- while (1)
- {
- protothread1(&pt1);
- protothread2(&pt2);
- }
- }
- /**
- * @}
- */
- /******************* (C)COPYRIGHT 2021 ***** END OF FILE *********************/
復(fù)制代碼
|