📄 serial.c
字号:
/******************************************************************************/
/* SERIAL.C: Low Level Serial Routines */
/******************************************************************************/
/* This file is part of the uVision/ARM development tools. */
/* Copyright (c) 2005-2006 Keil Software. All rights reserved. */
/* This software may only be used under the terms of a valid, current, */
/* end user licence from KEIL for a compatible version of KEIL software */
/* development tools. Nothing else gives you the right to use this software. */
/******************************************************************************/
#include <LPC21xx.H> /* LPC21xx definitions */
#include <stdio.h>
#include "adc.h"
#include "rtc.h"
#include "lcd_disp.h"
#include "gsm.h"
#define CR 0X0A
#define LF 0X0D
void send_bcd(int );
// #define VREF_ADC 3.3
// #define CRITICAL_VALUE_IR 150
// #define CRITICAL_VALUE_LDR 150
void send_current_time(void);
void ascii(unsigned int);
void hextobcd(unsigned long int);
char a[]="CHN1:";
char b[]="CHN2:";
char c[]="CHN3:";
char d[]="CHN4:";
char e[]="TIME:";
//void SEND_CMD(unsigned char *BASE_ADD,unsigned char COUNT);
void sendchar (unsigned char);
void delay1(void);
/* implementation of putchar (also used by printf function to output data) */
void sendchar (unsigned char ch) /* Write character to Serial Port */
{
U0THR = ch; /* output CR */
while (!(U0LSR & 0x20));
}
int getkey (void) { /* Read character from Serial Port */
while (!(U1LSR & 0x01));
return (U1RBR);
}
int main (void) { /* execution starts here */
unsigned int adcdata,adcdata1,temp,d1,d2,d3,d4,ch,p,count=0,count1=0;
unsigned char i,data[]="RF BASED SECURITY SYSTEM";
unsigned char ss[]="WELCOME";
unsigned char dd[]="Ashwini.M.K:";
IODIR0|=0X0400000;
IODIR0|=0XF0;
lcd_initialise();
lcd_command(0x01);
lcd_command(0x80);
for(i=0;ss[i]!='\0';i++)
{
display(ss[i]);
delay1();
if(i==15)
lcd_command(0x07);
}
lcd_command(0x01);
IOCLR1|=0x00300000;
UART_INIT();
GSM();
// rtc_init();
PINSEL1|=0x15400000;
while(1)
{
ADCR=0X01200401;
while(!(ADDR & 0x80000000));
adcdata=ADDR;
adcdata1=adcdata >> 6;
adcdata1=adcdata1 & 0X3FF;
temp=adcdata1;
d1=temp%10;
temp=temp/10;
d2=temp%10;
temp=temp/10;
d3=temp%10;
d4=temp/10;
p=d4*1000+d3*100+d2*10+d1;
d1+=0x30;
d2+=0x30;
d3+=0x30;
d4+=0x30;
if(p<100)
{
if(count<=0)
{
count=1;
IOSET1|=0x00100000;
delay1();
IOCLR1|=0x00100000;
delay1();
SEND_CMD(CMD_5,20);
SEND_CMD("temp=",20);
sendchar('T');
sendchar('=');
sendchar(d4);
sendchar(d3);
sendchar(d2);
sendchar(d1);
sendchar(0x0d);
sendchar(0x0a);
SEND_MSG(MSG_2_SEND,18);
delay1();
delay1();
delay1();
delay1();
delay1();
delay1();
delay1();
}
}
ADCR=0X01200404;
while(!(ADDR & 0x80000000));
adcdata=ADDR;
adcdata1=adcdata >> 6;
adcdata1=adcdata1 & 0X3FF;
temp=adcdata1;
d1=temp%10;
temp=temp/10;
d2=temp%10;
temp=temp/10;
d3=temp%10;
d4=temp/10;
p=d4*1000+d3*100+d2*10+d1;
d1+=0x30;
d2+=0x30;
d3+=0x30;
d4+=0x30;
if(p>800)
{
if(count1<=0)
{
count1=1;
IOSET1|=0x00200000;
delay1();
IOCLR1|=0x00200000;
delay1();
SEND_CMD(CMD_5,20);
SEND_MSG(MSG_3_SEND,18);
delay1();
delay1();
delay1();
delay1();
delay1();
delay1();
}
}
}
}
void delay1(void)
{
unsigned long i=0;
for(i=0;i<=(60000*2);i++);for(i=0;i<=(60000*2);i++);for(i=0;i<=(60000*2);i++);for(i=0;i<=(60000*2);i++);
for(i=0;i<=(60000*2);i++);for(i=0;i<=(60000*2);i++);for(i=0;i<=(60000*2);i++);for(i=0;i<=(60000*2);i++);
for(i=0;i<=(60000*2);i++);for(i=0;i<=(60000*2);i++);for(i=0;i<=(60000*2);i++);for(i=0;i<=(60000*2);i++);
for(i=0;i<=(60000*2);i++);for(i=0;i<=(60000*2);i++);for(i=0;i<=(60000*2);i++);for(i=0;i<=(60000*2);i++);
for(i=0;i<=(60000*2);i++);for(i=0;i<=(60000*2);i++);for(i=0;i<=(60000*2);i++);for(i=0;i<=(60000*2);i++);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -