ryujinaga
Newbie level 3
hello
i try to read ADC at pin AN0 from a potentiometer and display the digital measurement.the max output voltage of the potentiometer is 5V and to get the digital measurement=vin/5x1023...but then at my lcd show measurement 255 instead 1023. from datasheet, the pic is 10 bit. please explain to me why this happen???
the coding
best regard
i try to read ADC at pin AN0 from a potentiometer and display the digital measurement.the max output voltage of the potentiometer is 5V and to get the digital measurement=vin/5x1023...but then at my lcd show measurement 255 instead 1023. from datasheet, the pic is 10 bit. please explain to me why this happen???
the 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 #include <16F877A.h> // type of micricontroller #fuses HS,NOWDT,NOLVP,NOPROTECT // high speed oscillator, no watch dog timer #use delay (clock=20M) //20MHz crystal #include <lcd.c> #define LCD_ENABLE_PIN PIN_D0 ////set lcd port #define LCD_RS_PIN PIN_D1 //// #define LCD_RW_PIN PIN_D2 //// #define LCD_DATA4 PIN_D4 //// #define LCD_DATA5 PIN_D5 //// #define LCD_DATA6 PIN_D6 //// #define LCD_DATA7 PIN_D7 float ALL; void main() { set_tris_b(0x00); //set port b as output set_tris_C(0x00); //set port c as output output_b(0x00); //reset port b output_c(0x00); //reset port c setup_adc(ADC_CLOCK_INTERNAL); // set internal clck for ADC setup_adc_ports(ALL_ANALOG); //set s analog input lcd_init(); while (true) { delay_ms(200); set_adc_channel(0); ALL=read_adc(); lcd_gotoxy(1,1); printf(lcd_putc,"\fVDIG=%0.1f",(float)ALL); } }
best regard
Last edited by a moderator: