glenndingding
Newbie level 5
- Joined
- Feb 15, 2012
- Messages
- 10
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Location
- Philippines
- Activity points
- 1,403
hi everyone,
i am using MICRO C for my PIC16f877a micro controller but i have a problem encountered regarding the adc configuration and and making conditions in comparing constants.
i have 3 inputs which in need to be read in adc.....
1st input ...the adc read it. then it compares to a constant value of 12. then it gives 2 outputs. first output is switch relay and second output led blink.
2nd input ...the adc read it. then it compares to a constant value of 16. then it gives 2 outputs. first output is switch relay and second output led blink.
3rd input ...the adc read it. then it compares to a constant value of 24. then it gives 2 outputs. first output is switch relay and second output led blink.
here is my code .....please help me to correct..
..............the problems occur:
1. line 38 , 39, 40 .......too many parameters
2. line 46, .......;expected, but '6' found
3. line 46, .......'{' expected, but ';' found
4. line 95..........specifier needed
5. line 95........invalid declarator expected '(' or identifier
6. line 95.......internal error"
please help me to correct the configuration and the errors please
i am using MICRO C for my PIC16f877a micro controller but i have a problem encountered regarding the adc configuration and and making conditions in comparing constants.
i have 3 inputs which in need to be read in adc.....
1st input ...the adc read it. then it compares to a constant value of 12. then it gives 2 outputs. first output is switch relay and second output led blink.
2nd input ...the adc read it. then it compares to a constant value of 16. then it gives 2 outputs. first output is switch relay and second output led blink.
3rd input ...the adc read it. then it compares to a constant value of 24. then it gives 2 outputs. first output is switch relay and second output led blink.
here is my code .....please help me to correct..
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 void ADCInit(){ //configuring adc module } unsigned int ADCRead(){ ADCON1 = 0xFF; //configuring AN0-AN7 as analog inputs and VREF ADCON0 = 0x07; //configuring analog channels AN0, AN1, AN2 ADON_BIT = 1; //switch on adc module GO_DONE_BIT =1 ; //start conversion while(GO_DONE_BIT); //wait for the condition to finish ADON_BIT= 0; //switch off adc } void main(){ ADCInit(); //initializes adc in the main program TRISB = 0x00; PORTB = 0x00; //putting port B as output for LED indicator TRISD = 0X00; PORTD = 0x00; //putting port D as output for relay switching while(1){ unsigned int sensor1_15A; //assigning variable for input1 unsigned int sensor2_20A; //assigning variable for input2 unsigned int sensor3_30A; //assigning variable for input3 unsigned int reading1; //assigning variable for adc reading1 for input1 unsigned int reading2; //assigning variable for adc reading2 for input2 unsigned int reading3; //assigning variable for adc reading3 for input3 reading1 = sensor1_15A-511*0.012207; //assigning variables with constants reading2 = sensor2_20A-511*0.012207; //assigning variables with constants reading3 = sensor3_30A-511*0.012207; //assigning variables with constants sensor1_15A = ADCRead(1); //the adc reading of input 1 will be placed in the first variable sensor1_15A sensor2_20A = ADCRead(2); //the adc reading of input 2 will be placed in the first variable sensor2_20A sensor3_30A = ADCRead(3); //the adc reading of input 3 will be placed in the first variable sensor3_30A while(1){ if (reading1>12){ // condition when the (adc reading-511*0.012207) is greater to the set value of 12 amperes //adc reading-511*0.012207 = amperes....... PORTD.6 = 0xFF; //port D is used fOr switching relay1 at RD6 at pin 29 of PIC16f877a is set to input for relay switching // I do not know if it is PORTD.6.. i consider RD0, RD1, RD2, RD3, RD4, RD5,RD6, RD7 = pin 0,1,2,3,4,5,6,7 PORTD.6 = 0x00; delay_ms(5000); //port D at at RD6 at pin 29 of PIC16f877a is set to output for relay switching PORTB.7 = 0x00; //PORT B AT rb7 at pin 40 of pic16f877a is set to output for led blinking delay_ms(1000); PORTB.7 = 0xFF; //PORT B AT rb7 at pin 40 of pic16f877a is set to input for led blinking delay_ms(1000); else PORTD.6 = 0xFF; //PORT D AT RD6 is nothing to do PORTB.6 = 0x00; //PORT B AT rb6 at pin 39 of pic16f877a is set to output for led steady light } if (reading2>16){ // condition when the (adc reading-511*0.012207) is greater to the set value of 16 amperes //adc reading-511*0.012207 = amperes....... PORTD.5 = 0xFF; //port D is used fpr switching relay2 at RD5 at pin 28 of PIC16f877a is set to input for relay switching // I do not know if it is PORTD.5.. i consider RD0, RD1, RD2, RD3, RD4, RD5,RD6, RD7 = pin 0,1,2,3,4,5,6,7 delay_ms(5000); PORTD.5 = 0x00; delay_ms(5000); PORTB.5 = 0x00; //PORT B AT rb5 at pin 38 of pic16f877a is set to output for led blinking delay_ms(1000); PORTB.5 = 0xFF; //PORT B AT rb5 at pin 38 of pic16f877a is set to input for led blinking delay_ms(1000); else PORTD.5 = 0xFF; //PORT D AT RD5 is nothing to do PORTB.4 = 0x00; //PORT B AT rb4 at pin 37 of pic16f877a is set to output for led steady light } if (reading3>24){ // condition when the (adc reading-511*0.012207) is greater to the set value of 16 amperes //adc reading-511*0.012207 = amperes....... PORTD.4 = 0xFF; //port D is used fpr switching relay3 at RD4 at pin 28 of PIC16f877a is set to input for relay switching // I do not know if it is PORTD.5.. i consider RD0, RD1, RD2, RD3, RD4, RD5,RD6, RD7 = pin 0,1,2,3,4,5,6,7 delay_ms(5000); PORTD.4 = 0X00; delay_ms(5000); PORTB.3 = 0x00; //PORT B AT rb3 at pin 36 of pic16f877a is set to output for led blinking delay_ms(1000); PORTB.3 = 0xFF; //PORT B AT rb3 at pin 36 of pic16f877a is set to output for led blinking delay_ms(1000); else PORTD.4 = 0xFF; //PORT D AT RD4 is nothing to do PORTB.2 = 0x00; //PORT B AT rb2 at pin 35 of pic16f877a is set to output for led steady light } } } }
..............the problems occur:
1. line 38 , 39, 40 .......too many parameters
2. line 46, .......;expected, but '6' found
3. line 46, .......'{' expected, but ';' found
4. line 95..........specifier needed
5. line 95........invalid declarator expected '(' or identifier
6. line 95.......internal error"
please help me to correct the configuration and the errors please
Last edited by a moderator: