prem123
Newbie level 5
can somebody give me a sample code for A/D conversion in mikroc for 18f4431..
or please tell me the error in the following code...
or please tell me the error in the following code...
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 unsigned int temp_res; void interrupt() { if(PIR1.ADIF){ PIR1.ADIF=0; ADCON0.GO=1; }} void main() { TRISB=0x00; TRISD=0x00; TRISA=0xFF; ANSEL0=0b00000001; ANSEL1=0x00; ADCHS=0x00; ADCON0=0b00110101; ADCON1=0b00010000; ADCON2=0b01000001; ADCON3=0b11000000; INTCON.GIE=1; INTCON.PEIE=1; ADCON0.GO=1; PIE1.ADIE=1; PIR1.ADIF=0; Delay_us(10); while(1) { PORTD= 0x00; PORTB= 0x00; temp_res=Adc_Read(0); PORTD = temp_res; // Send lower 8 bits to PORTD PORTB = temp_res >> 2; // Send 2 most significant bits to RB7, RB6 Delay_ms(50); } }
Last edited by a moderator: