Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Code C - [expand] 1 2 3 4 char* return_my_name() { return "zeeshan"; }
Code C - [expand] 1 (StatP/29.9213)
Code C - [expand] 1 (fStatP/29.9213)
unsigned char Pressure[23], Temperature[23];
int strLength =0;
float ADRead0, StatP , DynP , QNH,TAT , AOA , Mack , TAS , SAT , TA ,PA = 0;
extern float Function(int n);
void main(){
TRISA = 0b111111;
PORTA = 0x00;
TRISC = 0x80;
PORTC = 0x00;
ADCON1 = 0b10001010;
CMCON = 0x07;
CVRCON = 0x00;
UART1_init(9600);
Delay_ms(1000);
while (1){
StatP = Function(0); // function call
DynP = Function(1);
QNH = Function(2);
TAT = Function(4);
AOA = Function(5);
// AOA Correction
if (AOA = 15 ) DynP = DynP-(DynP*(5/100)) ;
if (AOA = 20 ) DynP = DynP-(DynP*(12/100)) ;
if (AOA = 25 ) DynP = DynP-(DynP*(22/100)) ;
// Pressure Altitude calculation
PA = (288.16/0.0019812)*(1-pow((StatP/29.9213),0.190255)) ;
// Mack Number claculation
Mack = sqrt(5*((pow((1+(DynP/StatP)),(2/7)))-1)) ;
// Static Air Temperature calculation
SAT = TAT/(1+0.2*pow(mack,2)) ;
// True Air Speed calculation
TAS = 38.968*Mack*sqrt(SAT) ;
// True Altitude calculation
TA = (sat/0.0019812)*((pow((QNH/StatP),0.190255))-1) ;
// Sending data with a delay of 1 sec
FloatToStr(PA, Pressure);
strLength = strlen(Pressure);
Pressure[strLength - 1] = 'T';
Pressure[strLength] = 'x';
Pressure[strLength + 1] = '\0';
UART1_Write_Text(Pressure);
uart1_write(0x0d);
delay_ms(1000);
}
}
float Function(int n) {
ADRead0 = ADC_Read(n) * 0.1559251559251559;
return ADRead0;
}
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 #define METHOD1 //#define METHOD2 int strLength = 0; unsigned char Pressure[23], Temperature[23]; float ADRead = 0.0, fStatP = 0.0, fDynP = 0.0, fQNH = 0.0, fTAT = 0.0, fAOA = 0.0, fMack = 0.0, fSAT = 0.0, fTAS = 0.0, fTA = 0.0, fPA = 0.0; #ifdef METHOD1 unsigned char StatP[23] , DynP[23] , QNH[23], TAT[23], AOA[23], Mack[23], TAS[23], SAT[23], TA[23], PA[23]; #elif METHOD2 unsigned char sTemp[23]; #endif void Delay1Sec(){ Delay_ms(1000); } void UART1_CRLF(){ UART1_write(0x0D); UART1_write(0x0A); } float Function(int n) { ADRead = ADC_Read(n) * 0.1559251559251559; FloatToStr(ADRead, Pressure); strLength = strlen(Pressure); Pressure[strLength - 1] = 'T'; Pressure[strLength] = 'x'; Pressure[strLength + 1] = '\0'; UART1_Write_Text(Pressure); UART1_CRLF(); Delay1Sec(); return ADRead; } #ifdef METHOD1 void Float2String(){ FloatToStr(fStatP, StatP); FloatToStr(fDynP, DynP); FloatToStr(fQNH, QNH); FloatToStr(fTAT, TAT); FloatToStr(fAOA, AOA); FloatToStr(fPA, PA); FloatToStr(fMack, Mack); FloatToStr(fSAT, SAT); FloatToStr(fTAS, TAS); FloatToStr(fTA, TA); } void UART1Send(){ UART1_Write_Text(PA); UART1_CRLF(); Delay1Sec(); UART1_Write_Text(Mack); UART1_CRLF(); Delay1Sec(); UART1_Write_Text(SAT); UART1_CRLF(); Delay1Sec(); UART1_Write_Text(TAS); UART1_CRLF(); Delay1Sec(); UART1_Write_Text(TA); UART1_CRLF(); Delay1Sec(); } #elif METHOD2 void F2S_UART_CRLF(){ FloatToStr(fStatP, sTemp); UART1_Write_Text(sTemp); UART1_CRLF(); Delay1Sec(); FloatToStr(fDynP, sTemp); UART1_Write_Text(sTemp); UART1_CRLF(); Delay1Sec(); FloatToStr(fQNH, sTemp); UART1_Write_Text(sTemp); UART1_CRLF(); Delay1Sec(); FloatToStr(fTAT, sTemp); UART1_Write_Text(sTemp); UART1_CRLF(); Delay1Sec(); FloatToStr(fAOA, sTemp); UART1_Write_Text(sTemp); UART1_CRLF(); Delay1Sec(); FloatToStr(fPA, sTemp); UART1_Write_Text(sTemp); UART1_CRLF(); Delay1Sec(); FloatToStr(fMack, sTemp); UART1_Write_Text(sTemp); UART1_CRLF(); Delay1Sec(); FloatToStr(fSAT, sTemp); UART1_Write_Text(sTemp); UART1_CRLF(); Delay1Sec(); FloatToStr(fTAS, sTemp); UART1_Write_Text(sTemp); UART1_CRLF(); Delay1Sec(); FloatToStr(fTA, sTemp); UART1_Write_Text(sTemp); UART1_CRLF(); Delay1Sec(); } #endif void main(){ TRISA = 0b111111; PORTA = 0x00; TRISC = 0x80; PORTC = 0x00; ADCON1 = 0b00011000; ADCON2 = 0b10101001; CMCON = 0x07; CVRCON = 0x00; UART1_init(9600); Delay_ms(1000); while (1){ fStatP = Function(0); // function call fDynP = Function(1); // function call fQNH = Function(2); // function call fTAT = Function(5); // function call fAOA = Function(6); // function call // AOA Correction if(fAOA = 15.0) fDynP = fDynP-(fDynP*(5.0/100.0)); if(fAOA = 20.0) fDynP = fDynP-(fDynP*(12.0/100.0)); if(fAOA = 25.0) fDynP = fDynP-(fDynP*(22.0/100.0)); // Pressure Altitude calculation fPA = (288.16 / 0.0019812) * (1 - pow((fStatP / 29.9213), 0.190255)); // Mack Number claculation fMack = sqrt(5 * ((pow((1 + (fDynP / fStatP)), (2 / 7))) - 1)); // Static Air Temperature calculation fSAT = fTAT / (1 + 0.2 * pow(fMack, 2)) ; // True Air Speed calculation fTAS = 38.968 * fMack * sqrt(fSAT) ; // True Altitude calculation fTA = (fSAT / 0.0019812)*((pow((fQNH / fStatP), 0.190255)) - 1); #ifdef METHOD1 // Float to String Conversions Float2String(); // Sending data with a delay of 1 sec UART1Send(); #elif METHOD2 F2S_UART_CRLF(); #endif } /* function max returns greater one of its 2 arguments: */ }
#define METHOD2
Code C - [expand] 1 2 3 4 // AOA Correction if(fAOA == 15.0) fDynP = fDynP - (fDynP*(5.0/100.0)); if(fAOA == 20.0) fDynP = fDynP - (fDynP*(12.0/100.0)); if(fAOA == 25.0) fDynP = fDynP - (fDynP*(22.0/100.0));
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 #define METHOD1 //#define METHOD2 int strLength = 0; unsigned char Pressure[23], Temperature[23]; float ADRead = 0.0, fStatP = 0.0, fDynP = 0.0, fQNH = 0.0, fTAT = 0.0, fAOA = 0.0, fMack = 0.0, fSAT = 0.0, fTAS = 0.0, fTA = 0.0, fPA = 0.0; #ifdef METHOD1 unsigned char StatP[23] , DynP[23] , QNH[23], TAT[23], AOA[23], Mack[23], TAS[23], SAT[23], TA[23], PA[23]; #endif #ifdef METHOD2 unsigned char sTemp[23]; #endif unsigned char msg[23] = "EDABOARD\r\n"; unsigned char* Return_String(){ return msg; } void Delay1Sec(){ Delay_ms(2000); } void UART1_CRLF(){ UART1_write(0x0D); UART1_write(0x0A); } float Function(int n) { ADRead = ADC_Read(n) * 0.1559251559251559; FloatToStr(ADRead, Pressure); strLength = strlen(Pressure); Pressure[strLength - 1] = '\r'; Pressure[strLength] = '\n'; Pressure[strLength + 1] = '\0'; UART1_Write_Text(Pressure); //UART1_CRLF(); Delay1Sec(); return ADRead; } #ifdef METHOD1 void Float2String(){ FloatToStr(fStatP, StatP); FloatToStr(fDynP, DynP); FloatToStr(fQNH, QNH); FloatToStr(fTAT, TAT); FloatToStr(fAOA, AOA); FloatToStr(fPA, PA); FloatToStr(fMack, Mack); FloatToStr(fSAT, SAT); FloatToStr(fTAS, TAS); FloatToStr(fTA, TA); } void UART1Send(){ UART1_Write_Text(PA); UART1_CRLF(); Delay1Sec(); UART1_Write_Text(Mack); UART1_CRLF(); Delay1Sec(); UART1_Write_Text(SAT); UART1_CRLF(); Delay1Sec(); UART1_Write_Text(TAS); UART1_CRLF(); Delay1Sec(); UART1_Write_Text(TA); UART1_CRLF(); Delay1Sec(); } #endif #ifdef METHOD2 void F2S_UART_CRLF(){ FloatToStr(fStatP, sTemp); UART1_Write_Text(sTemp); UART1_CRLF(); Delay1Sec(); FloatToStr(fDynP, sTemp); UART1_Write_Text(sTemp); UART1_CRLF(); Delay1Sec(); FloatToStr(fQNH, sTemp); UART1_Write_Text(sTemp); UART1_CRLF(); Delay1Sec(); FloatToStr(fTAT, sTemp); UART1_Write_Text(sTemp); UART1_CRLF(); Delay1Sec(); FloatToStr(fAOA, sTemp); UART1_Write_Text(sTemp); UART1_CRLF(); Delay1Sec(); FloatToStr(fPA, sTemp); UART1_Write_Text(sTemp); UART1_CRLF(); Delay1Sec(); FloatToStr(fMack, sTemp); UART1_Write_Text(sTemp); UART1_CRLF(); Delay1Sec(); FloatToStr(fSAT, sTemp); UART1_Write_Text(sTemp); UART1_CRLF(); Delay1Sec(); FloatToStr(fTAS, sTemp); UART1_Write_Text(sTemp); UART1_CRLF(); Delay1Sec(); FloatToStr(fTA, sTemp); UART1_Write_Text(sTemp); UART1_CRLF(); Delay1Sec(); } #endif void main(){ TRISA = 0b111111; PORTA = 0x00; TRISC = 0x80; PORTC = 0x00; ADCON1 = 0b00011000; ADCON2 = 0b10101001; CMCON = 0x07; CVRCON = 0x00; UART1_init(9600); Delay_ms(1000); while (1){ fStatP = Function(0); // function call fDynP = Function(1); // function call fQNH = Function(2); // function call fTAT = Function(5); // function call fAOA = Function(6); // function call // AOA Correction if(fAOA == 15.0) fDynP = fDynP - (fDynP*(5.0/100.0)); if(fAOA == 20.0) fDynP = fDynP - (fDynP*(12.0/100.0)); if(fAOA == 25.0) fDynP = fDynP - (fDynP*(22.0/100.0)); // Pressure Altitude calculation fPA = (288.16 / 0.0019812) * (1 - pow((fStatP / 29.9213), 0.190255)); // Mack Number claculation fMack = sqrt(5 * ((pow((1 + (fDynP / fStatP)), (2 / 7))) - 1)); // Static Air Temperature calculation fSAT = fTAT / (1 + 0.2 * pow(fMack, 2)) ; // True Air Speed calculation fTAS = 38.968 * fMack * sqrt(fSAT) ; // True Altitude calculation fTA = (fSAT / 0.0019812)*((pow((fQNH / fStatP), 0.190255)) - 1); #ifdef METHOD1 // Float to String Conversions Float2String(); // Sending data with a delay of 1 sec UART1Send(); #endif #ifdef METHOD2 F2S_UART_CRLF(); #endif UART1_Write_Text(Return_String()); } /* function max returns greater one of its 2 arguments: */ }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 sbit LCD_RS at RB2_bit; sbit LCD_EN at RB3_bit; sbit LCD_D4 at RB4_bit; sbit LCD_D5 at RB5_bit; sbit LCD_D6 at RB6_bit; sbit LCD_D7 at RB7_bit; sbit LCD_RS_Direction at TRISB2_bit; sbit LCD_EN_Direction at TRISB3_bit; sbit LCD_D4_Direction at TRISB4_bit; sbit LCD_D5_Direction at TRISB5_bit; sbit LCD_D6_Direction at TRISB6_bit; sbit LCD_D7_Direction at TRISB7_bit; unsigned char output[23]; void main(){ TRISB = 0x00; PORTB = 0x00; TRISC = 0x80; PORTC = 0x00; LCD_Init(); LCD_Cmd(_LCD_CURSOR_OFF); LCD_Cmd(_LCD_CLEAR); UART1_Init(9600); Delay_ms(100); while(1){ if (UART1_Data_Ready() == 1){ UART1_Read_Text(output, "\r\n", 10); // reads text until 'Tx' is found Lcd_Out(1,1, output); UART1_Write_Text(output); UART1_Write(0x0D); UART1_Write(0x0A); output[0] = '\0'; } } }
Code C - [expand] 1 2 3 4 5 6 #ifdef METHOD1 #undef METHOD2 #endif #ifdef METHOD2 #undef METHOD1 #endif
but when i rebuilt the same prob occurs , no error mentioned ?
ADRead = ADC_Read(n) * 0.1559251559251559;