|
刚刚看protothreads,各位帮忙说说,这个东西到底有啥优点啊?
我写了个程序,不知道这样用有没有意义?
程序功能:每隔1秒亮灭一次D口LED
每隔10秒亮灭一次b口LED
#include"pt.h"
#include"avr/io.h"
#include"util/delay.h"
static int protothread1_flag, protothread2_flag,counter,counter1;
static int
protothread1(struct pt *pt)
{
PT_BEGIN(pt);
while(1) {
PT_WAIT_UNTIL(pt, counter==1);
PORTD=~PORTD;
counter=0;
}
PT_END(pt);
}
static int
protothread2(struct pt *pt)
{
PT_BEGIN(pt);
while(1) {
protothread2_flag = 1;
PT_WAIT_UNTIL(pt, counter1==10);
counter1=0;
PORTB = ~PORTB;
protothread1_flag = 0;
}
PT_END(pt);
}
static struct pt pt1, pt2;
int
main(void)
{
DDRD =0XFF;
DDRB =0XFF;
PORTD=0XFF;
PORTB=0XFF;
/* 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);
_delay_ms(1000);
counter++;
counter1++;
}
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
|