niranjan23
Member level 5
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.
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!!
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]); }