[SOLVED] PIC problem with GO done bit in ADC

Submitted by Baiju on Mon, 11/12/2018 - 22:19

HI

The PIC16F877A Projects are excellent study material. I reached up to the ADC project. Here I am facing some problems with GO_nDONE the compiler is throwing some error. Request your help. I am sending the code to u. I am trying to read an analogue signal and trying to diplay in LCD 16x2. also I dont know How to convert Float into String type kindly help I am not much familiar with c for most of my works I use VB. I am attaching the code and o/p below

 

// PIC16F877A Configuration Bit Settings

// 'C' source line config statements

// CONFIG
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON       // Power-up Timer Enable bit (PWRT enabled)
#pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF        // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF        // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#define _XTAL_FREQ 20000000
#define RS RD2
#define EN RD3
#define D4 RD4
#define D5 RD5
#define D6 RD6
#define D7 RD7
#include <xc.h>
#include "MyLCD.h";

     void ADC_Initialize()
    {
        ADCON0 = 0b01000001;//ADC ON and Fosc/16 is selected
        ADCON1 = 0b11000000;//Internal reference voltage is selected
    } 
    
    unsigned int ADC_Read(unsigned char channel)
    {
        ADCON0 &= 0x11000101;//Clearing the channel selection bits
        ADCON0 |= channel<<3;// setting the required channel bits
        __delay_ms(2)//Acqusition time for charge Hold capicitor
        GO_nDONE = 1;//Initializes A/D conversion             LINE 40 ??????????????????
        //ADCON0<2> = 1;
        while(GO_nDONE);// Wait for A/D conversion to complete
        //while(ADCON0<2>);
        return((ADRESH<<8)+ADRESL);//Returns Result        
    }
    void main()
    {
    //*****I/O Configuration****//
    unsigned int a;
    int flag = 0;//For creating delay 
    float adc = 0.0;
    float i = 0.0;
    char St;
    TRISC = 0x00;//Instruct the MCU that all pins of port C are out put
    PORTC = 0x00;//Initialize all pins to zero
    TRISD = 0x00;//Instruct the MCU that all pins of port D are out put
    PORTD = 0x00;//Initialize all pins to zero
    //*****End of I/O Configuration****//
    Lcd_Start();
    ADC_Initialize();
    while(1)
    {
        if(flag>=50)//wait till flag reaches 50
        {
        adc = (ADC_Read(4));
        i = adc*0.488281;
        //St = i;
        //St = St & " " & "V";
        Lcd_Clear();
        Lcd_Set_Cursor(1,1);
        Lcd_Print_String(i);//HOW CAN I CONVERT i TO STRING HERE ???????????????????????? line 71
        flag = 0;//only if flag = 50 i will get the adc value        
        }        
        flag++;//Increment flag for each cycle
    }        
    }

THE COMPILER O/P

 

make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'C:/MPLABXProjects/ADconversion.X'
make  -f nbproject/Makefile-default.mk dist/default/production/ADconversion.X.production.hex
make[2]: Entering directory 'C:/MPLABXProjects/ADconversion.X'
"C:\Program Files (x86)\Microchip\xc8\v1.38\bin\xc8.exe" --pass1  --chip=16F877A -Q -G  --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=-3 --asmlist -DXPRJ_default=default  --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-osccal,-resetbits,-download,-stackcall,+clib   --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s"    -obuild/default/production/ADconversion.p1  ADconversion.c 
MyLCD.h:34: warning: (371) missing basic type; int assumed
ADconversion.c:40: error: (195) expression syntax
ADconversion.c:71: error: (182) illegal conversion between types
double -> pointer to unsigned char
(908) exit status = 1
nbproject/Makefile-default.mk:100: recipe for target 'build/default/production/ADconversion.p1' failed
make[2]: Leaving directory 'C:/MPLABXProjects/ADconversion.X'
nbproject/Makefile-default.mk:84: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/MPLABXProjects/ADconversion.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make[2]: *** [build/default/production/ADconversion.p1] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 6s)

THANKS

BAIJU

 

Hi Baiju, Welcome to circuitdigest forums.

I am not sure how exactly does your librarey mylcd.h works. but you cannot print float values like this 

        i = adc*0.488281;

        Lcd_Print_String(i)

You have to break the varibale i from float type into char type by spliting it into numbers and then print these numbers. To give you an idea of how it is done I am pasting the code from my Thermometer project 

  adc = (ADC_Read(4)); // Reading ADC values
        volt = adc*4.88281; // Convert it into the voltage
        temp=volt/10.0;  // Getting the temperature values
        temp1 = temp*100;
        c1 = (temp1/1000)%10;
        c2 = (temp1/100)%10;
        c3 = (temp1/10)%10;
        c4 = (temp1/1)%10;

As can see here the varibale temp is of float type but to print the values in it we have convert it to int type by multiplying with 100 to remove the decimal number this resulting int value is stored in temp 1.

Then temp 1 has to be split into characters that is it has four digits and each digit has to be stored in a varibale. This can be done by using the modulus and divide option as shown above where c1, c2, c3 and c4 has the four digits from temp 1. Not c1,c2,3c3 and c4 are still in type int 

Finally you can print them like you print any charectors as shown below

  Lcd_Clear();
        Lcd_Set_Cursor(1,3);
        Lcd_Print_String("Temperature");
        Lcd_Set_Cursor(2,5);
        Lcd_Print_Char(c1+'0');
        Lcd_Print_Char(c2+'0');
        Lcd_Print_String(".");
        Lcd_Print_Char(c3+'0');
        Lcd_Print_Char(c4+'0');

With every variable we add +'0' to convert the int into char. and we also print a "." after printign two digits to make it appear like a decimal number.

Hope you got the idea.

Happy learnign !

 

  Joined August 16, 2016      998
Tuesday at 12:29 AM

Thank u Aswinth,

I will try ur suggestion. but what about line 40 I have marked with ??????  GO_nDONE = 1; gives error Expression Syntax error 195

what to do with this error I tried by adding TRISA5 = 1; but didnt work. how can I solve it.

LCD worked & Printed CIRCUIT DIGEST     

                                       WORKING     in the previous tutorial. Interfacing LCD with PIC 

Thanks 

BAIJU

  Joined November 12, 2018      5
Monday at 09:51 PM

The compile time error is because of the semi-colon missin in your program 

     __delay_ms(2)//Acqusition time for charge Hold capicitor
        GO_nDONE = 1;//Initializes A/D conversion             LINE 40 ??????????????????

the delay statement above the GOnDONE=1 is missing a semi-colon

  Joined August 16, 2016      998
Tuesday at 12:29 AM

Thank u very much Aswinth,

Its Working now.

BAIJU

  Joined November 12, 2018      5
Monday at 09:51 PM

Hi Aswinth,

For the UART tutorial, I have maxim232 IC & my computer has a COM port. Can I connect to the comport TX RX instead of RS to USB converter?

If yes, will the Hyper terminal  help me for the communication?  Is there any thing else that should be taken care of?

Thanks in advance.

Baiju.

  Joined November 12, 2018      5
Monday at 09:51 PM

Jayant

In reply to by Baiju

Permalink

I am closing this thread since the original question was already answered. Please post as new thread if you have other questions.

 

Thanks

  Joined May 19, 2015      213
Tuesday at 03:45 PM