Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

EEPROM PROBLEM in PIC 18f4550

Status
Not open for further replies.

arunbharathi.arasu

Full Member level 2
Full Member level 2
Joined
Feb 28, 2013
Messages
134
Helped
7
Reputation
14
Reaction score
6
Trophy points
1,298
Location
Chennai, Tamil Nadu, India
Activity points
2,151
Dear all,

Im using PIC18F4550, im writing some data to EEPROM.

Then read form the eeprom and write in to another memory.(Just Check)

i could not find any error in my code .

Please give me some suggestion. in proteus i'm seasoning EEPROM data.

Here is the code.
Code:
// PIC18F4550 Configuration Bit Settings


// 'C' source line config statements


#include <htc.h>


//#pragma config CONFIG1L = 0x0
__CONFIG(1, PLLDIV_1 & CPUDIV_OSC1_PLL2 & USBDIV_1);
//#pragma config CONFIG1H = 0x5
__CONFIG(2, FOSC_EC_EC & FCMEN_OFF & IESO_OFF);
//#pragma config CONFIG2L = 0x1F
__CONFIG(3, PWRT_OFF & BOR_ON & BORV_3 & VREGEN_OFF);
//#pragma config CONFIG2H = 0x1E
__CONFIG(4, WDT_OFF & WDTPS_32768);
//#pragma config CONFIG3H = 0x2
__CONFIG(5, CCP2MX_OFF & PBADEN_ON & LPT1OSC_OFF & MCLRE_OFF);
//#pragma config CONFIG4L = 0x80
__CONFIG(6, STVREN_OFF & LVP_OFF & ICPRT_OFF & XINST_OFF);
//#pragma config CONFIG5L = 0xF
__CONFIG(7, CP0_OFF & CP1_OFF & CP2_OFF & CP3_OFF);
//#pragma config CONFIG5H = 0xC0
__CONFIG(8, CPB_OFF & CPD_OFF);
//#pragma config CONFIG6L = 0xF
__CONFIG(9, WRT0_OFF & WRT1_OFF & WRT2_OFF & WRT3_OFF);
//#pragma config CONFIG6H = 0x60
__CONFIG(10, WRTC_OFF & WRTB_OFF & WRTD_ON);
//#pragma config CONFIG7L = 0xF
__CONFIG(11, EBTR0_OFF & EBTR1_OFF & EBTR2_OFF & EBTR3_OFF);
//#pragma config CONFIG7H = 0x40
__CONFIG(12, EBTRB_OFF);






#include "strings.h"


unsigned char ReadData;




void delay(unsigned int de)
{
    unsigned int maxde,minde;
    for(maxde=0;maxde<de;maxde++)
        for(minde=0;minde<453;minde++);
}


void Write_b_eep( unsigned int badd,unsigned char bdat )
 {
       //EEADR =0x00;
     EEADR = (badd & 0x0ff);


     EEDATA =bdat;
     EECON1bits.EEPGD = 0;
     EECON1bits.CFGS = 0;
     EECON1bits.WREN = 1;
     INTCONbits.GIE = 0;
     EECON2 = 0x55;
     EECON2 = 0xAA;
     EECON1bits.WR = 1;
 //while(EECON1bits.WR);
     INTCONbits.GIE = 1;
     EECON1bits.WREN = 0;
 }
 unsigned char Read_b_eep( unsigned int badd )
 {
     EEADR = (badd & 0x0ff);
     EECON1bits.CFGS = 0;
     EECON1bits.EEPGD = 0;
     EECON1bits.RD = 1;
     return( EEDATA );              // return with read byte
 }
 void main(void)
 {
     port1_init();
     UART_init();
     
     trans_string("PIC18F4550 EEPROM");
     while(1)
     {
         Write_b_eep(0x0069,0x0010);
         delay(100);
         ReadData=Read_b_eep(0x0069);
         delay(100);
         Write_b_eep(0x006C,ReadData);
         delay(1000);
     }
                    
  
 }
 

Hi,

i could not find any error in my code .

You even didn't describe any error.
So we have to assume your code us correct.

Why searching for an error if there is no error?

Klaus
 

hi klausst,

if my code is working properly i will not search error.

But my code was not working. So i said "i cound not find any error".

But Now Its working to enable " while(EECON1bits.WR);" this line. thanks for your reply.
 

hi,

Now i'm struggling with another problem.

I can able to write a string in different location.

I can read string from any location.

But the problem is : if am reading string data from any location i can read.
But continuously am reading data from different location is not possible.

am reading continuously, data can be read eaither all eeprom data or 2 more different location data.

Please suggest me how to read different location data from EEPROM.

Thanks in advance..
 

Hi,

Again you don't give any error description. Therefore you don't get any replies.

--> say what you expect ... and say what happens instead.

************
But continuously am reading data from different location is not possible.
What does "is not possible" mean? --> does the chip explode?

Read forum rules.
With a good error description you get good replies.

Klaus
 

Dear KlausST,

I successfully write data in EEPROM.

Data is nothing but IP address and Port value. IP Address is stored in address 30 and Port value is stored in 50.

IP is Stored Address From 30 to 45 and And port is stored Address from 50 to 55.

Now I want to read IP address and Port value from EEPROM and store in to variable x[] and y[].

When i only read IP value form address 30, I can read and store in x[].

when i onlu read port value from address 50. I can read and store y[].

But if i am reading IP address from address 30 and then read port value from address 50.

both values are stored in x and some other value is stored in y.


And also SERIAL interrupt is not working if iam reading data from EEPROM.
 

Hi,

IP is Stored Address From 30 to 45
IP address usually are only 4 bytes. Each with integer values form 0 to 255.
IPv6 uses 6 bytes...
It seems you don´t store it as 4 or 6 bytes. So how do you store the values? How are the values coded/decoded? And how is it delimited?

Port usually is a two byte value.

******
What have you done to debug your issue?
Did you read out EEPROM contents and did you compare the EEPROM contents with your variable x, y contents?

Klaus
 

What you have described in message #6 does not match up with the code you have provided at the start of this thread.
Perhaps it is time to show us your code.
Susan
 

Dear friends,

Thanks for your reply.

KlausST :

I have ip address 48.56.12.181 in unsigned char[].

In the above address first letter 4 is stored in address 30. And remaining will store continuous address.

Because here 4 is character.

Am I right??

Code:
unsigned char x[20],len,i;

void EEPROM_Read_string(unsigned int saddr)
{   
    i=0;
    do
    {
        x[i]=EEPROM_Read(saddr+i);
        i++;
    }while(x[i] !='#');
    x[i]='\0';
    
void EEPROM_Write()
{
    EECON1bits.WREN = 0;
    EECON1bits.EEPGD = 0;    //Points to EEPROM
    EECON1bits.CFGS = 0;    //Points to Flash and EEPROM
    EECON1bits.WREN = 1;    //EEPROM Write Enable bit
    INTCONbits.GIE = 0;        //Disable all Interrupts
    EECON2 = 0x55;
    EECON2 = 0xAA;
    EECON1bits.WR = 1;        //WR Control bit initiates Write Operation
    INTCONbits.GIE = 1;
    while(!PIR2bits.EEIF);
    PIR2bits.EEIF = 0;    
}

void EEPROM_Write_String(unsigned char msg[],unsigned char address)
{
    len = strlen(msg);
    for(i=0;i<len;i++)
    {
        EEADR = address + i;
        EEDATA = msg[i];
        EEPROM_Write();
    }
    EEADR = address + i;
    EEDATA ='#';
    EEPROM_Write();
    
}

unsigned char EEPROM_Read(unsigned int addr)
{
    EEADR = addr;
    EECON1bits.EEPGD = 0;    //Point to EEPROM
    EECON1bits.CFGS = 0;    //Points to Flash and EEPROM
    EECON1bits.RD = 1;        //EEPROM Read Enable Bit
    return(EEDATA);
}

The above is my code I used # symbol. To stop reading when i read continuous data form EEPROM. when i get # symbol Reading from EEPROM is stop.

in the above code if i call EEPROM_Read_string(address) funtion only one time. I can get data properly.

if i call the function another time with different address, I can not get proper data.

Note: Also Serial Interrupt will not work. If iam reading EEPROM data.
 

Hi,

We can not know if your address is stored as a string.
We can not know what values you read.
We can not know what the EEPROM contents are after writing.
We can not know what your main loop does (how it processes the data)

If you are not interested in giving useful error descriptions, code, expectations, ... I think you are not interested in an answer.

***
Example: "I tried to visit my mother by car. But it's impossible. Please help me."
--> it simply is not enough information .... countless possible problems.

Klaus
 

The logic in your 'Read_EEPROM_string' function is wrong.
You read a character into 'x' and then increment the 'i' variable but THEN check to see if the character at 'x' is the terminator. The problem us that 'x' now points at the location *AFTER* the one just read.
Susan
 

dear Aussie Susan ,

data is in eeprom is: 49.58.23.181#.

I'm Reading x,Now i=0, x points character 4. read that char.
and increment i, Now i=1, x[1] points charcter 9. read that char. this process will contineous untill x[] read (49.58.23.181)

Then increment i, and check x. so x points '#'. in this case while loop exit.

now Array char x[]=49.58.23.181.

- - - Updated - - -

We can not know if your address is stored as a string.
We can not know what values you read.
We can not know what the EEPROM contents are after writing.
We can not know what your main loop does (how it processes the data)

If you are not interested in giving useful error descriptions, code, expectations, ... I think you are not interested in an answer.

***
Example: "I tried to visit my mother by car. But it's impossible. Please help me."
--> it simply is not enough information .... countless possible problems.

Code:
void main() 
{
    UART_init();
    EEPROM_Write_String("49.50.23.181",30);    
    EEPROM_Read_string(30);
    trans_string(x);                                                      
    while(1);    
}

The above code i will get right data. output is 49.50.23.181

Code:
void main() 
{
    UART_init();
    EEPROM_Write_String("49.50.23.181",30);    
    delay(1000);
    EEPROM_Write_String("5201",45); 
    delay(1000);
    EEPROM_Read_string(30);
    trans_string(x);            
    delay(1000);
    EEPROM_Read_string(45);
    trans_string(x);                                         
    while(1);    
}

Now 1 trans_string(x) function output is :49.50.23.181 5201
And 2 trans_string(x) function output is 5201 49.50.23.181 5201 ..


This is my Error.
 

And I have explained exactly why you get what you do in my previous post. However lets go through it step by step.
The original code is
Code:
void EEPROM_Read_string(unsigned int saddr)
{   
    i=0;
    do
    {
        x[i]=EEPROM_Read(saddr+i);
        i++;
    }while(x[i] !='#');
    x[i]='\0';
(I note the missing trailing "}" in your posting but I assume that is a 'cut-and-paste' error.)
Lets start with I = 0 and saddr = 30. Lets also assume that the array X is all null characters (actually just about any random set of values will do).
That means the first time through the loop the statement
Code:
x[i]=EEPROM_Read(saddr+i);
is effectively:
Code:
x[0]=EEPROM_Read(30);
So we read from EEPROM address 30 and overwrite the null at X[0] with the character.
Next we execute the statement:
Code:
i++;
I now becomes 1.
We now come to the statement:
Code:
}while(x[i] !='#');
As I is now 1, this is the same as:
Code:
}while(x[1] !='#');
But we have not yet written into 'X[1]' (remember we wrote into 'x[0]' just before) and so we are comparing the assumed previous value (a null) against the literal '#' character. Therefore we go around the loop again but with i equal to 1 this time. THat mades the code equivalent to:
Code:
x[1]=EEPROM_Read(31);
Lets say this time that the EEPROM address 31 actually IS a '#' character; in other words that this is the terminator we are looking for. Therefore X[1] holds the '#' character.
We now perform the next statement:
Code:
i++;
and I becomes 2.
Now we look at the loop terminating code again:
Code:
}while(x[i] !='#');
which is now equivalent to:
Code:
}while(x[2] !='#');
Therefore we compare x[2] to '#'. However we have not yet written to X[2] (we actually wrote the '#' into X[1]) and so we again compare whatever was in that location before we started with the '#'. Chances are that it will not match and so we go around the loop again.
This is *NOT* what is wanted and so the logic must be wrong.
Eventually you will get to a point where 'x' just so happens to match the '#' character somewhere in memory and your function will exit.
The reason I think your first program appears to be working is that the EEPROM probably starts with all null characters. Therefore the function will start reading these null characters after it passes the end of the valid string. I don't know what 'trans_string' does but I'm assuming it outputs the string until it comes to a trailing null. Therefore it will stop outputting at the right place because of these nulls, and NOT because of anything your code has done.
There are many ways to fix the problem but the key is that you must compare the character you have just read with the '#' character before you increment 'i'.
Susan
 
dear Aussie Susan,


Thanks for your valuable reply. and i have changed . but still i am facing the same problem.

When i call the function in second time data will not read properly.

and also serial interrupt will not work.
 

Hi,

still missing a lot of informations....

When i call the function in second time data will not read properly.
Please tell us exactely why you know it is caused by the "read function"?
Why it can´t be a problem of the trans_string(x) function?

--> you don´t show us the trans_string() function. You just show us a piece of your code.
--> and you don´t show us what the function needs to operate correctely.

*****

and also serial interrupt will not work.
You said this several times.
--> But you never said how you come to that conclusion.
--> And you don´t show us any serial interrrupt declaration/function.

*****
Is it asking too much for a hex dump of the EEPROM contents? address area 20 ...60 at least..


Klaus
 

dear Aussie Susan,

thanks a lot.

Yes, i used different variable for different call. now i can read.

Please give some idea:

Actually in my project. i used gsm for ADC value is continuously send to the IP.

In between this process if GSM Received any msg, Controller has to read the message and respond. This is requirement.

Actually what happen means. If i am not using ADC , Controller Read message and do the process properly. Process may differ like reply the sms, change APN depends on the incoming message.

But using ADC commends, ADC process will do properly but during this process SERIAL INTERRUPT(to read sms) is not working.

I set SERIAL INTERRUPT as high priority.
 

I can only say yet again, please show is *ALL* of your code.
As you have seen already, once we have seen the code we at least have a chance to find any logical errors; without the code we do not have a hope.
Susan
 

Are the code a "secret"? or can you post the full code?
 

Dear Friends,

Thanks for your reply.

Are the code a "secret"? or can you post the full code?

Not like that.
here my code is:
Source code:
Code:
// PIC18F2550 Configuration Bit Settings

// 'C' source line config statements

#include <htc.h>

//#pragma config CONFIG1L = 0x0
__CONFIG(1, PLLDIV_1 & CPUDIV_OSC1_PLL2 & USBDIV_1);
//#pragma config CONFIG1H = 0x5
__CONFIG(2, FOSC_EC_EC & FCMEN_OFF & IESO_OFF);
//#pragma config CONFIG2L = 0x1F
__CONFIG(3, PWRT_OFF & BOR_ON & BORV_3 & VREGEN_OFF);
//#pragma config CONFIG2H = 0x1E
__CONFIG(4, WDT_OFF & WDTPS_32768);
//#pragma config CONFIG3H = 0x83
__CONFIG(5, CCP2MX_ON & PBADEN_ON & LPT1OSC_OFF & MCLRE_ON);
//#pragma config CONFIG4L = 0x80
__CONFIG(6, STVREN_OFF & LVP_OFF & XINST_OFF);
//#pragma config CONFIG5L = 0xF
__CONFIG(7, CP0_OFF & CP1_OFF & CP2_OFF & CP3_OFF);
//#pragma config CONFIG5H = 0xC0
__CONFIG(8, CPB_OFF & CPD_OFF);
//#pragma config CONFIG6L = 0xF
__CONFIG(9, WRT0_OFF & WRT1_OFF & WRT2_OFF & WRT3_OFF);
//#pragma config CONFIG6H = 0xE0
__CONFIG(10, WRTC_OFF & WRTB_OFF & WRTD_OFF);
//#pragma config CONFIG7L = 0xF
__CONFIG(11, EBTR0_OFF & EBTR1_OFF & EBTR2_OFF & EBTR3_OFF);
//#pragma config CONFIG7H = 0x40
__CONFIG(12, EBTRB_OFF);





#include<stdio.h>
#include <string.h>
#include"uartgsm.h"
#include"adc.h"
#include "GSM_READ.H"
#include "EEPROM.h"




#define  Sw RB1


unsigned char g_bitRxFlag,Rx_data;
unsigned char *arrayptr;

unsigned char *data,msgflag=0,CHECK[10],imeidata[20],clktime[20];
extern unsigned char cmd[20],y[20];
unsigned char Arraydata[160],idata[20],pdata[10];
unsigned int RC_BIT_Flag=0,count=0,count1=0,flag,m=0;
unsigned char *ok="OK",*error="ERROR",*newmsg="+CMTI: \"SM\",1";


void EEPROM_Read_string(unsigned int saddr);
unsigned char EEPROM_Read(unsigned int addr);
void EEPROM_Write_String(unsigned char msg[],unsigned char address);



void port_init()
{
    PCFG3=0;
    PCFG2=1;
    PCFG1=0;
    PCFG0=1;
    TRISB1=1;
    TRISB6=0;
    TRISB7=0;
    RB6=1;
    RB7=0;
}
void delay(unsigned int de)
{
    unsigned int maxde,minde;
    for(maxde=0;maxde<de;maxde++)
        for(minde=0;minde<453;minde++);
}

void interrupt uart_ISR() @ 0x0008
{
    if(RCIF == 1)
    {
        Rx_data=RCREG;
        RCIF=0;
         
        if(flag == 1)
        {
            if(Rx_data!= 0x0A)
           {
             Arraydata[count]= Rx_data; 
             count++;
           }
           else
           {
            Arraydata[count]='\0';
           }
            arrayptr=Arraydata;
        }
        else if(flag == 2)
        {
            if(Rx_data!= 0x0A)
           {
             imeidata[count]= Rx_data; 
             count++;
           }
           else
           {
            imeidata[count]='\0';
            }
        }
        else if(flag == 3)
        {
            if(Rx_data!= 0x0A)
           {
             clktime[count1]= Rx_data; 
             count1++;
           }
           else
           {
            clktime[count1]='\0';
            }
        }
    
        else
        {
            if(Rx_data!= 0x0A)
           {
             CHECK[count]= Rx_data; 
             count++;
           }
           else
           {
            CHECK[count]=0;
            count=0;
            }
            arrayptr=CHECK;
        }
        if(strstr(arrayptr,ok))
       {
           RC_BIT_Flag=1;
       }
       else if(strstr(arrayptr,error))
       {
           RC_BIT_Flag=0;   
       }
       else if(strstr(arrayptr,newmsg))
       {
         msgflag=1; 
       }
       else if(strstr(arrayptr,"ALREADY CONNECT"))
       {
           RC_BIT_Flag=2;
       }
       else;
      
}
}

void SEPARATE()
{ 
    m=-1;
    do
    {
       m++;
      idata[m]=EEPROM_Read(30+m);
    }while(idata[m] != '#');
    idata[m]='\0';
    
     m=-1;
    do
    {
        m++;
        pdata[m]=EEPROM_Read(50+m);
    }while(pdata[m] != '#');
    pdata[m]='\0';

}
void main()
{  
    port_init();
    port1_init();
    adc_init();
    UART_init();
    GSM_INIT();
    READ_IMEI();
    RB7=1;
    
   SEPARATE();
   SET_HTTP(idata,pdata);
         
    while(1)
    {
        if(msgflag==1)
        {
         MSG_READ();
         count=0;
         delay(1000);
         msgflag=0;
        }
        if(RC_BIT_Flag == 0)
        {
         SET_HTTP(idata,pdata);   
        }
       SEND_SERVER();
        delay(1000);
}
     
  }

UART CODE:uartgsm.h
Code:
#ifndef UARTGSM_H
#define    UARTGSM_H

#define transmitter    RC6
#define rec            RC7


extern void delay(unsigned int del);

void port1_init()
{
    TRISC6=0;
    TRISC7=1;
}
void transmitter_data(unsigned char dat)
{
    while(!TRMT);
    TXREG=dat;
}
void trans_string(unsigned char *str)
{
    while(*str!='\0')
    {
      transmitter_data(*str);
      str++;
      delay(100);
    }
}


void UART_init()
{
    TXEN    =   1;  //  transmission side enable
    SYNC    =   0;  //  enable asynchronous bit
    BRGH    =   1;  //  enable high baud rate generator
    TRMT    =   0;  //  make transmit shift register are full
    TX9D    =   0;  //  disable 9bit transmission

    SPEN    =   1;  //  enable serial port in receiver side
    CREN    =   1;  //  enable continuous reception
    ADDEN   =   0;  //  disable address decets bit
    FERR    =   0;  //  set no framing error bit
    OERR    =   0;  //  set no overrun bit
    RX9D    =   0;  //  disble 9bit reception

    SPBRG   =   129;//  load SPBRG value for 9600 baud rate for 20 mhz
    GIE     =   1;
 
   
    
    IPEN   = 1;
    GIEH  = 1;
    GIEL  = 1;
    PEIE    =   1;
    RCIE    =   1;
    RCIP  = 1;
  
}




    

#endif    /* UARTGSM_H */


EEPROM code: EEprom.h

Code:
/* 
 * File:   EEPROM.h
 * Author: Arun
 *
 * Created on December 26, 2016, 11:09 AM
 */
#ifndef EEPROM_H
#define    EEPROM_H


void EEPROM_Write();

unsigned char EEPROM_Read(unsigned int addr);
void EEPROM_Read_string(unsigned int saddr);

unsigned char x[20],len,i;

void EEPROM_Read_string(unsigned int saddr)
{   
    i=-1;
    do
    {
        i++;
        x[i]=EEPROM_Read(saddr+i);
    }while(x[i] !='#');
    x[i]='\0';
}


void EEPROM_Write()
{
    EECON1bits.WREN = 0;
    EECON1bits.EEPGD = 0;    //Points to EEPROM
    EECON1bits.CFGS = 0;    //Points to Flash and EEPROM
    EECON1bits.WREN = 1;    //EEPROM Write Enable bit
    INTCONbits.GIE = 0;        //Disable all Interrupts
    EECON2 = 0x55;
    EECON2 = 0xAA;
    EECON1bits.WR = 1;        //WR Control bit initiates Write Operation
    INTCONbits.GIE = 1;
    while(!PIR2bits.EEIF);
    PIR2bits.EEIF = 0;    
}

void EEPROM_Write_String(unsigned char msg[],unsigned char address)
{
    len = strlen(msg);
    for(i=0;i<len;i++)
    {
        EEADR = address + i;
        EEDATA = msg[i];
        EEPROM_Write();
    }
    EEADR = address + i;
    EEDATA ='#';
    EEPROM_Write();
    
}

unsigned char EEPROM_Read(unsigned int addr)
{
    EEADR = addr;
    EECON1bits.EEPGD = 0;    //Point to EEPROM
    EECON1bits.CFGS = 0;    //Points to Flash and EEPROM
    EECON1bits.RD = 1;        //EEPROM Read Enable Bit
    return(EEDATA);
}

#endif    /* EEPROM_H */

ADC code: adc.h

Code:
/* 
 * File:   adc.h
 * Author: Arun
 *
 * Created on December 24, 2016, 10:52 AM
 */

#ifndef ADC_H
#define    ADC_H

unsigned int ADC_value,ADC_value0,ADC_value1,ADC_value2,ADC_value3,ADC_value4,ADC_value5,ADC_value6,ADC_value7,ADC_value8,ADC_value9,ADC_value10,ADC_value11,ADC_value12, ADC_final;
unsigned int ADC_DATA[10],ADC_DATA1[10],ADC_DATA2[10],ADC_DATA3[10],ADC_DATA4[10],ADC_DATA5[10],ADC_DATA6[10],ADC_DATA7[10],ADC_DATA8[10],ADC_DATA9[10],ADC_DATA10[10],ADC_DATA11[10],ADC_DATA12[10];
extern void delay(unsigned int de);

unsigned int  ADC_channe0()
{
   
    CHS0=1;
    CHS1=0;
    CHS2=0;
    CHS3=0;
    ADON=1;
    GO_DONE=1;
    
    ADC_value=ADRESH;
    ADC_value=((ADRESH<<8)|ADRESL);
    return ADC_value;
}

unsigned int  ADC_channe1()
{
    CHS0=0;
    CHS1=1;
    CHS2=0;
    CHS3=0;
    ADON=1;
    GO_DONE=1;
    ADC_value1=ADRESH;
    ADC_value1=((ADRESH<<8)|ADRESL); 
  
    return ADC_value1;
    
}

unsigned int  ADC_channe2()
{
    CHS0=1;
    CHS1=1;
    CHS2=0;
    CHS3=0;
    ADON=1;
    GO_DONE=1;
    ADC_value2=ADRESH;
    ADC_value2=((ADRESH<<8)|ADRESL);    
  
    return ADC_value2;
}
unsigned int  ADC_channe3()
{
    CHS0=0;
    CHS1=0;
    CHS2=1;
    CHS3=0;
    ADON=1;
    GO_DONE=1;
    ADC_value3=ADRESH;
    ADC_value3=((ADRESH<<8)|ADRESL);
    
    return ADC_value3;
}
unsigned int  ADC_channe4()
{
    CHS0=1;
    CHS1=0;
    CHS2=1;
    CHS3=0;
    ADON=1;
    GO_DONE=1;
    ADC_value4=ADRESH;
    ADC_value4=((ADRESH<<8)|ADRESL);  

    return ADC_value4;
}

unsigned int  ADC_channe5()
{
    CHS0=0;
    CHS1=1;
    CHS2=1;
    CHS3=0;
    ADON=1;
    GO_DONE=1;
    ADC_value5=ADRESH;
    ADC_value5=((ADRESH<<8)|ADRESL);  
      delay(100);
    return ADC_value5;
}

unsigned int  ADC_channe6()
{
    CHS0=1;
    CHS1=1;
    CHS2=1;
    CHS3=0;
    ADON=1;
    GO_DONE=1;
    ADC_value6=ADRESH;
    ADC_value6=((ADRESH<<8)|ADRESL);   
      delay(100);
    return ADC_value6;
}

unsigned int  ADC_channe7()
{
    CHS0=0;
    CHS1=0;
    CHS2=0;
    CHS3=1;
    ADON=1;
    GO_DONE=1;
    ADC_value7=ADRESH;
    ADC_value7=((ADRESH<<8)|ADRESL);    
      delay(100);
    return ADC_value7;
}
unsigned int  ADC_channe8()
{
    CHS0=1;
    CHS1=0;
    CHS2=0;
    CHS3=1;
    ADON=1;
    GO_DONE=1;
    ADC_value8=ADRESH;
    ADC_value8=((ADRESH<<8)|ADRESL);     
    delay(100);
    return ADC_value8;
}
unsigned int  ADC_channe9()
{
    CHS0=0;
    CHS1=1;
    CHS2=0;
    CHS3=1;
    ADON=1;
    GO_DONE=1;
    ADC_value9=ADRESH;
    ADC_value9=((ADRESH<<8)|ADRESL); 
    delay(100);
    return ADC_value9;
}
unsigned int  ADC_channe10()
{
    CHS0=0;
    CHS1=0;
    CHS2=0;
    CHS3=0;
    ADON=1;
    GO_DONE=1;
    ADC_value10=ADRESH;
    ADC_value10=((ADRESH<<8)|ADRESL);   
    
      delay(100);
    return ADC_value10;
}
//unsigned int  ADC_channe11()
//{
//    CHS0=1;
//    CHS1=1;
//    CHS2=0;
//    CHS3=1;
//    ADON=1;
//    GO_DONE=1;
//    ADC_value11=ADRESH;
//    ADC_value11=((ADRESH<<8)|ADRESL);
//     delay(100);
//    return ADC_value11;
//}
//unsigned int  ADC_channe12()
//{
//    CHS0=0;
//    CHS1=0;
//    CHS2=1;
//    CHS3=1;
//    ADON=1;
//    GO_DONE=1;
//    ADC_value12=ADRESH;
//    ADC_value12=((ADRESH<<8)|ADRESL);
//    return ADC_value12;
//}
void ADC_VALUE_SEND(unsigned char *name,unsigned char *value)
{
    trans_string(name);
    trans_string(value);
    delay(100);
}
void ADC_READ()
{
    ADC_channe0();
    sprintf(ADC_DATA,"%d",( ADC_value/85));  
    ADC_VALUE_SEND("BT0=",ADC_DATA);
    delay(100);
    
     
    ADC_channe1();
    sprintf(ADC_DATA1,"%d",( ADC_value1/85));  
    ADC_VALUE_SEND(",BT1=",ADC_DATA1);
    delay(100);
    
    ADC_channe2();
    sprintf(ADC_DATA2,"%d",( ADC_value2/85)); 
    ADC_VALUE_SEND(",BT2=",ADC_DATA2);
    delay(100);
    
    ADC_channe3();
    sprintf(ADC_DATA3,"%d",( ADC_value3/85));  
    ADC_VALUE_SEND(",BT3=",ADC_DATA3);
    delay(100);
    
    ADC_channe4();
    sprintf(ADC_DATA4,"%d",( ADC_value4/85));  
    ADC_VALUE_SEND(",BT4=",ADC_DATA4);
    delay(100);
    
    ADC_channe5();
    sprintf(ADC_DATA5,"%d",( ADC_value5/85));  
    ADC_VALUE_SEND(",BT5=",ADC_DATA5);
    delay(100);
    
    ADC_channe6();
    sprintf(ADC_DATA6,"%d",( ADC_value6/85));  
    ADC_VALUE_SEND(",BT6=",ADC_DATA6);
    delay(100);
    
    ADC_channe7();
    sprintf(ADC_DATA7,"%d",( ADC_value7/85));  
    ADC_VALUE_SEND(",BT7=",ADC_DATA7);
    delay(100);
    
    ADC_channe8();
    sprintf(ADC_DATA8,"%d",( ADC_value8/85));  
    ADC_VALUE_SEND(",BT8=",ADC_DATA8);
    delay(100);
    
    ADC_channe9();
    sprintf(ADC_DATA9,"%d",( ADC_value9/85));  
    ADC_VALUE_SEND(",BT9=",ADC_DATA9);
    delay(100);
    
    ADC_channe10();
    sprintf(ADC_DATA10,"%d",( ADC_value10/85));  
    ADC_VALUE_SEND(",Temp=",ADC_DATA10);
    delay(100);
}


void adc_init()
{
    ADCS0=0;
    ADCS1=0;
    ADCS2=0;
    ADFM=1;
    ACQT2=1;
    ACQT1=1;
    ACQT0=0;
    VCFG1=0;
    VCFG0=0;
    PCFG3=0;
    PCFG2=0;
    PCFG1=0;
    PCFG0=1;
}

#endif    /* ADC_H */

GSM Comments code:

Code:
/* 
 * File:   GSM_READ.h
 * Author: Arun
 *
 * Created on December 28, 2016, 11:12 AM
 */

#ifndef GSM_READ_H
#define    GSM_READ_H
extern unsigned int RC_BIT_Flag,flag,j=0,count,count1;
extern unsigned char *arrayptr;
extern unsigned char Arraydata[160],imeidata[20],clktime[20];
extern unsigned char *data;
unsigned char num[10],cmd[20],setdata[20],ipnum[10],portnum[10],k=0;
//unsigned char *cmd_check;
unsigned char *imeireq="IMEI,AV2017",*apnset="APN,AV2017",*ipset="IP,AV2017";
//unsigned char data1[80]= "TH+918220882238 @IMEI AV2017 ";
unsigned int step=0;

void EEPROM_Write_String(unsigned char [],unsigned char address);
void MSG_SEND(unsigned char *message);
void SEND_IMEI(unsigned char *imeisend);
void SET_APN(unsigned char *setapn);
void SET_HTTP(unsigned char *inum,unsigned char *pnum);
void SEP_IP_PORT(unsigned char separate[]);
void READ_IMEI();
void ADC_READ();
void GET_TIME();


void CHECK_SMS(unsigned char *sms)
{
    trans_string(sms);
    delay(1000);
    for(k=0;k<=50;k++)
    {
        if(*sms == '"')
        {
            sms++;
            if(*sms == '+')
            {
                j=0;
                while(*sms != '"')
                {
                    num[j]=*sms;
                    sms++;j++;
                }
                k=50;
            }
            else
            sms++;       
        }
        else
        sms++;
    }
    num[j]=0;
    
    sms++;
    while(*sms != '#')
    {
      sms++;
    }
    sms++;
    j=0;
    do
    {
    cmd[j]=*sms;
    sms++;
    j++;
    delay(100);
    }while(*sms !='#');
    cmd[j]='\0';
    sms++;
    j=0;

    
    if(*sms == '#')
    {
        sms++;
        do
        {
        setdata[j]=*sms;
        sms++;
        j++;
        delay(100);
        }while(*sms !='#');
        setdata[j]='\0';
        
        
   
    }
    else;
}
void CHECK_CMD(unsigned char *chk)
{
    if(strstr(chk,imeireq))
        SEND_IMEI(imeidata);
    else if(strstr(chk,apnset))
    {
        EEPROM_Write_String(setdata,0);
        SET_APN(setdata); 
    }
    else if(strstr(chk,ipset))
    {
        j=0;
        do
        {
             ipnum[j]=setdata[j];
             j++;
        }  while(setdata[j] != ',');
        ipnum[j]='\0';
        EEPROM_Write_String(ipnum,30);
     
        
        j++;
        k=0;
        do
        {
            portnum[k]=setdata[j];
            j++;
            k++;
        }while(setdata[j] != '@');
        portnum[k]='\0';
        EEPROM_Write_String(portnum,50);
        //trans_string(portnum);
        trans_string("AT+CMGD=1\r");
        SET_HTTP(ipnum,portnum);
    }
    else if(strstr(chk,"RESET,AV2017"))
    {
        RB6=0;
        delay(1000);
        RB6=1;
        RESET();
        trans_string(chk);
    }
    else
        MSG_SEND("WRONG COMMAND"); 
}

void SET_HTTP(unsigned char *inum,unsigned char *pnum)
{   
    trans_string("AT+CIPMUX=0\r");
    delay(1000);
    while(RC_BIT_Flag != 2)
    {
    trans_string("AT+CIPSTART=\"TCP\",\"");
    trans_string(inum);
    trans_string("\",\"");
    trans_string(pnum);
    trans_string("\"\r");
    delay(1000);
    }
    RC_BIT_Flag=1;
    
    delay(2000);
}

void SEND_SERVER()
{
    flag=3;
    count1=0;
    trans_string("AT+CCLK?\r");
    delay(500);
    flag=0;
    READ_IMEI();

    trans_string("AT+CIPSEND\r");
    delay(500);

    j=0;
    while(clktime[j] != '"')
    {
        j++;
    }
    j++;
    do
    {
        transmitter_data(clktime[j]);
        j++;
        delay(100);
    }while(clktime[j] != '+');
    delay(100);

    transmitter_data('#');                          //software reading process 

    j=0;
    for(j=1;j<=15;j++)
    {
        transmitter_data(imeidata[j]);
        delay(100);
    }
     transmitter_data('#');                            //software reading process
  
    delay(100);
  
   
    ADC_READ(); 
    delay(500);
    transmitter_data('\x1A');
 
}

void READ_IMEI()
{
    flag=2;
    trans_string("AT+GSN\r");
    delay(500);
    flag=0; 
}
void SEND_IMEI(unsigned char *imeisend)
{
    trans_string("AT+CMGS=");
    transmitter_data('"');
    trans_string(num);
    transmitter_data('"');
    transmitter_data('\r');
    delay(100);
    for(j=0;j<=19;j++)
    {
        transmitter_data(*imeisend++);
        delay(100);
    }
     delay(100);
     transmitter_data('\x1A');
     delay(500); 
}

void MSG_READ()
{   
    flag=1;
    trans_string("AT+CMGR=1\r"); 
    delay(500);
    CHECK_SMS(arrayptr);
    delay(50);
    CHECK_CMD(cmd);
    flag=0;
    delay(2000);
    trans_string("AT+CMGD=1\r");
    delay(100);
}
void MSG_SEND(unsigned char *message)
{
    trans_string("AT+CMGS=");
    transmitter_data('"');
    trans_string(num);
    transmitter_data('"');
    transmitter_data('\r');
    delay(100);
    trans_string(message);
   transmitter_data('\x1A');
   delay(500);    
}
void SET_APN(unsigned char *setapn)
{
    trans_string("AT+CGATT=1\r");
    delay(1000); 
    trans_string("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"\r");
    delay(1000);
    trans_string("AT+SAPBR=3,1,\"APN\",\"");
    trans_string(setapn);
    transmitter_data('"');
    transmitter_data('\r');
    delay(1000);
    trans_string("AT+SAPBR=1,1\r");
    delay(3000);
    trans_string("AT+SAPBR=2,1\r");
    delay(1000);
    MSG_SEND("APN UPDATED");
    delay(500);   
}

void GSM_INIT()
{
    while(step<=6)
    {
        switch(step)
        {
            case 0: trans_string("AT\r"); delay(500);break;
            case 1: trans_string("ATE0\r");delay(500);break;
            case 2: trans_string("AT+CMGF=1\r");delay(500);break;
            case 3: trans_string("AT+CNMI=1,1,0,0,0\r");delay(500);break;
            case 4: trans_string("AT+CMGD=1\r");delay(500);break;
            case 5: trans_string("AT+CLTS=1\r");delay(1000);break;
            case 6: trans_string("AT+CTZU=1\r");delay(1000);break;
           
            
            default: break;
        }
        delay(500);
        if( RC_BIT_Flag==1)
        {
            RC_BIT_Flag=0;
            step++;
        }
         else if(RC_BIT_Flag==0)
         {
           step=0;
         }
    }
}

#endif    /* GSM_READ_H */

And my issue is.
Please give some idea:

Actually in my project. i used gsm for ADC value is continuously send to the IP.

In between this process if GSM Received any msg, Controller has to read the message and respond. This is requirement.

Actually what happen means. If i am not using ADC , Controller Read message and do the process properly. Process may differ like reply the sms, change APN depends on the incoming message.

But using ADC commends, ADC process will do properly but during this process SERIAL INTERRUPT(to read sms) is not working.

I set SERIAL INTERRUPT as high priority.

I just tried. if any mistake please tell me . And i have checked by using Proteus software.

And please tell me if any mistake in bit configuration.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top