#include <reg52.h>
#include <absacc.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
#define LCD_data P0
#define Phone_connec
tion 1
#define Clear_Connect 0
sbit LCD_RS = P3^5;
sbit LCD_RW = P3^6;
sbit LCD_EN = P3^4;
sbit LCD_PSB = P3^7;
sbit wela = P2^6;
sbit dula = P2^7;
sbit beep=P2^3;
void delayms(uint x);
void key_4x4_scan();
void ScanMessage(void);
void clr_rsbuf(void);
char Calls_State_Flag=Clear_Connect;
uchar code AT[]="AT
" ;
uchar code AT_CMGF[]= "AT+CMGF=1
";
uchar code AT_CMGS[]= "AT+CMGS=15212345577
";
uchar code AT_CMGR[]= "AT+CMGR=2
";
uchar code AT_CSCA[]="AT+CSCA="+8613800100500"
";
uchar code AT_CNMI[]= "AT+CNMI=2,1,0,0
";
uchar code AT_CLIP[]= "AT+CLIP=1,1
";
uchar Sms[]="hello!";
uchar Phone_call[]="5212345577";
uchar phone_num[12];
uchar RsPoint=0;
uchar RsBuf[100];
uchar j=0;
uchar k=0;
uint i,ii;
uchar num,mm,nn;
void write_cmd(uchar cmd)
{
LCD_RS = 0;
LCD_RW = 0;
LCD_EN = 0;
P0 = cmd;
delayms(5);
LCD_EN = 1;
delayms(5);
LCD_EN = 0;
}
void write_dat(uchar dat)
{
LCD_RS = 1;
LCD_RW = 0;
LCD_EN = 0;
P0 = dat;
delayms(5);
LCD_EN = 1;
delayms(5);
LCD_EN = 0;
}
void lcd_pos(uchar X,uchar Y)
{
uchar pos;
if(X==0)
{X=0x80;}
else if(X==1)
{X=0x90;}
else if(X==2)
{X=0x88;}
else if(X==3)
{X=0x98;}
pos=X+Y;
write_cmd(pos);
}
void lcd_init()
{
LCD_PSB = 1;
write_cmd(0x30);
delayms(5);
write_cmd(0x0C);
delayms(5);
write_cmd(0x01);
delayms(5);
}
void di()
{
beep=0;
delayms(250);
beep=1;
}
void delayms(uint x)
{
uint i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);
}
void Print_Char(uchar ch)
{
SBUF=ch;
while(TI==0);
TI=0;
}
void Print_Str(uchar *str)
{
while(*str!=' ')
{
Print_Char(*str++);
}
}
void clr_rsbuf(void)
{
for(RsPoint=0;RsPoint<100;RsPoint++)
{
RsBuf[RsPoint]=0x00;
}
RsPoint=0;
}
void ser()interrupt 4
{
if(RI==1)
{
di();
delayms(50);
RI=0;
RsBuf[RsPoint++]=SBUF;
if(RsPoint>=sizeof(RsBuf))
{
RsPoint=0;
}
}
}
Ini_UART(void)
{
TMOD = 0x20;
TH1 = 0xFD;
TL1 = 0xFD;
SCON = 0x50;
PCON = 0x00;
TF1 = 1;
TR1 = 1;
ES=1;
ET0=1;
EA=1;
}
void ScanMessage(void)
{
for(ii=0;ii<32;ii++)
if(RsBuf[ii-3]=='C'&&RsBuf[ii-2]=='M'&&RsBuf[ii-1]=='T'&&RsBuf[ii]=='I')
{
di();
delayms(50);
di();
delayms(50);
di();
delayms(50);
lcd_pos(0,0);
clr_rsbuf();
Print_Str(AT_CMGR);
delayms(250);delayms(250);delayms(250);delayms(250);
lcd_pos(0,0);
for(i=0;i<15;i++)
{
write_dat(RsBuf[i+20]);
delayms(100);
}
lcd_pos(1,0);
for(i=15;i<32;i++)
{
write_dat(RsBuf[i+20]);
delayms(100);
}
}
else if(RsBuf[ii-3]=='C'&&RsBuf[ii-2]=='L'&&RsBuf[ii-1]=='I'&&RsBuf[ii]=='P')
{
beep=0;
delayms(250);
delayms(250);
lcd_pos(0,0);
for(i=(ii+3);i<15+(ii+3);i++)
{
write_dat(RsBuf
);
delayms(5);
}
lcd_pos(1,0);
for(i=(ii+3)+15;i<32+(ii+3);i++)
{
write_dat(RsBuf);
delayms(5);
}
while(!beep)
{
key_4x4_scan();
}
clr_rsbuf();
}
}
void phone()
{
uchar ATD1[]="ATD";
uchar ATD3[]=";
";
uchar ATDINTOL[25];
strcpy(ATDINTOL,ATD1);
strcat(ATDINTOL,phone_num); //EEE
//strcat(ATDINTOL,Phone_call);
strcat(ATDINTOL,ATD3);
Print_Str(ATDINTOL);
delayms(250); delayms(250);
}
void GSM_ATH()
{
Print_Str("ATH");
Print_Str("
");
delayms(250);delayms(250);delayms(250);delayms(250);
}
void Rphone()
{
Print_Str("ATA");
Print_Str("
");
delayms(250);
delayms(250);
delayms(250);
delayms(250);
}
void GSM_TEXT_SMS()
{
Print_Str(AT_CMGS);
Print_Str(Phone_call);
Print_Str("
");
delayms(200);
Print_Str(Sms);
Print_Char(0x1A);
ES=1;
delayms(250);
delayms(250);
}
void main()
{
di();
Ini_UART();
wela=0;
dula=0;
delayms(10);
lcd_init();
k=0;
Print_Str(AT);
delayms(100);
Print_Str(AT_CMGF);
delayms(100);
Print_Str(AT_CNMI);
delayms(200);
Print_Str(AT_CLIP);
delayms(250);
clr_rsbuf();
P3=0xff;
while(1)
{
ScanMessage();
key_4x4_scan();
}
}
void key_4x4_scan()
{
uchar temp,i;
P3=0xfe;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delayms(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xee:num=0;
phone_num[k++]=0x30;
break;
case 0xde:num=1;
phone_num[k++]=0x31;
break;
case 0xbe:num=2;
phone_num[k++]=0x32;
break;
case 0x7e:num=3;
phone_num[k++]=0x33;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
write_cmd(0x01);
lcd_pos(0,0);
while(phone_num!=' ')
{
write_dat(phone_num);
i++;
}
i=0;
}
}
P3=0xfd;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delayms(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xed:num=4;
phone_num[k++]=0x34;
break;
case 0xdd:num=5;
phone_num[k++]=0x35;
break;
case 0xbd:num=6;
phone_num[k++]=0x36;
break;
case 0x7d:num=7;
phone_num[k++]=0x37;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
write_cmd(0x01);
lcd_pos(0,0);
while(phone_num!=' ')
{
write_dat(phone_num);
i++;
}
i=0;
}
}
P3=0xfb;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delayms(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xeb:num=8;
phone_num[k++]=0x38;
break;
case 0xdb:num=9;
phone_num[k++]=0x39;
break;
case 0xbb:num=10;
break;
case 0x7b:num=11;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
if(num==10||num==11)
{
switch(num)
{
case 10: //打电话
write_cmd(0x01);
clr_rsbuf();
phone();
lcd_pos(0,0);
for(nn=0;nn<32;nn++)
{
write_dat(RsBuf);
delayms(50);
}
delayms(250);
Calls_State_Flag=Clear_Connect;
break;
case 11: //挂电话
write_cmd(0x01);
clr_rsbuf();
GSM_ATH();
beep=1;
lcd_pos(0,0);
for(nn=0;nn<32;nn++)
{
write_dat(RsBuf); //
delayms(50);
}
delayms(250);
Calls_State_Flag=Phone_connection;
break;
}
}
else
{
write_cmd(0x01);
lcd_pos(0,0);
while(phone_num!=' ')
{
write_dat(phone_num);
i++;
}
i=0;
}
}
}
P3=0xf7;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delayms(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xe7:num=12;
break;
case 0xd7:num=13;
break;
case 0xb7:num=14;
break;
case 0x77:num=15;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
switch(num)
{
case 12: //接听电话
write_cmd(0x01);
clr_rsbuf();
Rphone();
beep=1;
lcd_pos(0,0);
for(i=0;i<32;i++)
{
write_dat(RsBuf);
delayms(50);
}
delayms(250);delayms(250);
break;
case 13: //发送短信
write_cmd(0x01);
clr_rsbuf();
//GSM_TEXT();
GSM_TEXT_SMS();
lcd_pos(0,0);
for(i=0;i<15;i++)
{
write_dat(RsBuf);
delayms(100);
}
for(i=15;i<32;i++)
{
write_dat(RsBuf);
delayms(100);
}
delayms(250);
delayms(250);
break;
case 14:// 清屏
write_cmd(0x01);
break;
case 15:// 清屏
write_cmd(0x01);
break;
}
}
}
}
4*4键盘扫描有问题,求大神改一改程序
一周热门 更多>