savoc
Newbie level 6
I need help to solve this problem, the coding can be compile and trasfer to PIC, but LED that need to be UP when certain condition is met is not lightup, here are my coding:-
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 #include<pic.h> __CONFIG (0x3F32); #define RS RA2 #define E RA5 #define CHANNEL0 0b10000001 // AN0 #define buzzer RB5 #define ledA RB2 #define ledB RB1 //==============FUNCTION PTOTOTYPE========================= void delay(unsigned short i); void read_adc(void); unsigned short read_temp(void); //====================MAIN================================ unsigned short result; unsigned short temp,tempA,tempB; void main(void) { ADRESH=0; //clear A/D result ADRESL=0; //clear A/D result //setting ADCON1 Register ADCON1=0b11000101; // A/D result right justified, TRISA=0b11011011; //configure PORTA I/O direction TRISB=0b00000000; //configure PORTB as output TRISC=0b00000000; //configure PORTC as output // PORTA=0; PORTB=0; while(1) { while(1) //infinity loop { //sensor A ADCON0=CHANNEL0; //CHANNEL1=0b10001001 /* lcd_goto(8); temp=read_temp(); dis_num(temp/10); send_char('.'); dis_num(temp%10); send_char(0b11011111); send_char('C'); send_char(' '); send_char(' '); */ temp=read_temp(); read_adc(); tempA=result; if((tempA>220)&&(tempA<300)) // ***************************************** { // * LED A and Fan A activated only for * ledA=1; // * temperature A greater than 40'C * //lebih27 ledB=0; // * and temperature B less than 35'C * // ***************************************** } else((tempA>301)&&(tempA<400)) // ***************************************** { // * LED B and Fan B activated only for * ledA=1; // * temperature A less than 40'C and *//lebih 22=26 ledB=1; // * temperature B greater than 35'C * // ***************************************** buzzer=0; } // else if((tempA>210)) // ***************************************************** // { // * All LED A & LED B, Fan A & Fan B and Buzzer * // ledA=0; // * activated for temperature A greater than 40'C *//kurang 21 // ledB=1; // * and temperature B greater than 35'C * // // ***************************************************** // buzzer=1; // } delay(2000); } } } //==================subroutine ADC========================= void read_adc(void) { unsigned short i; unsigned long result_temp=0; for(i=2000;i>0;i-=1) //looping 2000 times for getting average value { ADGO = 1; //ADGO is the bit 2 of the ADCON0 register while(ADGO==1); //ADC start, ADGO=0 after finish ADC progress result=ADRESH; result=result<<8; //shift to left for 8 bit result=result|ADRESL; //10 bit result from ADC result_temp+=result; } result = result_temp/2000; //getting average value } unsigned short read_temp(void) { unsigned short temp; temp=result; return temp; } //==================subroutine DELAY========================== void delay(unsigned short i) { for(;i>0;i--); }
Last edited by a moderator: