SMART CLEO Uart Text Lcd

Committer:
SMART_CLEO
Date:
Thu Sep 28 06:29:59 2017 +0000
Revision:
1:d05971975fdc
Parent:
0:21b4d8237564
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 1:d05971975fdc 19 volatile UART_buf RX_BUF;
SMART_CLEO 0:21b4d8237564 20
SMART_CLEO 0:21b4d8237564 21 void SerialUARTRX_ISR(void);
SMART_CLEO 0:21b4d8237564 22
SMART_CLEO 0:21b4d8237564 23 int main() {
SMART_CLEO 0:21b4d8237564 24
SMART_CLEO 0:21b4d8237564 25 SerialUART.baud(115200);
SMART_CLEO 0:21b4d8237564 26
SMART_CLEO 0:21b4d8237564 27 SerialUART.attach(&SerialUARTRX_ISR);
SMART_CLEO 1:d05971975fdc 28
SMART_CLEO 0:21b4d8237564 29 while(1)
SMART_CLEO 0:21b4d8237564 30 {
SMART_CLEO 0:21b4d8237564 31 }
SMART_CLEO 0:21b4d8237564 32 }
SMART_CLEO 0:21b4d8237564 33
SMART_CLEO 0:21b4d8237564 34 void SerialUARTRX_ISR(void)
SMART_CLEO 0:21b4d8237564 35 {
SMART_CLEO 0:21b4d8237564 36 static uint8_t RX_count = 0, RX_Len = 32, RX_Status = 0;
SMART_CLEO 0:21b4d8237564 37 uint8_t rx_da = SerialUART.getc();
SMART_CLEO 1:d05971975fdc 38 char buf[32];
SMART_CLEO 0:21b4d8237564 39 switch(RX_Status)
SMART_CLEO 0:21b4d8237564 40 {
SMART_CLEO 0:21b4d8237564 41 case 0:
SMART_CLEO 0:21b4d8237564 42 if(rx_da == 0x76)
SMART_CLEO 0:21b4d8237564 43 {
SMART_CLEO 0:21b4d8237564 44 RX_BUF.STA = rx_da;
SMART_CLEO 0:21b4d8237564 45 RX_Status++;
SMART_CLEO 0:21b4d8237564 46 }
SMART_CLEO 0:21b4d8237564 47 break;
SMART_CLEO 0:21b4d8237564 48 case 1:
SMART_CLEO 0:21b4d8237564 49 RX_BUF.MODE = rx_da;
SMART_CLEO 0:21b4d8237564 50 RX_Status++;
SMART_CLEO 0:21b4d8237564 51 break;
SMART_CLEO 0:21b4d8237564 52 case 2:
SMART_CLEO 0:21b4d8237564 53 RX_BUF.CMD = rx_da;
SMART_CLEO 0:21b4d8237564 54 RX_Status++;
SMART_CLEO 0:21b4d8237564 55 break;
SMART_CLEO 0:21b4d8237564 56 case 3:
SMART_CLEO 0:21b4d8237564 57 RX_BUF.LEN = rx_da;
SMART_CLEO 0:21b4d8237564 58 RX_Len = RX_BUF.LEN;
SMART_CLEO 0:21b4d8237564 59 RX_Status++;
SMART_CLEO 0:21b4d8237564 60 if(RX_Len == 0)
SMART_CLEO 0:21b4d8237564 61 RX_Status++;
SMART_CLEO 0:21b4d8237564 62 break;
SMART_CLEO 0:21b4d8237564 63 case 4:
SMART_CLEO 0:21b4d8237564 64 RX_BUF.DATA[RX_count] = rx_da;
SMART_CLEO 0:21b4d8237564 65 RX_count++;
SMART_CLEO 0:21b4d8237564 66 if(RX_count == RX_Len)
SMART_CLEO 0:21b4d8237564 67 {
SMART_CLEO 0:21b4d8237564 68 RX_Status++;
SMART_CLEO 0:21b4d8237564 69 RX_count = 0;
SMART_CLEO 0:21b4d8237564 70 RX_Len = 32;
SMART_CLEO 0:21b4d8237564 71 }
SMART_CLEO 0:21b4d8237564 72 break;
SMART_CLEO 0:21b4d8237564 73 case 5:
SMART_CLEO 0:21b4d8237564 74 if(rx_da == 0x3E)
SMART_CLEO 0:21b4d8237564 75 {
SMART_CLEO 0:21b4d8237564 76 RX_BUF.END = rx_da;
SMART_CLEO 0:21b4d8237564 77 RX_Status = 0;
SMART_CLEO 0:21b4d8237564 78 switch(RX_BUF.MODE)
SMART_CLEO 0:21b4d8237564 79 {
SMART_CLEO 0:21b4d8237564 80 case 0x01:
SMART_CLEO 0:21b4d8237564 81 if(RX_BUF.CMD == 0x18)
SMART_CLEO 0:21b4d8237564 82 {
SMART_CLEO 1:d05971975fdc 83 lcd.locate(0, 0);
SMART_CLEO 1:d05971975fdc 84 for(int i=0; i<32; i++)
SMART_CLEO 1:d05971975fdc 85 {
SMART_CLEO 1:d05971975fdc 86 if(i<RX_BUF.LEN)
SMART_CLEO 1:d05971975fdc 87 lcd.putc(RX_BUF.DATA[i]);
SMART_CLEO 1:d05971975fdc 88 else
SMART_CLEO 1:d05971975fdc 89 lcd.putc(0x20);
SMART_CLEO 1:d05971975fdc 90 }
SMART_CLEO 0:21b4d8237564 91 }
SMART_CLEO 0:21b4d8237564 92 break;
SMART_CLEO 0:21b4d8237564 93 }
SMART_CLEO 0:21b4d8237564 94 }
SMART_CLEO 0:21b4d8237564 95 break;
SMART_CLEO 0:21b4d8237564 96 }
SMART_CLEO 0:21b4d8237564 97 }