This demo uses the mbed RTOS to run eight threads (including main). The threads are using different I/O devices on the application board. Several of the threads output to the LCD and an OS mutex lock is used to control access to the LCD and make the LCD thread safe.

Dependencies:   C12832_lcd LCD_fonts mbed-rtos mbed

Fork of lab1 by Peter Drescher

Committer:
dreschpe
Date:
Mon Oct 15 21:48:28 2012 +0000
Revision:
0:f6a57b843f79
Child:
1:1c6a9eaf55b5
first test of the lcd driver

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dreschpe 0:f6a57b843f79 1 // example to test the mbed Lab Board lcd
dreschpe 0:f6a57b843f79 2
dreschpe 0:f6a57b843f79 3 #include "mbed.h"
dreschpe 0:f6a57b843f79 4 #include "rtos.h"
dreschpe 0:f6a57b843f79 5 #include "Small_6.h"
dreschpe 0:f6a57b843f79 6 #include "Small_7.h"
dreschpe 0:f6a57b843f79 7 #include "Arial_9.h"
dreschpe 0:f6a57b843f79 8 #include "stdio.h"
dreschpe 0:f6a57b843f79 9
dreschpe 0:f6a57b843f79 10
dreschpe 0:f6a57b843f79 11 Serial pc(USBTX, USBRX);
dreschpe 0:f6a57b843f79 12
dreschpe 0:f6a57b843f79 13 #include "C12832_lcd.h"
dreschpe 0:f6a57b843f79 14
dreschpe 0:f6a57b843f79 15 // LCD object
dreschpe 0:f6a57b843f79 16 C12832_LCD LCD("LCD");
dreschpe 0:f6a57b843f79 17
dreschpe 0:f6a57b843f79 18
dreschpe 0:f6a57b843f79 19
dreschpe 0:f6a57b843f79 20 // print data into first line and wait for 1s
dreschpe 0:f6a57b843f79 21 void thread1(void const *args)
dreschpe 0:f6a57b843f79 22 {
dreschpe 0:f6a57b843f79 23 int i;
dreschpe 0:f6a57b843f79 24 while(true) { // thread loop
dreschpe 0:f6a57b843f79 25 _lock
dreschpe 0:f6a57b843f79 26 LCD.locate(0,0);
dreschpe 0:f6a57b843f79 27 LCD.set_font((unsigned char*) Small_6);
dreschpe 0:f6a57b843f79 28 printf("Thread 1 count : %d",i);
dreschpe 0:f6a57b843f79 29 LCD.copy_to_lcd();
dreschpe 0:f6a57b843f79 30 _unlock
dreschpe 0:f6a57b843f79 31 i++;
dreschpe 0:f6a57b843f79 32 Thread::wait(1000);
dreschpe 0:f6a57b843f79 33 }
dreschpe 0:f6a57b843f79 34 }
dreschpe 0:f6a57b843f79 35
dreschpe 0:f6a57b843f79 36 // print data into third line and wait for 0,5s
dreschpe 0:f6a57b843f79 37 void thread2(void const *args)
dreschpe 0:f6a57b843f79 38 {
dreschpe 0:f6a57b843f79 39 int i;
dreschpe 0:f6a57b843f79 40 while(true) { // thread loop
dreschpe 0:f6a57b843f79 41 _lock
dreschpe 0:f6a57b843f79 42 LCD.locate(0,20);
dreschpe 0:f6a57b843f79 43 LCD.set_font((unsigned char*) Arial_9);
dreschpe 0:f6a57b843f79 44 printf("Thread 2 count : %d",i);
dreschpe 0:f6a57b843f79 45 LCD.copy_to_lcd();
dreschpe 0:f6a57b843f79 46 _unlock
dreschpe 0:f6a57b843f79 47 i++;
dreschpe 0:f6a57b843f79 48 Thread::wait(500);
dreschpe 0:f6a57b843f79 49 }
dreschpe 0:f6a57b843f79 50 }
dreschpe 0:f6a57b843f79 51
dreschpe 0:f6a57b843f79 52
dreschpe 0:f6a57b843f79 53
dreschpe 0:f6a57b843f79 54
dreschpe 0:f6a57b843f79 55 int main()
dreschpe 0:f6a57b843f79 56 {
dreschpe 0:f6a57b843f79 57 int j;
dreschpe 0:f6a57b843f79 58 pc.printf("Test LCD \n\r");
dreschpe 0:f6a57b843f79 59
dreschpe 0:f6a57b843f79 60 LCD.set_orientation(1);
dreschpe 0:f6a57b843f79 61 LCD.claim(stdout); // send stdout to the LCD display
dreschpe 0:f6a57b843f79 62
dreschpe 0:f6a57b843f79 63 // start thread1
dreschpe 0:f6a57b843f79 64 Thread t1(thread1);
dreschpe 0:f6a57b843f79 65 // start thread2
dreschpe 0:f6a57b843f79 66 Thread t2(thread2);
dreschpe 0:f6a57b843f79 67
dreschpe 0:f6a57b843f79 68 while(true) { // this is the third thread
dreschpe 0:f6a57b843f79 69 _lock
dreschpe 0:f6a57b843f79 70 LCD.locate(0,10);
dreschpe 0:f6a57b843f79 71 LCD.set_font((unsigned char*) Small_7);
dreschpe 0:f6a57b843f79 72 printf("Thread3 count : %d",j);
dreschpe 0:f6a57b843f79 73 LCD.copy_to_lcd();
dreschpe 0:f6a57b843f79 74 _unlock
dreschpe 0:f6a57b843f79 75 j++;
dreschpe 0:f6a57b843f79 76 Thread::wait(1500);
dreschpe 0:f6a57b843f79 77 }
dreschpe 0:f6a57b843f79 78
dreschpe 0:f6a57b843f79 79 }