You are on page 1of 6

/*******************************************************************************

***********************************
ARM Based Smart Car System.
********************************************************************************
**********************************/
#include <lpc21xx.h>
#include <stdio.h>
#include <string.h>
#include "LED.h"
#include "UART.h"
#define Relay 16
void lcd_initialize(void);
void delay(unsigned int);
void lcd_cmd(unsigned char);
void lcd_data(unsigned char);
void UART0_ISR (void)__irq;
void UART1_ISR (void)__irq;

const unsigned char cmd[4] = {0x38,0x0c,0x06,0x01}; //lcd commands


unsigned char Key, Gate;
unsigned char Buff[50];
unsigned char Latt[16];
unsigned char Long[16];
unsigned char IE=0;
//----------------------------------
// LCD Initialize
//----------------------------------
void lcd_initialize(void)
{
int i;
for(i=0;i<4;i++)
{
lcd_cmd(cmd[i]);
delay(15);
}
}

//----------------------------------
// LCD Command Send
//----------------------------------
void lcd_cmd(unsigned char data)
{
IOPIN0 = data << 16;
IOCLR1 |= 0x100000; //RS
IOCLR1 |= 0x200000; //RW
IOSET1 |= 0x400000; //EN
delay(15);
IOCLR1 |= 0x400000; //EN
}

//----------------------------------
// LCD Data Send
//----------------------------------
void lcd_data(unsigned char data)
{
IOPIN0 = data << 16;
IOSET1 |= 0x100000; //RS
IOCLR1 |= 0x200000; //RW
IOSET1 |= 0x400000; //EN
delay(15);
IOCLR1 |= 0x400000; //EN
}

//----------------------------------
// LCD Display Msg
//----------------------------------
void lcd_display(void)
{
char i;
lcd_cmd(0x80);
delay(15);
i=0;
while(msg[i]!='\0')
{
lcd_data(msg[i]);
i++;
delay(15);
}
delay(15);
lcd_cmd(0xc0);
delay(15);
i=0;
while(msg1[i]!='\0')
{
lcd_data(msg1[i]);
i++;
delay(15);
}
delay(15);
}

//----------------------------------
// Delay Routine
//----------------------------------
void delay(unsigned int n)
{
int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<0x2700;j++)
{;}
}
}

//----------------------------------
// Main program Starts Here
//----------------------------------
void main(void)
{
unsigned char Flag=0, Q=0, ii = 0, pos, j;
PINSEL0 = 0;
PINSEL1 = 0;
VPBDIV = 0x02;
//Make PCLK = 30MHz
UART0_Init (9600);
//Initialize UART0 to 9600 Baud Rate @ 30MHz
UART1_Init (9600);
//Initialize UART0 to 9600 Baud Rate @ 30MHz
U0IER = 1;
U1IER = 1;
/********* UART0 Init *************/
VICIntSelect = 0<<6; //UART0
('0' - irq '1'-fiq)
VICVectCntl6 = 0x020 | 6; //VIC slot enabl
ed
VICVectAddr6 = (unsigned long)UART0_ISR; //pass address of UART0
VICIntEnable = 1 << 6; //Enable
UART0 Interrupt
/********* UART0 Init *************/
VICIntSelect = 0<<7; //UART0
('0' - irq '1'-fiq)
VICVectCntl7 = 0x020 | 7; //VIC slot enabl
ed
VICVectAddr7 = (unsigned long)UART1_ISR; //pass address of UART0
VICIntEnable = 1 << 7; //Enable
UART0 Interrupt
IODIR0 = 0X0000FFFF; //PORT [
P0.8--P0.15] and Port [0.15--p0.23] as output
IODIR0 |= 0x00FF0000;
IODIR1 = 0xFF << 16; //Config
ure Port as O/p for LCD Controls and LEDs
delay(10);
lcd_initialize();
//Initialize LCD
delay(10);
ii=0;
lcd_display();
IOSET1 = 1 << Relay;
UART1_PutC ('L');
while(1)
{
if (Flag == 2)
{
if (Key == 'A' || Key == 'L')
{
Flag = 1;
//IOSET1 = 1 << LED2;
//IOCLR1 = 1 << LED4;
//delay(10);
//delay(10);
}
else
{
Flag = 0;
}
}
if ((Key == 'G' || Key == 'L') && Q == 0)
{
Flag = 2;
//delay(10);
//delay(10);
}

if (Flag == 1)
{
Q = 1;
Gate = 0;
//delay(10);
IOSET1 = 1 << LED3;
//delay(10);
Buff[ii] = Key;
while (!Gate);
//ii++;
if (*(Buff+ii) == '*')
{
IE = 1;
U0IER = 0;
IOSET1 = 1 << LED4;
//IOCLR1 = 1 << LED1;
IOCLR1 = 1 << LED2;
IOCLR1 = 1 << LED3;
Q = 0;
Flag = 0;
//strcpy (msg1, Buff);
//msg1[sizeof(msg1)-1] = '\0';
//strcpy (Buff,"");
// pos = strpos(Buff, ',');
// msg1[pos] = '*';
// pos = strpos(Buff, ',');
// msg1[pos] = '*';
pos = 13;
j = 0;
while (j<10)
{
Latt[j] = Buff[pos];
pos++;
j++;
}
Latt[j] = '\0';
//
// pos = strpos(Buff, ',');
// msg1[pos] = '*';
// pos = strpos(Buff, ',');
// msg1[pos] = '*';
strcpy (msg, "Lat: ");
strcpy (msg1,"Lon: ");
pos = 25;
j=0;
while (j < 10)
{
Long[j] = Buff[pos];
pos++;
j++;
}
Long[j] = '\0';
j = 0;
while (j<10)
{
msg[j+5] = Latt[j];
msg1[j+5] = Long[j];
j++;
}
//msg[j+5] = '\0';
// msg1[j+5] = '\0';
// strcpy(msg, Latt);
// strcpy(msg1, Long);
//j=0
//pos1 = strpos
ii=0;
lcd_display();
IE = 0;
U0IER = 1;
}
ii++;
//delay(10);
}

}
}
void UART0_ISR (void)__irq
{
char Msg;
if(((Msg = U0IIR) & 0x01) == 0) //Check
Flag Status of Recieve Interrupt
{
switch (Msg & 0x0E)
//Filter Msg
{
case 0x04: while (!(U0LSR & 0x20)); //Reciev
e Data
while (IE);
Key = U0RBR;
Gate = 1;
break;
case 0x02: break;
//THRE Interrupt
default : break;
}
}
VICVectAddr = 6;
}
void UART1_ISR (void)__irq
{
char ch;
ch = U1RBR;
if (ch == 'V')
{
UART1_PutS (Buff);
delay (10);
}
if (ch == 'S')
{
IOCLR1 = 1 << Relay;
}
VICVectAddr = 7;
}

You might also like