Shivanand Gowda / Mbed 2 deprecated Multiple_7SegDisplays

Dependencies:   74HC595 RS485 mbed

Fork of Check_7segLED_driver by Kenji Arai

Revision:
1:69423a344fe4
Parent:
0:b24071fbcbb3
diff -r b24071fbcbb3 -r 69423a344fe4 main.cpp
--- a/main.cpp	Mon Jan 22 10:25:28 2018 +0000
+++ b/main.cpp	Tue Aug 21 10:24:08 2018 +0000
@@ -1,215 +1,174 @@
-/*
- * Mbed Application program / Akizuki 7-segment LED driver [OSL10564-74HC595-x]
- *      AKIZUKI AE-7SEG-BOARD-KIT-BLUE
- *      http://akizukidenshi.com/catalog/g/gK-10344/
- *
- * Copyright (c) 2018 Kenji Arai / JH1PJL
- *  http://www.page.sannet.ne.jp/kenjia/index.html
- *  http://mbed.org/users/kenjiArai/
- *      Created:    January    7th, 2018
- *      Revised:    January   22nd, 2018
- */
 
 //  Include --------------------------------------------------------------------
 #include "mbed.h"
 #include "7segLed_HC595.h"
+#include "RS485.h"
 
 //  Definition -----------------------------------------------------------------
 #define NUM_OF_DIGIT    6
-
 #define KEYIN_THEN_EXIT_WHILE() {if(exit_while_loop_when_keyinput()){ break;}}
 
-//  Constructor ----------------------------------------------------------------
-Serial      pc(USBTX, USBRX);
-#if defined(TARGET_NUCLEO_F446RE) || defined(TARGET_NUCLEO_F411RE)\
- || defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_L152RE)\
- || defined(TARGET_NUCLEO_L073RZ) || defined(TARGET_NUCLEO_L053R8)\
- || defined(TARGET_NUCLEO_L476RG)
-//                SPI MOSI,SCLK,any port, PWM, number of digit
-SevenSegLed led_7segs(D4,  D3,  D5,       D6,  NUM_OF_DIGIT);
-#elif defined(TARGET_NUCLEO_F334R8)
-//                SPI MOSI,SCLK,any port, PWM, number of digit
-SevenSegLed led_7segs(D4,  D3,  D5,       D7,  NUM_OF_DIGIT);
-#elif defined(TARGET_NUCLEO_F303K8)
-//                SPI MOSI,SCLK,any port, PWM, number of digit
-SevenSegLed led_7segs(A6,  A4,  A5,       A3,  NUM_OF_DIGIT);
-#elif TARGET_Freescale
-//                SPI MOSI,SCLK,any port, PWM, number of digit
-SevenSegLed led_7segs(D11, D13, D12,     D10,  NUM_OF_DIGIT);
-#else
-#error    "Please set your own SevenSegLed constractor!"
-#endif
+SevenSegLed led_7segs(PC_12,PC_10, PC_9, PC_8,  NUM_OF_DIGIT);
+// Serial_Data_Out, Serial_Clock, Latch , PWM_Brightness_Contol
+Serial pc(USBTX,USBRX);
+Serial rs485(PF_7,PF_6,PA_1);
 DigitalOut  myled(LED1);
 AnalogIn    vol(A0);
-
-//  RAM ------------------------------------------------------------------------
 time_t seconds;
 
-//  ROM / Constant data --------------------------------------------------------
+DigitalIn sw1(PE_10);
+DigitalIn sw2(PE_12);
+DigitalIn sw3(PE_13);
+DigitalIn sw4(PE_14);
+DigitalIn sw5(PH_1);
+DigitalIn sw6(PH_0);
+DigitalIn sw7(PC_15);
+DigitalIn sw8(PC_14);
 
-//  Function prototypes --------------------------------------------------------
+char Rx_Data[20]={'\0'};
+char Floor_No_MSB,Floor_No_LSB;
+int Get_Floor_Number( int result);
+int validate_rx_data(char *Rx);
+int read_switch_state(void);
+int Count=0;
 bool exit_while_loop_when_keyinput(void);
 
-//------------------------------------------------------------------------------
-//  Control Program
-//------------------------------------------------------------------------------
+
 int main()
 {
-    //--------------------------------------------------------------------------
-    pc.printf("Hit any key to go next step\r\n");
-    pc.printf("Step1\r\n");
-    {
-        uint32_t max = 9;
-        for (uint32_t i = 1; i < NUM_OF_DIGIT; i++) {
+        int value=read_switch_state();
+        int floor=Get_Floor_Number(value);
+        
+        uint32_t max = 4;
+        for (uint32_t i = 1; i < NUM_OF_DIGIT; i++) 
+        {
             max = max * 10 + 9;
         }
         pc.printf("max = %d\r\n", max);
         led_7segs.zero_suppress(true);
-        int32_t count = 0;
-        while(true) {
-            led_7segs = count++;
-            if (count > max) {
-                count = 0;
-            }
-            float wait_time = 5.0f / (float)(count + 1);
-            if (wait_time > 0.01f) {
-                wait(wait_time);
-            }
-            KEYIN_THEN_EXIT_WHILE();
-        }
-    }
-    //--------------------------------------------------------------------------
-    pc.printf("Step2\r\n");
-    {
-        char buf[16];
-
-        led_7segs.zero_suppress(false);
-        float led_bright = 0.5f;
-        while(true) {
-            time_t seconds = time(NULL);
-            strftime(buf, 10, "%H.%M.%S", localtime(&seconds));
-            //strftime(buf, 10, "1.2.3.4.%S", localtime(&seconds));
-            pc.printf("%s\r\n", buf);
-            led_7segs.put_ascii(buf);
-            led_7segs.brightness(led_bright);
-            if (led_bright == 0.5f) {
-                led_bright = 1.0f;
-            } else {
-                led_bright = 0.5f;
+        
+        
+        while(true)
+        { 
+            if(rs485.readable())
+            {
+               int i=0;
+              //A22010055B; Send this data to Mbed Device through RS485
+              // A - Start of Frame 
+              // 22 - Display Address Panel Number 
+              // 0 - Delimeter 
+              // 1- Turn On Display
+              //0- Delimiter
+              //055 or xxx Number to be displayed 
+              // B; End of Frame.       
+               Rx_Data[i++]=rs485.getc();    
             }
-            wait(1.0f);
-            KEYIN_THEN_EXIT_WHILE();
-        }
-    }
-    //--------------------------------------------------------------------------
-    pc.printf("Step3\r\n");
-    {
-        uint8_t seg_bf[6] =  {
-            0b00000001     // LSB
-            ,0b00000010
-            ,0b10000100     // +Dot
-            ,0b00001000
-            ,0b00010000
-            ,0b00100000     // MSB
-        };
+                     
+         }       
+}
 
-        led_7segs.zero_suppress(true);
-        led_7segs.brightness(1.0f);
-        int32_t count = 0;
-        while(true) {
-            count++;
-            if (count & 0x01) {
-                led_7segs.put_raw(seg_bf);
-            } else {
-                led_7segs.put_ascii("12.34567");
-            }
-            wait(1.0f);
-            KEYIN_THEN_EXIT_WHILE();
-        }
-    }
-    //--------------------------------------------------------------------------
-    pc.printf("Step4\r\n");
-    {
-        char buf[16];
+
 
-        for (uint32_t i = 0; i < sizeof(buf); i++) {
-            buf[i] = ' ';
-        }
-        bool exit_req = false;
-        while(true) {
-            for (uint32_t n = ' '; n < '~'; n++) {
-                for (uint32_t i = 0 ; i < sizeof(buf) - 1; i++) {
-                    buf[i] = buf[i + 1];
-                }
-                buf[NUM_OF_DIGIT - 1] = n;
-                pc.putc(n);
-                led_7segs.put_strings(buf);
-                led_7segs.brightness(vol);
-                wait(1.0f);
-                if(exit_while_loop_when_keyinput()) {
-                    exit_req = true;
-                    break;
-                }
-            }
-            if (exit_req == true) {
-                break;
-            }
-        }
-        for (uint32_t i = 0; i < sizeof(buf); i++) {
-            buf[i] = ' ';
-        }
-        led_7segs.put_strings(buf);
-        pc.printf("\r\n");
-    }
-    //--------------------------------------------------------------------------
-    pc.printf("Step5\r\n");
+int validate_rx_data(char *Rx)
+{
+   int res;
+   if( Rx[0]=='A' && Rx[1]=='2'&& Rx[2]=='2'
+    && Rx[3]==0x30 && Rx[4]=='1'&& Rx[5]==0x30
+    && Rx[9]=='B')
     {
-        char buf[16];
-
-        pc.printf("hit [Esc] to exit the function\r\n");
-        for (uint32_t i = 0; i < sizeof(buf); i++) {
-            buf[i] = ' ';
-        }
-        led_7segs.put_strings(buf);
-        while(true) {
-            while(pc.readable() == 0) {
-                ;
-            }
-            char c = pc.getc();
-            pc.putc(c);
-            if (c == 0x1b) {    // [Esc]
-                break;
-            }
-            for (uint32_t i = 0 ; i < sizeof(buf) - 1; i++) {
-                buf[i] = buf[i + 1];
-            }
-            buf[NUM_OF_DIGIT - 1] = c;
-            led_7segs.put_strings(buf);
-        }
-        for (uint32_t i = 0; i < sizeof(buf); i++) {
-            buf[i] = ' ';
-        }
-        led_7segs.put_strings(buf);
-        pc.printf("\r\n");
+      printf("Valid Data Recieved \r\n");  
+        int a =Rx[6]-0x30;
+        int b=Rx[7]-0x30;
+        int c=Rx[8]-0x30;
+         res=(a<<16 ||b<<8||c);
+        led_7segs=res;
+        return 1;
     }
-    //--------------------------------------------------------------------------
-    pc.printf("Step_END\r\n");
+    
+    else if( Rx[0]=='A' && Rx[1]=='2'&& Rx[2]=='2'
+    && Rx[3]==0x30 && Rx[4]=='2'&& Rx[5]==0x30
+    && Rx[9]=='B')
     {
-        while(true) {
-            pc.printf("Finished -> Reset then start again\r\n");
-            wait(10.0f);
-        }
+        char str[4]="nil";
+        printf("Valid Data Recieved \r\n");   
+        led_7segs=res;
+        led_7segs.put_strings(str);
+        return 1;
     }
+    else 
+    {
+        printf(" Not Intended to me \r\n");
+        memset(Rx,'\0',20); 
+        return 0;
+    } 
+    
 }
 
-bool exit_while_loop_when_keyinput(void)
+int read_switch_state(void)
 {
-    if (pc.readable()) {
-        while(pc.readable()) {
-            char c = pc.getc();
-        }
-        return true;
-    } else {
-        return false;
-    }
+    int c1,c2,c3,c4,c5,c6,c7,c8; int res=0;
+    if(sw1==0)
+       c1=0;  
+    else 
+    c1=1; 
+    if(sw2==0)
+       c2=0;   
+    else
+    c2=0x02; 
+    if(sw3==0)
+     c3=0;  
+    else
+    c3=0x04; 
+    if(sw4==0)
+       c4=0;   
+    else
+    c4=0x08; 
+    
+    if(sw5==0)
+       c5=0;  
+    else 
+    c5=16; 
+    if(sw6==0)
+       c6=0;   
+    else
+    c6=32; 
+    if(sw7==0)
+     c7=0;  
+    else
+    c7=64; 
+    if(sw8==0)
+       c8=0;   
+    else
+    c8=128; 
+    
+    res=c1|c2|c3|c4|c5|c6|c7|c8;
+    if(res==1)
+    return 1;
+    else if(res==3)
+    return 2;
+    else if(res==7)
+    return 3;
+    else if(res==15)
+    return 4;
+    else if(res==31)
+    return 5;
+    else if(res==63)
+    return 6;
+    else if(res==127)
+    return 7;  
+    else if(res==255)
+    return 8;   
+    
+    return -1;
 }
+
+
+int Get_Floor_Number( int result )
+{   
+    int MSB;int LSB;
+    MSB=0x30;
+    LSB=0x30+result;
+    result=MSB+LSB;
+    return result;
+    
+}
\ No newline at end of file