Sie sind auf Seite 1von 13

/

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

#include <LPC21xx.H> /* LPC21xx definitions */


#include "Lcd.h"

#define IR_Sensor (1 << 7)


#define Tamper1 IR_Sensor

extern void init_serial (void); /* Initialize Serial Interface */


extern int sendchar (int ch); /* Write character to Serial Port */
extern int getkey (void); /* Read character from Serial Port */

extern void Send_Sms1(void );


extern void Send_Sms2(void );

extern void UART_to_UART(void);

void sendhex (int hex) { /* Write Hex Digit to Serial Port */


if (hex > 9) sendchar('A' + (hex - 10));
else sendchar('0' + hex);
}

void sendstr (char *p) { /* Write string */


while (*p) {
sendchar (*p++);
}
}

void delay (void)


{ /* Delay function */
unsigned int cnt;
unsigned int val;

LCD_Off()
{

int main (void)


{

Unsigned char kk;


IODIR1 = 0x00FF0000; /* P1.16..23 defined as Outputs */
ADCR = 0x002E0401; /* Setup A/D: 10-bit AIN0 @ 3MHz */
init_serial(); /* Initialize Serial Interface */
lcd_init();
//PINSEL0 |= 0x00045500; // configure SPI0 pins (except SSEL0)

S0SPCCR = 30; // SCK = 100 KHz, counter > 8 and even


S0SPCR = 0x30; //Configure as SPI Master
interrupts enabled

IODIR0 |= 0x00000000; // P0.7 defined as output for Slave Select


IOSET0 |= 0x00000400; // SS_DS1722 = 1 raju added p0.10 Slave select

lcd_write_control(0x80);
lcd_write_ascii('E');
lcd_write_ascii('m');
lcd_write_ascii('W');
lcd_write_ascii('a');
lcd_write_ascii('r');
lcd_write_ascii('e');

/ IOSET1=0XF0000000;

Send_Char('A');
Send_Char('T');
Send_Char('+');
Send_Char('C');
Send_Char('M');
Send_Char('G');
Send_Char('D');
Send_Char('=');
Send_Char('9');
Send_Char(0x0D);
kk = 0;
ii=1;
while (1)
{

if(!(IO0PIN & Ir_Sensor))


{
Kk++;
If(kk==10*ii)
{
Send_Sms1(kk);
Send_Sms2(kk);
ii++;
}
DELAY(100);
LCD_Off();

}
Else
{

DELAY(1000);

bc = 0;
while(bc<12);
DELAY(200);

DELAY(100);

bc=0;
Send_Char('A');
Send_Char('T');
Send_Char('+');
Send_Char('C');
Send_Char('M');
Send_Char('G');
Send_Char('R');
Send_Char('=');
Send_Char('9');

bc=0;
Send_Char(0x0D);
//bc=0;
//DELAY(200);
DELAY(1000);
// DELAY(200);

for(i=66;i<77;i++)
{

if((RData[i]=='1')|| (RData[i+1]=='1')||(RData[i+2]=='1')||
(RData[i+3]=='1'))
{
IOSET1=0XF0000000;

}
if((RData[i]=='0')||(RData[i+1]=='0'))
{

IOCLR1 =0XF0000000 ;
}
DELAY(200);
}
bc=0;

lcd_write_control(0x80);
lcd_write_ascii('N');
lcd_write_ascii('e');
lcd_write_ascii('W');
lcd_write_ascii('m');
lcd_write_ascii('e');
lcd_write_ascii('s');
lcd_write_ascii('s');
lcd_write_ascii('a');
lcd_write_ascii('g');
lcd_write_ascii('e');

DELAY(1000);

Send_Char('A');
Send_Char('T');
Send_Char('+');
Send_Char('C');
Send_Char('M');
Send_Char('G');
Send_Char('D');
Send_Char('=');
Send_Char('9');
Send_Char(0x0D);
bc=0;
DELAY(1000);

}
}

void U1ISR(void) __irq {


unsigned char ch;
U1IIR |= 0x01; /* Clear Interrupt */
//ch=SBUF;

data = U1RBR;
RData[bc]=data;

bc=bc+1;
// RI=0;

//data = U1RBR;
//Send_Char(data );
// IOCLR1 =0XF0000000 ;
DELAY(500);
VICVectAddr = 0x0; /* return from interrupt */
}
extern void sendstr (char *);
extern void sendchar(int);

void Send_Sms1(void );
void Send_Sms2(void );

void Delay_1Ms(unsigned int kk)


{
unsigned int i,k;
for(i=0;i<kk;i++)
{
for(k=0;k<1275;k++);
}
}

void Send_Sms1()
{

sendchar('A');
sendchar('T');
sendchar('+');
sendchar('C');
sendchar('M');
sendchar('G');
sendchar('F');
sendchar('=');
sendchar('1');
sendchar(0x0d);
Delay_1Ms(300);
//Delay_1ms(255);

sendchar('A');
sendchar('T');
sendchar('+');
sendchar('C');
sendchar('M');
sendchar('G');
sendchar('S');
sendchar('=');
sendchar('"');
sendchar('9');
sendchar('0');
sendchar('0');
sendchar('0');
sendchar('4');
sendchar('2');
sendchar('0');
sendchar('3');
sendchar('0');
sendchar('5');

sendchar('"');

sendchar(0x0d);
Delay_1Ms(300);
// Delay_1ms(255);

sendchar('T');
sendchar('E');
sendchar('M');
sendchar('P');
sendchar(':');

sendchar(0x1a);
Delay_1Ms(255);
Delay_1Ms(255);
}

void Send_Sms2()
{

sendchar('A');
sendchar('T');
sendchar('+');
sendchar('C');
sendchar('M');
sendchar('G');
sendchar('F');
sendchar('=');
sendchar('1');
sendchar(0x0d);
Delay_1Ms(300);
//Delay_1ms(255);

sendchar('A');
sendchar('T');
sendchar('+');
sendchar('C');
sendchar('M');
sendchar('G');
sendchar('S');
sendchar('=');
sendchar('"');

sendchar('9');
sendchar('4');
sendchar('9');
sendchar('4');
sendchar('6');
sendchar('4');
sendchar('3');
sendchar('2');
sendchar('0');
sendchar('8');

sendchar('"');

sendchar(0x0d);
Delay_1Ms(300);
// Delay_1ms(255);

sendchar('T');
sendchar('E');
sendchar('M');
sendchar('P');
sendchar(':');

sendchar(0x1a);
Delay_1Ms(255);
Delay_1Ms(255);
}
#include<LPC21xx.h>

#define LCD_RS 0x00010000 // P1.16(0000


0000 0000 000x 0000 0000 0000 0000)
#define LCD_EN 0x00020000 // P1.17(0000
0000 0000 00x0 0000 0000 0000 0000)
#define LCD_D4 0x00040000 // P1.18(0000
0000 0000 0x00 0000 0000 0000 0000)
#define LCD_D5 0x00080000 // P1.19(0000
0000 0000 x000 0000 0000 0000 0000)
#define LCD_D6 0x00100000 // P1.20(0000
0000 000x 0000 0000 0000 0000 0000)
#define LCD_D7 0x00200000 // P1.21(0000
0000 00x0 0000 0000 0000 0000 0000)

#define LCD_DATA (LCD_D7|LCD_D6|LCD_D5|LCD_D4)


#define LCD_IOALL (LCD_D7|LCD_D6|LCD_D5|LCD_D4|LCD_RS|LCD_EN)

#define lcd_rs_set() IOSET1 = LCD_RS // RS = 1


(Select Instruction)
#define lcd_rs_clr() IOCLR1 = LCD_RS // RS = 0
(Select Data)
#define lcd_en_set() IOSET1 = LCD_EN // EN = 1
(Enable)
#define lcd_en_clr() IOCLR1 = LCD_EN // EN = 0
(Disable)
#define lcd_dir_write() IODIR1 |= 0x003F0000 // LCD Data Bus =
Write

#define lcd_clear() lcd_write_control(0x01) // Clear Display


#define lcd_cursor_home() lcd_write_control(0x02) // Set Cursor = 0
#define lcd_display_on() lcd_write_control(0x0E) // LCD Display Enable
#define lcd_display_off() lcd_write_control(0x08) // LCD Display Disable
#define lcd_cursor_blink() lcd_write_control(0x0F) // Set Cursor = Blink
#define lcd_cursor_on() lcd_write_control(0x0E) // Enable LCD Cursor
#define lcd_cursor_off() lcd_write_control(0x0C) // Disable LCD Cursor
#define lcd_cursor_left() lcd_write_control(0x10)// Shift Left Cursor
#define lcd_cursor_right() lcd_write_control(0x14) // Shift Right Cursor
#define lcd_display_sleft() lcd_write_control(0x18) // Shift Left Display
#define lcd_display_sright() lcd_write_control(0x1C) // Shift Right Display

void lcd_init(void);
// Initial LCD
void lcd_out_data4(unsigned char); // Strobe 4-Bit
Data to LCD
void lcd_write_byte(unsigned char); // Write 1 Byte
Data to LCD
void lcd_write_control(unsigned char); // Write
Instruction
void lcd_write_ascii(unsigned char); // Write LCD
Display(ASCII)
void goto_cursor(unsigned char); // Set Position
Cursor LCD
void lcd_print(unsigned char*); // Print
Display to LCD
void enable_lcd(void);
void delay1(unsigned long int); //
Delay Function

void lcd_out_data4(unsigned char val)


{
IOCLR1 = (LCD_DATA);
// Reset 4-Bit Pin Data
IOSET1 = (val<<18);
// EN,0,RW,RS:DDDD:0000:0000:0000:0000:0000:0000

void lcd_write_byte(unsigned char val)


{

lcd_out_data4((val>>4)&0x0F); //
Strobe 4-Bit High-Nibble to LCD

enable_lcd();
// Enable Pulse

lcd_out_data4(val&0x0F); //
Strobe 4-Bit Low-Nibble to LCD
enable_lcd();
// Enable Pulse

delay1(100000);
//while(busy_lcd()); // Wait
LCD Execute Complete
}

void lcd_write_control(unsigned char val)


{
lcd_rs_clr();
// RS = 0 = Instruction Select
lcd_write_byte(val); //
Strobe Command Byte
}

void lcd_write_ascii(unsigned char c)


{
lcd_rs_set();
// RS = 1 = Data Select
lcd_write_byte(c); //
Strobe 1 Byte to LCD
}

void lcd_init()
{
unsigned int i;
// LCD Initial Delay Count

PINSEL2 = 0x00000000; //
GPIO1[31..26] = I/O Function
lcd_dir_write();
// LCD Data Bus = Write
for (i=0;i<1000;i++); //
Power-On Delay (15 mS)

IOCLR1 = (LCD_IOALL);
// Reset (RS,RW,EN,4-Bit Data) Pin
IOSET1 = (LCD_D5|LCD_D4);
// DDDD:EN,RW,RS,0:0000:0000:0000:0000:0000:0000
enable_lcd();
// Enable Pulse
for (i=0;i<100;i++); // Delay
4.1mS

IOCLR1 = (LCD_IOALL);
// Reset (RS,RW,EN,4-Bit Data) Pin
IOSET1 = (LCD_D5|LCD_D4);
// DDDD:EN,RW,RS,0:0000:0000:0000:0000:0000:0000
enable_lcd();
// Enable Pulse
for (i=0;i<100;i++); // delay
100uS
IOCLR1 = (LCD_IOALL);
// Reset (RS,RW,EN,4-Bit Data) Pin
IOSET1 = (LCD_D5|LCD_D4);
// DDDD:EN,RW,RS,0:0000:0000:0000:0000:0000:0000
enable_lcd();
// Enable Pulse
delay1(10000);
//while(busy_lcd()); // Wait
LCD Execute Complete

IOCLR1 = (LCD_IOALL);
// Reset (RS,RW,EN,4-Bit Data) Pin
IOSET1 = (LCD_D5);
// DDDD:EN,RW,RS,0:0000:0000:0000:0000:0000:0000
enable_lcd();
// Enable Pulse
delay1(10000);
//while(busy_lcd()); // Wait
LCD Execute Complete

lcd_write_control(0x28); // Function Set


(DL=0 4-Bit,N=1 2 Line,F=0 5X7)
lcd_write_control(0x0C); // Display
on/off Control (Entry Display,Cursor off,Cursor not Blink)
lcd_write_control(0x06); // Entry Mode
Set (I/D=1 Increment,S=0 Cursor Shift)
lcd_write_control(0x01); // Clear
Display (Clear Display,Set DD RAM Address=0)
for (i=0;i<100000;i++); // Wait
Command Ready

void goto_cursor(unsigned char i)


{
i |= 0x80;
// Set DD-RAM Address Command
lcd_write_control(i);
}

void lcd_print(unsigned char* str)


{
int i;
for (i=0;i<16 && str[i]!=0;i++) // 16 Character
Print
{
lcd_write_ascii(str[i]); // Print Byte to
LCD
}

void enable_lcd(void) //
Enable Pulse
{
unsigned int i;
// Delay Count

lcd_en_set();
// Enable ON
for (i=0;i<400000;i++);
lcd_en_clr();
// Enable OFF
}

void delay1(unsigned long int count1)


{
while(count1 > 0) {count1--;} // Loop
Decrease Counter
}

Das könnte Ihnen auch gefallen