SMART CLEO Uart Text Lcd

Committer:
SMART_CLEO
Date:
Thu Sep 28 03:42:07 2017 +0000
Revision:
0:21b4d8237564
Child:
1:d05971975fdc
SMART_CLEO

Who changed what in which revision?

UserRevisionLine numberNew contents of line
SMART_CLEO 0:21b4d8237564 1 #include "mbed.h"
SMART_CLEO 0:21b4d8237564 2 #include "TextLCD.h"
SMART_CLEO 0:21b4d8237564 3
SMART_CLEO 0:21b4d8237564 4 struct UART_buf
SMART_CLEO 0:21b4d8237564 5 {
SMART_CLEO 0:21b4d8237564 6 uint8_t STA;
SMART_CLEO 0:21b4d8237564 7 uint8_t MODE;
SMART_CLEO 0:21b4d8237564 8 uint8_t CMD;
SMART_CLEO 0:21b4d8237564 9 uint8_t LEN;
SMART_CLEO 0:21b4d8237564 10 uint8_t DATA[32];
SMART_CLEO 0:21b4d8237564 11 uint8_t END;
SMART_CLEO 0:21b4d8237564 12 };
SMART_CLEO 0:21b4d8237564 13
SMART_CLEO 0:21b4d8237564 14 // rs, rw, e, d0-d3
SMART_CLEO 0:21b4d8237564 15 TextLCD lcd(PB_12, PB_13, PB_14, PB_15, PA_9, PA_10, PA_11);
SMART_CLEO 0:21b4d8237564 16
SMART_CLEO 0:21b4d8237564 17 Serial SerialUART(PA_2, PA_3);
SMART_CLEO 0:21b4d8237564 18
SMART_CLEO 0:21b4d8237564 19 UART_buf RX_BUF;
SMART_CLEO 0:21b4d8237564 20
SMART_CLEO 0:21b4d8237564 21 void SerialUARTRX_ISR(void);
SMART_CLEO 0:21b4d8237564 22 void LCD_printf(uint8_t *data, uint8_t len);
SMART_CLEO 0:21b4d8237564 23
SMART_CLEO 0:21b4d8237564 24 int main() {
SMART_CLEO 0:21b4d8237564 25
SMART_CLEO 0:21b4d8237564 26 uint8_t ab[3] = {1, 2, 3};
SMART_CLEO 0:21b4d8237564 27 SerialUART.baud(115200);
SMART_CLEO 0:21b4d8237564 28
SMART_CLEO 0:21b4d8237564 29 SerialUART.attach(&SerialUARTRX_ISR);
SMART_CLEO 0:21b4d8237564 30
SMART_CLEO 0:21b4d8237564 31 LCD_printf(ab, 3);
SMART_CLEO 0:21b4d8237564 32 while(1)
SMART_CLEO 0:21b4d8237564 33 {
SMART_CLEO 0:21b4d8237564 34 }
SMART_CLEO 0:21b4d8237564 35 }
SMART_CLEO 0:21b4d8237564 36
SMART_CLEO 0:21b4d8237564 37 void SerialUARTRX_ISR(void)
SMART_CLEO 0:21b4d8237564 38 {
SMART_CLEO 0:21b4d8237564 39 static uint8_t RX_count = 0, RX_Len = 32, RX_Status = 0;
SMART_CLEO 0:21b4d8237564 40 uint8_t rx_da = SerialUART.getc();
SMART_CLEO 0:21b4d8237564 41 switch(RX_Status)
SMART_CLEO 0:21b4d8237564 42 {
SMART_CLEO 0:21b4d8237564 43 case 0:
SMART_CLEO 0:21b4d8237564 44 if(rx_da == 0x76)
SMART_CLEO 0:21b4d8237564 45 {
SMART_CLEO 0:21b4d8237564 46 RX_BUF.STA = rx_da;
SMART_CLEO 0:21b4d8237564 47 RX_Status++;
SMART_CLEO 0:21b4d8237564 48 }
SMART_CLEO 0:21b4d8237564 49 break;
SMART_CLEO 0:21b4d8237564 50 case 1:
SMART_CLEO 0:21b4d8237564 51 RX_BUF.MODE = rx_da;
SMART_CLEO 0:21b4d8237564 52 RX_Status++;
SMART_CLEO 0:21b4d8237564 53 break;
SMART_CLEO 0:21b4d8237564 54 case 2:
SMART_CLEO 0:21b4d8237564 55 RX_BUF.CMD = rx_da;
SMART_CLEO 0:21b4d8237564 56 RX_Status++;
SMART_CLEO 0:21b4d8237564 57 break;
SMART_CLEO 0:21b4d8237564 58 case 3:
SMART_CLEO 0:21b4d8237564 59 RX_BUF.LEN = rx_da;
SMART_CLEO 0:21b4d8237564 60 RX_Len = RX_BUF.LEN;
SMART_CLEO 0:21b4d8237564 61 RX_Status++;
SMART_CLEO 0:21b4d8237564 62 if(RX_Len == 0)
SMART_CLEO 0:21b4d8237564 63 RX_Status++;
SMART_CLEO 0:21b4d8237564 64 break;
SMART_CLEO 0:21b4d8237564 65 case 4:
SMART_CLEO 0:21b4d8237564 66 RX_BUF.DATA[RX_count] = rx_da;
SMART_CLEO 0:21b4d8237564 67 RX_count++;
SMART_CLEO 0:21b4d8237564 68 if(RX_count == RX_Len)
SMART_CLEO 0:21b4d8237564 69 {
SMART_CLEO 0:21b4d8237564 70 RX_Status++;
SMART_CLEO 0:21b4d8237564 71 RX_count = 0;
SMART_CLEO 0:21b4d8237564 72 RX_Len = 32;
SMART_CLEO 0:21b4d8237564 73 }
SMART_CLEO 0:21b4d8237564 74 break;
SMART_CLEO 0:21b4d8237564 75 case 5:
SMART_CLEO 0:21b4d8237564 76 if(rx_da == 0x3E)
SMART_CLEO 0:21b4d8237564 77 {
SMART_CLEO 0:21b4d8237564 78 RX_BUF.END = rx_da;
SMART_CLEO 0:21b4d8237564 79 RX_Status = 0;
SMART_CLEO 0:21b4d8237564 80 switch(RX_BUF.MODE)
SMART_CLEO 0:21b4d8237564 81 {
SMART_CLEO 0:21b4d8237564 82 case 0x01:
SMART_CLEO 0:21b4d8237564 83 if(RX_BUF.CMD == 0x18)
SMART_CLEO 0:21b4d8237564 84 {
SMART_CLEO 0:21b4d8237564 85 LCD_printf(&RX_BUF.DATA[0], RX_BUF.LEN);
SMART_CLEO 0:21b4d8237564 86 }
SMART_CLEO 0:21b4d8237564 87 break;
SMART_CLEO 0:21b4d8237564 88 }
SMART_CLEO 0:21b4d8237564 89 }
SMART_CLEO 0:21b4d8237564 90 break;
SMART_CLEO 0:21b4d8237564 91 }
SMART_CLEO 0:21b4d8237564 92 }
SMART_CLEO 0:21b4d8237564 93
SMART_CLEO 0:21b4d8237564 94 void LCD_printf(uint8_t *data, uint8_t len)
SMART_CLEO 0:21b4d8237564 95 {
SMART_CLEO 0:21b4d8237564 96 char buf[32];
SMART_CLEO 0:21b4d8237564 97 for(int i=0; i<32; i++)
SMART_CLEO 0:21b4d8237564 98 {
SMART_CLEO 0:21b4d8237564 99 if(i<len)
SMART_CLEO 0:21b4d8237564 100 buf[i] = data[i];
SMART_CLEO 0:21b4d8237564 101 else
SMART_CLEO 0:21b4d8237564 102 buf[i] = 0x20;
SMART_CLEO 0:21b4d8237564 103 }
SMART_CLEO 0:21b4d8237564 104 lcd.locate(0, 0);
SMART_CLEO 0:21b4d8237564 105 lcd.printf(buf);
SMART_CLEO 0:21b4d8237564 106 }