Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed mbed-rtos ShiftOut
main.cpp
00001 #include "mbed.h" 00002 #include "rtos.h" 00003 #include "ShiftOut.h" // Ollie Milton, https://os.mbed.com/users/ollie8/code/ShiftOut/ 00004 00005 DigitalOut buzzer(D3); 00006 Serial pc(USBTX,USBRX); //UART via ST-Link 00007 00008 typedef uint32_t message_t; 00009 Queue <message_t, 4> queue; 00010 00011 void display_thread(void const *argument) 00012 { 00013 ShiftOut display(D7, D8, D4); // clk=D7, data=D8, latch=D4, 16) 00014 uint8_t segment_data[4] = {0xFF, 0xFF, 0xFF, 0xFF}; // A frissítendő szegmenskép 00015 /* Számjegyek (0 – 9) szegmensképe, negatív logikával */ 00016 const uint8_t SEGMENT_MAP[]= {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90}; 00017 /* Számjegy (1 - 4) kiválasztó jelek */ 00018 const uint8_t SEGMENT_SELECT[] = {0x01, 0x02, 0x04, 0x08}; 00019 uint8_t i, idx = 0; 00020 while (true) { 00021 osEvent evt = queue.get(0); // Check for a message without waiting 00022 switch(evt.status) { 00023 case osEventMessage: 00024 printf("osEventMessage = %#05x\n",evt.value.v); //message arrived 00025 int n = evt.value.v; 00026 segment_data[0] = SEGMENT_MAP[(n/1000) %10]; 00027 segment_data[1] = SEGMENT_MAP[(n/100) % 10]; 00028 segment_data[2] = SEGMENT_MAP[(n/10) % 10]; 00029 segment_data[3] = SEGMENT_MAP[n % 10]; 00030 break; 00031 case osOK: 00032 //--- pc.printf("osOK\n"); //no error, no message arrived 00033 i = idx++ & 0x03; 00034 display.write(segment_data[i]); 00035 display.write(SEGMENT_SELECT[i]); 00036 break; 00037 case osEventTimeout: 00038 pc.printf("osEventTimeout\n"); //timeout occurred 00039 break; 00040 case osErrorParameter: 00041 pc.printf("osErrorParameter\n"); 00042 break; //invalid parameter or is out of range. 00043 default: 00044 pc.printf("Unknown error flag: %#08x\n",(uint32_t)evt.status); 00045 break; 00046 }; 00047 Thread::wait(2); 00048 } 00049 } 00050 00051 int main (void) 00052 { 00053 uint16_t raw; 00054 Thread thread2(display_thread); 00055 pc.baud(115200); 00056 buzzer = true; 00057 while (true) { 00058 Thread::wait(1000); 00059 raw++; 00060 queue.put((message_t*)raw); 00061 } 00062 }
Generated on Wed Jul 20 2022 04:34:20 by
1.7.2