Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 3 months ago.
Problem with the mbed RTOS
Can somebody tell me why LCD_thread is undefined in the LCDtime function and how to fix that?
#include "mbed.h"
#include "rtos.h"
#include "TextLCD.h"
#define LCDsignal 0x01
TextLCD lcd(PB_12, PA_11, PA_12, PC_5, PC_6, PC_8); // rs, e, d4-d7
void LCD_handler (void const *args)
{
uint16_t i=0;
while(1)
{
lcd.cls();
lcd.printf("hello world %i",i);
i++;
Thread::signal_wait(LCDsignal);
}
}
void LCDtime(void const *args)
{
LCD_thread.signal_set(LCDsignal);
}
int main()
{
Thread LCD_thread(LCD_handler);
RtosTimer LCDtimer(LCDtime, osTimerPeriodic, (void *)0);
LCDtimer.start(2000);
Thread::wait(osWaitForever);
}
1 Answer
11 years, 3 months ago.
LCD_thread is defined within main. That means it's only visible within main.
If you want it to be visible to all functions within the file then you need to make it a global variable by defining it outside of any functions. e.g.
#include "mbed.h"
#include "rtos.h"
#include "TextLCD.h"
#define LCDsignal 0x01
TextLCD lcd(PB_12, PA_11, PA_12, PC_5, PC_6, PC_8); // rs, e, d4-d7
void LCD_handler (void const *args)
{
uint16_t i=0;
while(1)
{
lcd.cls();
lcd.printf("hello world %i",i);
i++;
Thread::signal_wait(LCDsignal);
}
}
void LCDtime(void const *args)
{
LCD_thread.signal_set(LCDsignal);
}
Thread LCD_thread(LCD_handler);
int main()
{
RtosTimer LCDtimer(LCDtime, osTimerPeriodic, (void *)0);
LCDtimer.start(2000);
Thread::wait(osWaitForever);
}