samizard
Junior Member level 2
Hello guys, as I am new to pic-controllers there's a problem that I am facing right now.
Currently I'm using Olimex Pic-Maxi-Web development board, it consist of pic18f97j60 controller.
In my current project I want to display analog values from potentiometer on lcd using pic18f97j60.
But I'm facing problem with adc conversion. The board consist of potentiometer connected to RA2 Port/AN2 channel. Following is the program that I made from some examples...->
lcd is showing some number and then garbage values but how will I know if the ADC is working properly...
Please help me with my problem.
Currently I'm using Olimex Pic-Maxi-Web development board, it consist of pic18f97j60 controller.
In my current project I want to display analog values from potentiometer on lcd using pic18f97j60.
But I'm facing problem with adc conversion. The board consist of potentiometer connected to RA2 Port/AN2 channel. Following is the program that I made from some examples...->
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 #include <p18f97j60.h> #include <stdio.h> #define XTAL_FREQ 25000000 #define ldata PORTE #define rs PORTHbits.RH2 #define rw PORTHbits.RH1 #define en PORTHbits.RH0 #define pot PORTAbits.RA2; int x,y,j; char buff[] = ""; void MSDelay(unsigned int itime){ unsigned int i,j; for(i=0;i<itime;i++) for(j=0;j<135;j++); } void lcdcmd(unsigned char value){ ldata = value; rs = 0; rw = 0; en = 1; MSDelay(1); en = 0; } void lcddata(unsigned char value){ ldata = value; rs = 1; rw = 0; en = 1; MSDelay(1); en = 0; } void lcdinit(void){ lcdcmd(0x01); //clear lcd screen MSDelay(20); lcdcmd(0x38); //lcd 2 lines, 5x7 matrix MSDelay(20); lcdcmd(0x0E); //display on, cursor on MSDelay(20); lcdcmd(0x01); //clear screen MSDelay(20); lcdcmd(0x06); //shift cursor right MSDelay(20); lcdcmd(0x80); //line 1, position 0 } void main(){ TRISA = 1; //port A for pot TRISE = 0; //port E for lcd data TRISH = 0; //port H for lcd control lines TRISJ = 0; //port J for led PORTJ = 0; en = 0; //enable pin 0 lcdinit(); //lcd initialization ADCON0 = 0b00001001; //ADC bits ADCON1 = 0b00101100; //.. ADCON2 = 0b00000010; //.. ADCON0bits.ADON = 1; PORTJbits.RJ0 = 1; //port J0 led on while(1){ PORTJbits.RJ0 = 0; PORTJbits.RJ2 = 0; //port J2 led off PORTJbits.RJ1 = 1; //port J1 led on ADCON0bits.GO = 1; //start ADC conversion lcddata('G'); //display G on lcd MSDelay(25); while(ADCON0bits.DONE == 1); //ADC conversion finish lcdcmd(0x01); MSDelay(10); x = ADRESH; x += (ADRESL<<8); itoa(x,buff); //convert int value from x to char and store in buff for(j=0;j<10;j++){ lcddata(buff[j]); //displaying buff } } }
Please help me with my problem.
Last edited by a moderator: