#include <lpc21xx.h> /* LPC2200 definitions */
#include <stdio.h>
#include <string.h>
#include "uart.h" /* standard I/O .h-file */
#define CR 0x0D
#define VREF 3
int adc_process();
void delay1(int n);
void delay2(int n);
int tem_conv(void);
unsigned int val,temp1=0,temp2;
float deg_temp,temperature; //temp1=previous value,temp2=current value
char t[2],degree[5];
int j;
void
delay(void)
{
int temp;
for(temp = 0; temp < 400000; temp++) {
}
}
int main(void)
{
IODIR1 = 0x00FF0000;
VPBDIV = 0x02; /*Set the Pclk to 30 Mhz */
uart();
while(1)
{
printf("AT\n\r%c",13);
delay2(10000);
printf("AT+CMGF=1\n\r%c",13);
delay2(10000); //Text Mode | hex value of 13 is 0x0D (CR )
printf("AT+CMGS=\"9986552281\"\n\r%c",13);
delay2(10000);
temp2=adc_process();
while((temp2-temp1)<=50);
temp1=temp2;
sprintf(t,"%d",temp1);
printf ("Digital Value=" );
for(j=0;t[j]!='\0';j++)
{
put(t[j]);
}
delay2(1000);
printf("\n");
deg_temp=tem_conv();
sprintf(degree,"%f",deg_temp);
printf("Temperature(C)=");
for(j=0;degree[j]!='\0';j++)
put(degree[j]);
delay2(10000);
// printf("ATD9986552281;\r"); //calling function
printf("%c",0x1A); //line feed command
delay2(10000);
}
}
int adc_process() /* Setup the A/D converter */
{
PINSEL1 = 0x04000000; /* P1.16..23 defined as Outputs */
ADCR = 0x00210604; /* Setup A/D: 10-bit AIN0 @ 3MHz */
{
ADCR |= 0x01000000; // Start A/D Conversion
while ((ADDR & 0x80000000) == 0); // Wait for the conversion to complete
val = ((ADDR >> 6) & 0x03FF); // Extract the A/D result
IOSET1=val;
return(val);
}
}
//Delay Routine start here
void delay1(int n)
{
int i;
for(i=0;i<n;i++);
}
void delay2(int n)
{
int i;
for(i=0;i<n;i++)
delay1(1000);
}
int tem_conv(void)
{
temperature=(((float)adc_process()/1023)*3.3*100);
return(temperature);
}