Shivanand Gowda / Mbed 2 deprecated Multiple_7SegDisplays

Dependencies:   74HC595 RS485 mbed

Fork of Check_7segLED_driver by Kenji Arai

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 
00002 //  Include --------------------------------------------------------------------
00003 #include "mbed.h"
00004 #include "7segLed_HC595.h"
00005 #include "RS485.h"
00006 
00007 //  Definition -----------------------------------------------------------------
00008 #define NUM_OF_DIGIT    6
00009 #define KEYIN_THEN_EXIT_WHILE() {if(exit_while_loop_when_keyinput()){ break;}}
00010 
00011 SevenSegLed led_7segs(PC_12,PC_10, PC_9, PC_8,  NUM_OF_DIGIT);
00012 // Serial_Data_Out, Serial_Clock, Latch , PWM_Brightness_Contol
00013 Serial pc(USBTX,USBRX);
00014 Serial rs485(PF_7,PF_6,PA_1);
00015 DigitalOut  myled(LED1);
00016 AnalogIn    vol(A0);
00017 time_t seconds;
00018 
00019 DigitalIn sw1(PE_10);
00020 DigitalIn sw2(PE_12);
00021 DigitalIn sw3(PE_13);
00022 DigitalIn sw4(PE_14);
00023 DigitalIn sw5(PH_1);
00024 DigitalIn sw6(PH_0);
00025 DigitalIn sw7(PC_15);
00026 DigitalIn sw8(PC_14);
00027 
00028 char Rx_Data[20]={'\0'};
00029 char Floor_No_MSB,Floor_No_LSB;
00030 int Get_Floor_Number( int result);
00031 int validate_rx_data(char *Rx);
00032 int read_switch_state(void);
00033 int Count=0;
00034 bool exit_while_loop_when_keyinput(void);
00035 
00036 
00037 int main()
00038 {
00039         int value=read_switch_state();
00040         int floor=Get_Floor_Number(value);
00041         
00042         uint32_t max = 4;
00043         for (uint32_t i = 1; i < NUM_OF_DIGIT; i++) 
00044         {
00045             max = max * 10 + 9;
00046         }
00047         pc.printf("max = %d\r\n", max);
00048         led_7segs.zero_suppress(true);
00049         
00050         
00051         while(true)
00052         { 
00053             if(rs485.readable())
00054             {
00055                int i=0;
00056               //A22010055B; Send this data to Mbed Device through RS485
00057               // A - Start of Frame 
00058               // 22 - Display Address Panel Number 
00059               // 0 - Delimeter 
00060               // 1- Turn On Display
00061               //0- Delimiter
00062               //055 or xxx Number to be displayed 
00063               // B; End of Frame.       
00064                Rx_Data[i++]=rs485.getc();    
00065             }
00066                      
00067          }       
00068 }
00069 
00070 
00071 
00072 int validate_rx_data(char *Rx)
00073 {
00074    int res;
00075    if( Rx[0]=='A' && Rx[1]=='2'&& Rx[2]=='2'
00076     && Rx[3]==0x30 && Rx[4]=='1'&& Rx[5]==0x30
00077     && Rx[9]=='B')
00078     {
00079       printf("Valid Data Recieved \r\n");  
00080         int a =Rx[6]-0x30;
00081         int b=Rx[7]-0x30;
00082         int c=Rx[8]-0x30;
00083          res=(a<<16 ||b<<8||c);
00084         led_7segs=res;
00085         return 1;
00086     }
00087     
00088     else if( Rx[0]=='A' && Rx[1]=='2'&& Rx[2]=='2'
00089     && Rx[3]==0x30 && Rx[4]=='2'&& Rx[5]==0x30
00090     && Rx[9]=='B')
00091     {
00092         char str[4]="nil";
00093         printf("Valid Data Recieved \r\n");   
00094         led_7segs=res;
00095         led_7segs.put_strings(str);
00096         return 1;
00097     }
00098     else 
00099     {
00100         printf(" Not Intended to me \r\n");
00101         memset(Rx,'\0',20); 
00102         return 0;
00103     } 
00104     
00105 }
00106 
00107 int read_switch_state(void)
00108 {
00109     int c1,c2,c3,c4,c5,c6,c7,c8; int res=0;
00110     if(sw1==0)
00111        c1=0;  
00112     else 
00113     c1=1; 
00114     if(sw2==0)
00115        c2=0;   
00116     else
00117     c2=0x02; 
00118     if(sw3==0)
00119      c3=0;  
00120     else
00121     c3=0x04; 
00122     if(sw4==0)
00123        c4=0;   
00124     else
00125     c4=0x08; 
00126     
00127     if(sw5==0)
00128        c5=0;  
00129     else 
00130     c5=16; 
00131     if(sw6==0)
00132        c6=0;   
00133     else
00134     c6=32; 
00135     if(sw7==0)
00136      c7=0;  
00137     else
00138     c7=64; 
00139     if(sw8==0)
00140        c8=0;   
00141     else
00142     c8=128; 
00143     
00144     res=c1|c2|c3|c4|c5|c6|c7|c8;
00145     if(res==1)
00146     return 1;
00147     else if(res==3)
00148     return 2;
00149     else if(res==7)
00150     return 3;
00151     else if(res==15)
00152     return 4;
00153     else if(res==31)
00154     return 5;
00155     else if(res==63)
00156     return 6;
00157     else if(res==127)
00158     return 7;  
00159     else if(res==255)
00160     return 8;   
00161     
00162     return -1;
00163 }
00164 
00165 
00166 int Get_Floor_Number( int result )
00167 {   
00168     int MSB;int LSB;
00169     MSB=0x30;
00170     LSB=0x30+result;
00171     result=MSB+LSB;
00172     return result;
00173     
00174 }