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.

Problem while sending adc data through GSM

Status
Not open for further replies.

niranjan23

Member level 5
Joined
Jan 22, 2012
Messages
94
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,288
Activity points
2,109
Hello!


As title says I having problem with PIC16F877A ADC.,Thus I want to send ADC data through GSM modem, But problem is.... I getting error Warning in MPLAB IDE (Hi-Tech C compiler) is as follows.

Warning [356] C:\Users\abk\Desktop\MPLAB TEST\SEM.c; 174.28 implicit conversion of float to integer
Warning [360] C:\Users\abk\Desktop\MPLAB TEST\SEM.c; 181.7 array index out of bounds

And when I run this code on Proteus Simulation it shows me nothing.....only GSM AT commands on virtual terminal. My ADC program is right and its working.Im Attaching my code below.Plz Help me with this!!!Thankyou!!


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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*******************************************************************************
* Function    : Uart_Initial_Tx_Rx
* Description : Usart Initialization function - Baud Rate 9600
* Parameters  : baud, for selecting baurd rate
*******************************************************************************/
void Uart_Initial_Tx_Rx(unsigned long baud)
{
 TRISC6 = 0;                            /* Set Tx pin Output and Rx pin Input */
 TXEN=1;                                /* Transmit Enabled                   */
 BRGH=1;                                /* BaudRate = 9600                    */
 SYNC=0;                                /* Asynchronous Mode                  */
 SPEN=1;                                /* Enable Serial Port                 */
 if(baud == 9600 )
 SPBRG = 129;
 else if (baud == 19200)
 SPBRG = 64;
 else if (baud == 38400)
 SPBRG = 32;
 else if (baud == 57600)
 SPBRG = 21;
 else if (baud == 115200)
 SPBRG = 10;
}
 
/********************************************************************************
* Function    : Uart_Data
* Description : Function to send data through the UART
* Parameters  : data, contains the data to be transmitted and is written to
*               the TXREG register
********************************************************************************/
void Uart_Data(unsigned char data)
{
 TXREG=data;
 while(TRMT!=1);
}
 
/********************************************************************************
* Function    : Send
* Description : Function to send a string data thru USART
* Parameters  : ptr, contains the byte to be sent
********************************************************************************/
void Send(const char *ptr)
{
 while(*ptr!='\0')
 {
  TXREG=*ptr;
  while(TRMT!=1);
  ptr++;
 }
}
 
 
/********************************************************************************
* Function    : Delay_Ms
* Description : Function for milliseconds at 20mhz
* Parameters  : ms, variable for delay
********************************************************************************/
void Delay_Ms(int ms)
{
 int i,count;
 for(i=1;i<=ms;i++)
 {
  count=498;
  while(count!=1)
  {
   count--;
  }
 }
}
 
 
void delay()
{
  for(i=0;i<500;i++)
    for(j=0;j<500;j++);
}
/********************************************************************************
* Function    : Send_Message
* Description : Function to send commands for sending sms
* Parameters  : None
********************************************************************************/
void Send_Message()
{
 Send("AT\r\n");                        /* Transmit AT to the module           */
 Delay_Ms(500);                         /* 500ms delay                         */
 Send("ATE0\r\n");                      /* Echo Off                            */
 Delay_Ms(500);                         /* 500ms delay                         */
 Send("AT+CMGF=1\r\n");                 /* Switch to text mode                 */
 Delay_Ms(500);                         /* 500ms delay                         */
 Send("AT+CNMI=2,1,0,0,0\r\n");         
 Delay_Ms(500);                         /* 500ms delay                         */
 Send("AT+CMGS="+917507942453"\r\n");  /* Send SMS to a cell number           */
 Delay_Ms(500);                         /* 500ms delay                         */
 Send("\rTest SMS from rhydoLABZ.com-Cochin\r\n"); 
 Send(data[1]);
 Send(data[2]);                         //ADC DATA
 Send(data[3]);
 Send(data[4]); 
 Delay_Ms(500); 
 Uart_Data(0x1A);                       /* Ctrl-Z indicates end of SMS         */
 Delay_Ms(500);                         /* 500ms delay                         */
}
 
 
/////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////ADC CODE AREA///////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
void ADC_Init()
{
  ADCON0 = 0x81; //ADC Module Turned ON and Clock is selected
  ADCON1 = 0x84; //All pins as Analog Input
                 //With reference voltages VDD and VSS
}
 
unsigned int ADC_Read(unsigned char channel)
{
  if(channel > 7) //If Invalid channel selected 
    return 0;     //Return 0
 
  //ADCON0 &= 0xC5; //Clearing the Channel Selection Bits
  ADCON0 |= channel<<3; //Setting the required Bits
  __delay_ms(2); //Acquisition time to charge hold capacitor
  GODONE = 1; //Initializes A/D Conversion
  while(GODONE); //Wait for A/D Conversion to complete
  return ((ADRESH<<8)+ADRESL); //Returns Result
}
 
void ADC_main()
{
  unsigned char ADCResult,data[5];
  TRISA = 0xFF; //PORTA as input
   Uart_Initial_Tx_Rx(9600);
  ADC_Init(); //Initializes ADC Module
    ADCResult= ADC_Read(0); //Reading Analog Channel 0
   Voltage = ADCResult;
VRMS = (Voltage/2.0) *0.707;
AmpsRMS = (VRMS * 1000)/mVperAmp;
 
  data[1]= AmpsRMS/ 10000 + 48 ; 
data[2]=(AmpsRMS % 10000) / 1000 + 48 ;
data[3]=(AmpsRMS % 1000) / 100 + 48 ;
data[4]=(AmpsRMS % 100) / 10 + 48 ;
data[5]=AmpsRMS % 10 + 48 ;
  __delay_ms(10); //Delay
Uart_Data(data[1]);
Uart_Data(data[2]);
Uart_Data(data[3]);
Uart_Data(data[4]);
Uart_Data(data[5]);
 
}

 

You have not posted the code sem.c where this WARNING happens.
In fact, there isn't any mention of this function at the code you've posted.

Anyway, although the 2nd message was not indeed tagged as a compilation ERROR, it is quite serious, able to ruin the program working.
 

You have not posted the code sem.c where this WARNING happens.
In fact, there isn't any mention of this function at the code you've posted.

Anyway, although the 2nd message was not indeed tagged as a compilation ERROR, it is quite serious, able to ruin the program working.

Im sorry I didnt get it.
what exactly you want.. I will give you!!
this is the SEM.c
Code:
#include <htc.h>
#include<pic.h>
#define _XTAL_FREQ 20000000
 unsigned char sensor1[10];
//unsigned char sensor2[];
void Uart_Initial_Tx_Rx(unsigned long baud);
void Uart_Data(unsigned char data);
void Send(const char *ptr);
void Send_Message();
 void delay();
void ADC_main();
unsigned char AmpsRMS,Voltage=0,VRMS=0,mVperAmp=66;
unsigned char data1,z,p,q;
int i,j;

///////////////////////////MAIN CODE AREA////////////////////////////////////////////////
void main()
{
TRISD0 = 1;
TRISD1 = 1;
TRISD2 = 0;
TRISD3 = 0;
RD2 = 0;
RD3 = 0;
Uart_Initial_Tx_Rx(9600);
while(1)
{
if(RD0==1) ////////////////////Phase cut
{
  Send_Message();
  _delay(100);
  RD2 = 1; 
}
else if(RD1==1)            ////////Mis call Input
{
   RD3 = 1;
 //Remaining to write
}
}

}

 
/*******************************************************************************
* Function    : Uart_Initial_Tx_Rx
* Description : Usart Initialization function - Baud Rate 9600
* Parameters  : baud, for selecting baurd rate
*******************************************************************************/
void Uart_Initial_Tx_Rx(unsigned long baud)
{
 TRISC6 = 0;                            /* Set Tx pin Output and Rx pin Input */
 TXEN=1;                                /* Transmit Enabled                   */
 BRGH=1;                                /* BaudRate = 9600                    */
 SYNC=0;                                /* Asynchronous Mode                  */
 SPEN=1;                                /* Enable Serial Port                 */
 if(baud == 9600 )
 SPBRG = 129;
 else if (baud == 19200)
 SPBRG = 64;
 else if (baud == 38400)
 SPBRG = 32;
 else if (baud == 57600)
 SPBRG = 21;
 else if (baud == 115200)
 SPBRG = 10;
}
 
/********************************************************************************
* Function    : Uart_Data
* Description : Function to send data through the UART
* Parameters  : data, contains the data to be transmitted and is written to
*               the TXREG register
********************************************************************************/
void Uart_Data(unsigned char data)
{
 TXREG=data;
 while(TRMT!=1);
}
 
/********************************************************************************
* Function    : Send
* Description : Function to send a string data thru USART
* Parameters  : ptr, contains the byte to be sent
********************************************************************************/
void Send(const char *ptr)
{
 while(*ptr!='\0')
 {
  TXREG=*ptr;
  while(TRMT!=1);
  ptr++;
 }
}

 
/********************************************************************************
* Function    : Delay_Ms
* Description : Function for milliseconds at 20mhz
* Parameters  : ms, variable for delay
********************************************************************************/
void Delay_Ms(int ms)
{
 int i,count;
 for(i=1;i<=ms;i++)
 {
  count=498;
  while(count!=1)
  {
   count--;
  }
 }
}
 

void delay()
{
  for(i=0;i<500;i++)
    for(j=0;j<500;j++);
}
/********************************************************************************
* Function    : Send_Message
* Description : Function to send commands for sending sms
* Parameters  : None
********************************************************************************/
void Send_Message()
{
 Send("AT\r\n");                        /* Transmit AT to the module           */
 Delay_Ms(500);                         /* 500ms delay                         */
 Send("ATE0\r\n");                      /* Echo Off                            */
 Delay_Ms(500);                         /* 500ms delay                         */
 Send("AT+CMGF=1\r\n");                 /* Switch to text mode                 */
 Delay_Ms(500);                         /* 500ms delay                         */
 Send("AT+CNMI=2,1,0,0,0\r\n");         
 Delay_Ms(500);                         /* 500ms delay                         */
 Send("AT+CMGS=\"+917507942453\"\r\n");  /* Send SMS to a cell number           */
 Delay_Ms(500);                         /* 500ms delay                         */
 Send("\rTest SMS from rhydoLABZ.com-Cochin\r\n"); 
 Send(data[1]);
 Send(data[2]);                         //ADC DATA
 Send(data[3]);
 Send(data[4]); 
 Delay_Ms(500); 
 Uart_Data(0x1A);                       /* Ctrl-Z indicates end of SMS         */
 Delay_Ms(500);                         /* 500ms delay                         */
}


/////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////ADC CODE AREA///////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
void ADC_Init()
{
  ADCON0 = 0x81; //ADC Module Turned ON and Clock is selected
  ADCON1 = 0x84; //All pins as Analog Input
                 //With reference voltages VDD and VSS
}

unsigned int ADC_Read(unsigned char channel)
{
  if(channel > 7) //If Invalid channel selected 
    return 0;     //Return 0

  //ADCON0 &= 0xC5; //Clearing the Channel Selection Bits
  ADCON0 |= channel<<3; //Setting the required Bits
  __delay_ms(2); //Acquisition time to charge hold capacitor
  GODONE = 1; //Initializes A/D Conversion
  while(GODONE); //Wait for A/D Conversion to complete
  return ((ADRESH<<8)+ADRESL); //Returns Result
}

void ADC_main()
{
  unsigned char ADCResult,data[5];
  TRISA = 0xFF; //PORTA as input
   Uart_Initial_Tx_Rx(9600);
  ADC_Init(); //Initializes ADC Module
    ADCResult= ADC_Read(0); //Reading Analog Channel 0
   Voltage = ADCResult;
VRMS = (Voltage/2.0) *0.707;
AmpsRMS = (VRMS * 1000)/mVperAmp;

  data[1]= AmpsRMS/ 10000 + 48 ; 
data[2]=(AmpsRMS % 10000) / 1000 + 48 ;
data[3]=(AmpsRMS % 1000) / 100 + 48 ;
data[4]=(AmpsRMS % 100) / 10 + 48 ;
data[5]=AmpsRMS % 10 + 48 ;
  __delay_ms(10); //Delay
Uart_Data(data[1]);
Uart_Data(data[2]);
Uart_Data(data[3]);
Uart_Data(data[4]);
Uart_Data(data[5]);

}
 
Last edited:

The amount of lines of the code you've posted at initial post is 151, whereas the 1st warning message apparently assigns the problem to line 174.
 

I posted complete code up there

here also!!


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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include <htc.h>
#include<pic.h>
 
#define _XTAL_FREQ 20000000
 
void Uart_Initial_Tx_Rx(unsigned long baud);
void Uart_Data(unsigned char data);
void Send(const char *ptr);
void Send_Message();
 void delay();
void ADC_main();
unsigned char AmpsRMS,Voltage=0,VRMS=0,mVperAmp=66;
unsigned char data1,z,p,q;
int i,j;
 
///////////////////////////MAIN CODE AREA////////////////////////////////////////////////
void main()
{
TRISD0 = 1;
TRISD1 = 1;
TRISD2 = 0;
TRISD3 = 0;
RD2 = 0;
RD3 = 0;
Uart_Initial_Tx_Rx(9600);
while(1)
{
if(RD0==1) ////////////////////Phase cut
{
  Send_Message();
  _delay(100);
  RD2 = 1; 
}
else if(RD1==1)            ////////Mis call Input
{
   RD3 = 1;
 //Remaining to write
}
}
 
}
 
 
/*******************************************************************************
* Function    : Uart_Initial_Tx_Rx
* Description : Usart Initialization function - Baud Rate 9600
* Parameters  : baud, for selecting baurd rate
*******************************************************************************/
void Uart_Initial_Tx_Rx(unsigned long baud)
{
 TRISC6 = 0;                            /* Set Tx pin Output and Rx pin Input */
 TXEN=1;                                /* Transmit Enabled                   */
 BRGH=1;                                /* BaudRate = 9600                    */
 SYNC=0;                                /* Asynchronous Mode                  */
 SPEN=1;                                /* Enable Serial Port                 */
 if(baud == 9600 )
 SPBRG = 129;
 else if (baud == 19200)
 SPBRG = 64;
 else if (baud == 38400)
 SPBRG = 32;
 else if (baud == 57600)
 SPBRG = 21;
 else if (baud == 115200)
 SPBRG = 10;
}
 
/********************************************************************************
* Function    : Uart_Data
* Description : Function to send data through the UART
* Parameters  : data, contains the data to be transmitted and is written to
*               the TXREG register
********************************************************************************/
void Uart_Data(unsigned char data)
{
 TXREG=data;
 while(TRMT!=1);
}
 
/********************************************************************************
* Function    : Send
* Description : Function to send a string data thru USART
* Parameters  : ptr, contains the byte to be sent
********************************************************************************/
void Send(const char *ptr)
{
 while(*ptr!='\0')
 {
  TXREG=*ptr;
  while(TRMT!=1);
  ptr++;
 }
}
 
 
/********************************************************************************
* Function    : Delay_Ms
* Description : Function for milliseconds at 20mhz
* Parameters  : ms, variable for delay
********************************************************************************/
void Delay_Ms(int ms)
{
 int i,count;
 for(i=1;i<=ms;i++)
 {
  count=498;
  while(count!=1)
  {
   count--;
  }
 }
}
 
 
void delay()
{
  for(i=0;i<500;i++)
    for(j=0;j<500;j++);
}
/********************************************************************************
* Function    : Send_Message
* Description : Function to send commands for sending sms
* Parameters  : None
********************************************************************************/
void Send_Message()
{
 Send("AT\r\n");                        /* Transmit AT to the module           */
 Delay_Ms(500);                         /* 500ms delay                         */
 Send("ATE0\r\n");                      /* Echo Off                            */
 Delay_Ms(500);                         /* 500ms delay                         */
 Send("AT+CMGF=1\r\n");                 /* Switch to text mode                 */
 Delay_Ms(500);                         /* 500ms delay                         */
 Send("AT+CNMI=2,1,0,0,0\r\n");         
 Delay_Ms(500);                         /* 500ms delay                         */
 Send("AT+CMGS="+917507942453"\r\n");  /* Send SMS to a cell number           */
 Delay_Ms(500);                         /* 500ms delay                         */
 Send("\rTest SMS from rhydoLABZ.com-Cochin\r\n"); 
 Send(data[1]);
 Send(data[2]);                         //ADC DATA
 Send(data[3]);
 Send(data[4]); 
 Delay_Ms(500); 
 Uart_Data(0x1A);                       /* Ctrl-Z indicates end of SMS         */
 Delay_Ms(500);                         /* 500ms delay                         */
}
 
 
/////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////ADC CODE AREA///////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
void ADC_Init()
{
  ADCON0 = 0x81; //ADC Module Turned ON and Clock is selected
  ADCON1 = 0x84; //All pins as Analog Input
                 //With reference voltages VDD and VSS
}
 
unsigned int ADC_Read(unsigned char channel)
{
  if(channel > 7) //If Invalid channel selected 
    return 0;     //Return 0
 
  //ADCON0 &= 0xC5; //Clearing the Channel Selection Bits
  ADCON0 |= channel<<3; //Setting the required Bits
  __delay_ms(2); //Acquisition time to charge hold capacitor
  GODONE = 1; //Initializes A/D Conversion
  while(GODONE); //Wait for A/D Conversion to complete
  return ((ADRESH<<8)+ADRESL); //Returns Result
}
 
void ADC_main()
{
  unsigned char ADCResult,data[5];
  TRISA = 0xFF; //PORTA as input
   Uart_Initial_Tx_Rx(9600);
  ADC_Init(); //Initializes ADC Module
    ADCResult= ADC_Read(0); //Reading Analog Channel 0
   Voltage = ADCResult;
VRMS = (Voltage/2.0) *0.707;
AmpsRMS = (VRMS * 1000)/mVperAmp;
 
  data[1]= AmpsRMS/ 10000 + 48 ; 
data[2]=(AmpsRMS % 10000) / 1000 + 48 ;
data[3]=(AmpsRMS % 1000) / 100 + 48 ;
data[4]=(AmpsRMS % 100) / 10 + 48 ;
data[5]=AmpsRMS % 10 + 48 ;
  __delay_ms(10); //Delay
Uart_Data(data[1]);
Uart_Data(data[2]);
Uart_Data(data[3]);
Uart_Data(data[4]);
Uart_Data(data[5]);
 
}

 

The first warning occurs because the division operator "/" performs and implicit conversion of its arguments ( dividend and divisor ) from any type to float; it is expected that both are float and the compiler do automatically this job for you, and warn it just for remind.

However, the second warning I consider as said before an error; At line 13 you had declared data as a single char, but from line 182 to 186 you address it as an array of 6 chars ( note that you have even skipped the first position, data[0] ).
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top