#include <LPC214x.h>
#include "lcd.h"
/* ADC Macros */
#define ANALOG_IN
(1<<28)
//Assign Analog In to P0.28
#define ANALOG_IN_DIR (1<<24)
//Assign Direction register bits
#define ANALOG_IN1
(1<<29)
#define ANALOG_IN1_DIR
(1<<26)
#define ANALOG_IN2
(1<<30)
#define ANALOG_IN2_DIR
(1<<28)
#define _PDN_BIT 1<<21
#define _ADCR_START_MASK 7<<24
#define _ADCR_SEL_MASK 0x000000FF
#define _ADC0_START 1<<24
/* GPS Macros */
#define RDR 0x01
#define THRE 0x20
#define RDA 0x04
#define _9600_12_MHZ 78
//approximate
#define _9600_15_MHZ 97
#define UART0_CH_NUM 6
// dont change thiss
#define VIC_UART0_CH (0x01 << UART0_CH_NUM)
//don't change thiss
#define VIC_INT_CH_EN (0x01 << 5)
//don't change thiss
#define UART1_CH_NUM 7
// dont change thiss
#define VIC_UART1_CH (0x01 << UART1_CH_NUM)
//don't change thiss
long num1,num2,num3,num4;
/* ADC Prototypes */
void Adc0Init(unsigned char clkdiv);
unsigned int Adc0Read(unsigned char channel);
/* UART Prototypes */
void Uart0Init (void);
void Uart0PutCh (unsigned char ch);
void Uart0PutS(unsigned char *str);
void SendHexData0(unsigned char *str0, int StrLenCntr0);
void Uart1PutCh (unsigned char ch);
unsigned char Uart1GetCh (void);
void Uart1PutS(unsigned char *str);
void SendHexData1(unsigned char *str1, int StrLenCntr1);
void _DelayMs(unsigned int count);
/* Variables */
char stcol, endcol, j ;
//int val1,val2;
int temp,humidity,IR;
char END[1] = {26};
char SendingText1[6] = {'I','0','0','0',0x0D,0x0A};
char SendingText2[6] = {'T','0','0','0',0x0D,0x0A};
char SendingText3[6] = {'H','0','0','0',0x0D,0x0A};
int localADC0Data = 0;
int localADC1Data = 0;
int localADC2Data = 0;
int localADC3Data = 0;
unsigned char str4[] = {" "};
char InChar;
char RecWordsP1[60];
int RecWordsCntrP1 = 0;
char RecChar_Int;
char CurrReChar;
char PrevReChar;
int GGAFound = 0;
char WorkingString[50];
int WorkStrWordCnt = 0;
unsigned char CopyTheSring[40];
int FillChar;
//*******************End of Private Protoype************************************
//*****************************************************************************
// Function: int main(void)
//
// Input: None
//
// Output: None
//
// Overview: Main enrty point.
//
// Note: None
//*****************************************************************************
int main(void)
{
int flag1=0;
int flag2=0;
int flag3=0;
int flag4=0;
/* ADC initialization */
PINSEL1 |=
ANALOG_IN_DIR;
IODIR0
&=
~(ANALOG_IN);
Adc0Init(10);
PINSEL1 |= ANALOG_IN1_DIR;
IODIR0 &= ~(ANALOG_IN1);
Adc0Init(10);
PINSEL1 |= ANALOG_IN2_DIR;
IODIR0 &= ~(ANALOG_IN2);
Adc0Init(10);
Uart0Init();
while(1)
{
num1 = Adc0Read(1);
//Select channel number
num2 = Adc0Read(2);
num3 = Adc0Read(3);
//Display Analog voltage on Character L
IR = num1;
temp = num2/4;
humidity = num3 ;
localADC0Data = IR %1000;
SendingText1[2] = 48+(localADC0Data%10);
localADC0Data = localADC0Data/10;
SendingText1[1] = 48+(localADC0Data%10);
localADC2Data = humidity%1000;
SendingText3[3] = 48+(localADC2Data%10);
localADC2Data = localADC2Data/10;
SendingText3[2] = 48+(localADC2Data%10);
SendingText3[1] = 48+(localADC2Data%10);
if (flag2==0)
{
flag2=1;
if((IR>500) && (temp>20) && (humidity>50))
{
Uart0PutS("AT\r\n");
_DelayMs(100);
Uart0PutS("AT+CMGF=1\r\n");
_DelayMs(200);
Uart0PutS("AT+CMGS=\"9767034006\"\r\n");
_DelayMs(200);
SendHexData0(SendingText1, 6);
_DelayMs(200);
Uart0PutS(" Detected\r\n");
_DelayMs(200);
Uart0PutS(CopyTheSring);
_DelayMs(200);
SendHexData0(END,1);
//
GPS
for(FillChar = 0; FillChar < 24; FillChar++)
{
CopyTheSring[FillChar] = WorkingString[FillChar + 14];
}
SendHexData0(CopyTheSring, 24);
_DelayMs(50);
SendHexData0(END, 1);
_DelayMs(50);
_DelayMs(200);
}
}
else
{
flag2=0;
}
if (temp>20)
{
if (flag3==0)
{
flag3=1;
Uart0PutS("AT\r\n");
_DelayMs(100);
Uart0PutS("AT+CMGF=1\r\n");
_DelayMs(200);
Uart0PutS("AT+CMGS=\"9767034006\"\r\n");
_DelayMs(200);
SendHexData0(SendingText2, 6);
_DelayMs(200);
Uart0PutS("High Temp.\r\n");
_DelayMs(200);
SendHexData0(END,1);
}
}
else
{
flag3=0;
}
if (humidity>50)
{
if (flag4==0)
{
flag4=1;
Uart0PutS("AT\r\n");
_DelayMs(100);
Uart0PutS("AT+CMGF=1\r\n");
_DelayMs(200);
Uart0PutS("AT+CMGS=\"9767034006\"\r\n");
_DelayMs(200);
SendHexData0(SendingText3,6);
_DelayMs(200);
Uart0PutS("High Humidity.\r\n");
_DelayMs(200);
SendHexData0(END,1);
}
}
else
{
flag4=0;
}
Arm7 Training
}
}
`
void Uart0Init (void)
// Initialize Serial Interface
{
// initialize the serial interface
PINSEL0 |= 0x00050005; // Enable RxD0 and TxD0
U0LCR = 0x83; //8 bits, no Parity, 1 Stop bit
U0DLL = _9600_15_MHZ; //9600 Baud Rate @ 12MHz Clock
U0LCR = 0x03; //DLAB = 0
//Enable Uart FIFO
U0FCR |= 0x01;
U1LCR = 0x83; // 8 bits, no Parity, 1 Stop bit
U1DLL = 97; // 9600 Baud Rate @ 12MHz Clock
U1LCR = 0x03; // DLAB = 0
U1FCR |= 0x01;
// Configure the VIC for Interrupt Handling
VICVectCntl7 |= (VIC_INT_CH_EN | UART1_CH_NUM);
VICVectAddr7 = (unsigned int) UART1_ISR;
VICIntSelect &= (~VIC_UART1_CH); // optional : you can remove this line : This is to ensure the IRQ Mode
VICIntEnable |= VIC_UART1_CH; // Enabel the Interrupt for listening request
// Enable UART Interrupt
U1IER |= 0x01;
// DLAB = 0
}
void Uart0PutCh (unsigned char ch) // Write character to Serial Port
{
_DelayMs(100);
while (!(U0LSR && 0x20));
U0THR = ch;
}
IOT Training
void Uart1PutS(unsigned char *str)
//A function to send a string on UART1
{
while(*str)
{
Uart1PutCh(*str++);
}
}
void SendHexData0(unsigned char *str0, int StrLenCntr0)
//A function to send a string on UART1
{
int LenCntr0 = 0;
while(LenCntr0 !StrLenCntr0)
{
Uart0PutCh(*str0++);
}
}
Embedded Training