7ezhil7
Junior Member level 2
Hello,
I am a beginner in Embedded programming. I am doing a project to measure temperature,humidity,wind speed and produce a high output with respect to measured values.I need to measure temperatures from two different areas using sensors placed at different port pins.I need the code reused for both sensors.I tried a code which contains a lot of errors.So please help to correct my code as soon as possible.Thanks in advance.
I am a beginner in Embedded programming. I am doing a project to measure temperature,humidity,wind speed and produce a high output with respect to measured values.I need to measure temperatures from two different areas using sensors placed at different port pins.I need the code reused for both sensors.I tried a code which contains a lot of errors.So please help to correct my code as soon as possible.Thanks in advance.
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 #include<htc.h> void ReadData() { for(int b=0;b<8;b++) {int i; while(!PORTE); //Wait until PORTE.Fx goes HIGH Delay_us(30); if(PORTE == 0) i&=~(1<<(7-b)); ` //Clear bit (7-b) else {i|= (1<<(7-b)); //Set bit (7-b) while(PORTE);} //Wait until PORTE.Fx goes LOW } void main() { unsigned char a = 0; unsigned char b = 0; unsigned char i = 0; int t1[1] = 0; int t2 = 0; int rh1[1] = 0; int rh2 = 0; unsigned char sum = 0; unsigned char v=0; unsigned char u=0; TRISA=00000110; CMCON=0x02; TRISC=0; PORTC=0; v=0b110;t=0; temp(v); v=v<<1; //left shift zero to next bit(next sensor) t=1; temp(v); tempdiff=t1[0]-t1[1]; windspeed(); if (ws>383) //needed condition {PORTC=0;} else if(tempdiff<8 && (25<rh1[0]<80)) {PORTC=1;} while(show) { text = "Temp Diff:"; Lcd_Out(1,1,text); text = "ExH:"; Lcd_Out(2,1,text); text = "WS:"; Lcd_Out(2,9,text); text=tempdiff"C"; Lcd_Out(1,11,text); text=rh1[0]"%"; Lcd_Out(2,5,text); text=ws"m/s"; Lcd_Out(2,12,text); } } temp(int u) { //start signal TRISE = u; //Configure RB2 as output PORTE = 0; //RB2 senBs 0 to the sensor Delay_ms(18); PORTE = 1; //RB2 senBs 1 to the sensor Delay_us(30); TRISE =~u; //Configure RB2 as input // CheckResponse int a = 0; Delay_us(40); if (PORTE == 0) { Delay_us(80); if (PORTE == 1) a = 1; Delay_us(40); } if(a == 1) { ReadData(); rh1[t]=i; ReadData(); rh2 =i; ReadData(); t1[t] =i; ReadData(); t2 =i; ReadData(); sum = i; if(sum == rh1[t]+rh2+t1[t]+t2 ) { } //check sum and do nothing if correct. else { Lcd_Cmd(_Lcd_CURSOR_OFF); // cursor off Lcd_Cmd(_Lcd_CLEAR); // clear Lcd text = "Check sum error"; Lcd_Out(1,1,text); main(); } } else { Delay_ms(2000); main(); } windspeed() //wind speed { T1CON=0b00110100; TMR1IE=1; TMR1IF=0; INTCON=0b11000000; TMR1H=0x0B; TMR1L=0xDC; T1CON=0b00110101; CIS=1 ; //CMCON<3> while(TMR1IF=0) { if (C2OUT=1) //measuring wind speed for 0.5 second. { ws=ws+1; } } ws=ws*2; //calculating wind speed for a second } }
Last edited by a moderator: