Instructions

361 C-Control Pro IDE
© 2013 Conrad Electronic
5.25.11 Thread Example
// demo program of multithreading
// this program makes no debouncing, therefore a short trigger of the switch
// can lead to more than one string outputs
#thread 0, 0, 10 //main thread with task change every 10 * 10ms =100ms
#thread 1, 128, 10 //thread 1 with 128 Byte & task change 10*10ms =100ms
void thread1(void)
{
while(true) // endless loop
{
if(!Port_ReadBit(PORT_SW2)) Msg_WriteText("Switch 2"); // SW2 is pressed
}
}
void main(void)
{
#ifdef AVR32
// set noth Pin to input & pull-up
Port_Attribute(PORT_T1, PORT_ATTR_INPUT | PORT_ATTR_PULL_UP);
Port_Attribute(PORT_T2, PORT_ATTR_INPUT | PORT_ATTR_PULL_UP);
#else
Port_DataDirBit(PORT_SW1, PORT_IN); // set Pin to input
Port_DataDirBit(PORT_SW2, PORT_IN); // set Pin to input
Port_WriteBit(PORT_SW1, 1); // set pull-up
Port_WriteBit(PORT_SW1, 1); // set pull-up
#endif
Thread_Start(1,thread1); // start new Thread
while(true) // endless loop
{
if(!Port_ReadBit(PORT_SW1)) Msg_WriteText("Switch 1");// SW1 is pressed
}
}
5.25.12 Thread Example 2
// multithread2: multithreading with Thread_Delay()
// necessary library: IntFunc_Lib.cc
#thread 0, 0, 10 //main thread with task change every 10 * 10ms =100ms
#thread 1, 128, 10 //thread 1 with 128 Byte & task change 10*10ms =100ms
void thread1(void)
{
while(true)
{
Msg_WriteText("Thread2"); Thread_Delay(200);
} // "Thread2" is displayed