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 LCD_DISCO_F469NIa SD_DISCO_F469NI BSP_DISCO_F469NIa EEPROM_DISCO_F469NI
main.cpp
00001 #include "CAN_library.h" 00002 #include "screen_library.h" 00003 #include "EEPROM_DISCO_F469NI.h" 00004 00005 00006 LCD_DISCO_F469NI lcd; //Initialize LCD Display 00007 SD_DISCO_F469NI sd; //Initialize SD Card 00008 //EEPROM_DISCO_F469NI eep; //Initialize EEPROM Internal memory 00009 Serial pc(USBTX, USBRX,115200); //Initialize Serial. This is used only while debuging code. 00010 CAN can(PB_5, PB_13,1000000); //Initialize CAN. 00011 I2C i2c(D14, D15); 00012 DigitalOut reset(D8); 00013 InterruptIn change_screen_input(D0); //Initialize Digital input for Change screen button 00014 Timer t_int,t_store; 00015 00016 // Variables received from DTA, LVDTs and brakes 00017 uint16_t Capacity0=0,HV_Voltage0=0,Rpm0=0,Speed0=0,Gear0=0,Water_Temp0=0,Bat_Temp0=0,TPS0=0,Brakes0=0,MAP0=0,Air_Temp0=0,Lambda0=0,Volts0=0; 00018 uint16_t Capacity=80,HV_Voltage=542,Rpm=0,Speed=720,Gear=0,Water_Temp=47,Bat_Temp=34,TPS=69,Brakes=0,MAP=0,Air_Temp=0,Lambda=0,Volts=0; 00019 int FL_LVDT0=0,FR_LVDT0=0,RL_LVDT0=0,RR_LVDT0=0,FL_LVDT=0,FR_LVDT=0,RL_LVDT=0,RR_LVDT=0; 00020 //Referrent LVDT values. First received value is referrent. 00021 int FL_LVDT_Ref,FR_LVDT_Ref,RL_LVDT_Ref,RR_LVDT_Ref; 00022 //float Meter_counter=0,Meter_counter0=0; 00023 uint8_t Acc_Temperature[70],Acc_Temperature0[70]; 00024 00025 uint8_t change_flag=0; 00026 uint16_t rx_flag=0x0000; // Receive specific CAN data message 00027 uint8_t distance_flag=0; 00028 uint8_t lvdtref=0x0F; // Flag if refferent LVDT value is received (first received LVDT value, 1=no, 0=yes). From highest to lowest bit: LL,LR,RL,RR. 00029 uint8_t screen_flag=0x01; // Current screen flag. 1=Main, 2=First Aux, 3=Second Aux. 00030 uint8_t ft_main_flag=1; // Detect first time Main screne in loop 00031 uint8_t ft_2aux_flag=1; // Detect first time Second Aux screne in loop 00032 00033 // CAN Message variables, one variable for each ID 00034 // If new IDs are added, add variables for them 00035 CANMessage msgDTA1; // RPM, TPS %, Water temp C, Air temp C 00036 CANMessage msgDTA2; // MAP Kpa, Lambda x1000, KPH x10, Oil P Kpa 00037 CANMessage msgDTA3; // Fuel P Kpa, Oil temp C, Volts x10, Fuel Con. L/Hr x10 00038 CANMessage msgDTA4; // Gear, Advance Deg x10, Injection ms x100, Fuel Con L/100km x10 00039 CANMessage msgDTA5; // Ana1 mV, Ana2 mV, Ana3 mV, Cam Advance x10 00040 CANMessage msgDTA6; // Cam Targ x10, Cam PWM x10, Crank Errors, Cam Errors 00041 CANMessage msgLVDTFront; // Left, Right, Steering Wheel 00042 CANMessage msgLVDTRear; // Left, Right 00043 CANMessage msgBrakes; // Brake system preassure, Braking On/Off 00044 CANMessage msgDistance; // Total distance 00045 00046 // LED Bar for RPM 00047 00048 char cmd[3]; 00049 int addr = 0x74<<1; 00050 00051 void LEDInitialize(){ 00052 reset.write(1); 00053 // set port as output 00054 cmd[0]=0x06; 00055 cmd[1]=0x00; 00056 cmd[2]=0x00; 00057 i2c.write(addr,cmd,3); 00058 } 00059 00060 void showLedRpm(int RPM){ 00061 //pc.printf("%d\n",RPM); 00062 if(RPM<1000) { 00063 cmd[1]=0xFF; 00064 cmd[2]=0xFF; 00065 } 00066 else if (RPM<2000) { 00067 cmd[1]=0xFF; 00068 cmd[2]=0xDF; 00069 } 00070 else if (RPM <3000) { 00071 cmd[1]=0xFF; 00072 cmd[2]=0xCF; 00073 } 00074 else if (RPM <4000) { 00075 cmd[1]=0xFF; 00076 cmd[2]=0xC7; 00077 } 00078 else if (RPM <5000) { 00079 cmd[1]=0xFF; 00080 cmd[2]=0xC3; 00081 } 00082 else if (RPM <6000) { 00083 cmd[1]=0xFF; 00084 cmd[2]=0xC1; 00085 } 00086 else if (RPM <7000) { 00087 cmd[1]=0xFF; 00088 cmd[2]=0xC0; 00089 } 00090 else if (RPM <8000) { 00091 cmd[1]=0xBF; 00092 cmd[2]=0xC0; 00093 } 00094 else if (RPM <9000) { 00095 cmd[1]=0x9F; 00096 cmd[2]=0xC0; 00097 } 00098 else if (RPM <10000) { 00099 cmd[1]=0x8F; 00100 cmd[2]=0xC0; 00101 } 00102 else if (RPM <11000) { 00103 cmd[1]=0x87; 00104 cmd[2]=0xC0; 00105 } 00106 else if (RPM <12000) { 00107 cmd[1]=0x83; 00108 cmd[2]=0xC0; 00109 } 00110 else if (RPM <13000) { 00111 cmd[1]=0x81; 00112 cmd[2]=0xC0; 00113 } 00114 else { 00115 cmd[1]=0x80; 00116 cmd[2]=0xC0; 00117 } 00118 cmd[0]=0x02; 00119 i2c.write(addr, cmd, 3); 00120 } 00121 00122 00123 int main(){ 00124 //pc.printf("proba\n"); 00125 LEDInitialize(); 00126 can.attach(&CANMsgReceive,CAN::RxIrq); // Attach interrupt function to CAN RX 00127 change_screen_input.rise(&ChangeCommand); //Attach interrupt function to rising edge of DigitalIn for changing screen. 00128 //SetIntro(); // Display logo when starting display 00129 SetMain(); 00130 lcd.SetTextColor(LCD_COLOR_BLACK); // First screen is main by default 00131 sd.Init(); 00132 for (uint8_t k = 1 ; k <= 70 ; k++){ 00133 Acc_Temperature0[k] = 0; 00134 }; 00135 SetFixedAccTemp(); 00136 while(1){ 00137 if(change_flag){ // Check if screen is changed 00138 ChangeScreen(); 00139 }; 00140 UpdateInfo(); // Update info for DTA values in every iteration 00141 //pc.printf("proba2\n"); 00142 switch(screen_flag){ // Display only changes visible on current screen 00143 case(1): 00144 MainUpdate(); 00145 break; 00146 case(2): 00147 FirstAuxUpdate(); 00148 break; 00149 case(3): 00150 SecondAuxUpdate(); 00151 break; 00152 }; 00153 }; 00154 00155 };
Generated on Tue Jul 12 2022 18:36:18 by
