⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 w77e58.c

📁 GPS定位程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 说明:Winbond 单片机 W77E58 双串口测试程序
 时间:2008年7月3日
 程序:张建波
 串口0 采用9600波特率
 串口1 采用4800波特率
*/
#include "w77e58.h"
#include "string.h"

static int flag_1,flag_0;
//char c1[]="hello china";  //串口0
//char c2[]="hello World";  //串口1 
//串口0 9600   8 N 1
//串口1 4800   8 N 1

//GSM 数据存储数组
unsigned char PhoneNum[12]; //手机号码
unsigned char smsCmd[2];    //短信命令
unsigned char smsPWD[8];       //密码(在绑定指定号码时,需要)
unsigned char sms_count;     //短信长度
unsigned char sms[25];        //短信内容 "*SZ12345678#13577062679#";
unsigned char sms_mode;       //当前短信接收,=1 正在接收 =0 命令语句接收是否完毕

//unsigned char CNMI[]="AT+CNMI=2,2,0,0\r\n";//每次接收短信后,再设置,不然不会再有短信进取
//unsigned char CMGF[]="AT+CMGF=1\r\n"; //是以TEXT格式发送
//GPS ----

//GPS数据存储数组
unsigned char JD[10];            //经度
unsigned char JD_a;            //经度方向
unsigned char WD[9];            //纬度
unsigned char WD_a;            //纬度方向
unsigned char time[6];        //时间
unsigned char speed[5];        //速度
unsigned char high[6];        //高度
unsigned char angle[5];        //方位角
unsigned char use_sat[2];        //使用的卫星数
unsigned char total_sat[2];    //天空中总卫星数
unsigned char lock;            //定位状态

//串口中断需要的变量
unsigned char seg_count;        //逗号计数器
unsigned char dot_count;        //小数点计数器
unsigned char byte_count;        //位数计数器
unsigned char cmd_number;        //命令类型
unsigned char mode;                //0:结束模式,1:命令模式,2:数据模式
unsigned char buf_full;            //1:整句接收完成,相应数据有效。0:缓存数据无效。
unsigned char cmd[5];            //命令类型存储数组

//------
//状态指示灯
sbit P0_0=P0^0;
sbit P0_1=P0^1;
sbit P0_2=P0^2;
sbit P0_3=P0^3;
sbit P0_4=P0^4;
sbit P0_5=P0^5;
sbit P0_6=P0^6;
sbit P0_7=P0^7;
//-----------------
void Delay400Ms(void)
{
 		unsigned char TempCycA = 5;
 		unsigned int TempCycB;
 		while(TempCycA--)
		{
			TempCycB=7269;
			while(TempCycB--);
		};
}
//向串口发送一个字符
void send_char_com0(unsigned char ch) 
{
    SBUF=ch;
    while(TI==0);
    TI=0;
}

void init_GSM(void)
{
 
  //系统初始化
  //初始化 GSM
  // AT+CMGF=1是以TEXT格式发送  
  send_char_com0('A');
  send_char_com0('T');
  send_char_com0('+');
  send_char_com0('C');
  send_char_com0('M');
  send_char_com0('G');
  send_char_com0('F');
  send_char_com0('=');
  send_char_com0('1');
  send_char_com0('\r');
  send_char_com0('\n');
  Delay400Ms();
  Delay400Ms();
  Delay400Ms();
  //Delay400Ms();
  //Delay400Ms();
  //AT+CNMI=2,2,0,0  //每次接收短信后,再设置,不然不会再有短信进取
  send_char_com0('A');
  send_char_com0('T');
  send_char_com0('+');
  send_char_com0('C');
  send_char_com0('N');
  send_char_com0('M');
  send_char_com0('I');
  send_char_com0('=');
  send_char_com0('2');
  send_char_com0(',');
  send_char_com0('2');
  send_char_com0(',');
  send_char_com0('0');
  send_char_com0(',');
  send_char_com0('0');
  send_char_com0('\r');
  send_char_com0('\n');   
}

void SendSM(char *s)
{
int i=0;
  do{ 
     if(s[i]!='$')
	 {
       send_char_com0(s[i]);
	 }
	 i++;
  }while(s[i]!='$');
}

main()
{
//    int i;
	int j=0;
    flag_1=1;
    flag_0=1;

    for(j=0;j<5;j++)
	{
    P0_0=~P0_0;
	P0_1=~P0_1;
	P0_2=~P0_2;
	P0_3=~P0_3;
	P0_4=~P0_4;
	P0_5=~P0_5;
	P0_6=~P0_6;
	P0_7=~P0_7;
	Delay400Ms();
	Delay400Ms();
	}

	P0_0=1;
	P0_1=1;
	P0_2=1;
	P0_3=1;
	P0_4=1;
	P0_5=1;
	P0_6=1;
	P0_7=1;

     //其中串口0用定时器2,串口1用定时器1    
     //串口1的设置
     IE=0x90;      //允许总中断和串口0的中断
     TMOD=0x20;      //定时器1工作在模式1
     TL1=0xfa;      //baud rate=4800
     TH1=0xfa;
     SCON=0x58;      //工作在模式1,接收允许
     PCON=0x00; // SM0=0 SM1=1 在10位异步收发模式 SMOD=0 溢出速率/32     
     ES1=1;    //串口1中断允许     

     //串口0设置
     T2CON=0x30;  //用定时器2做串口0的波特率发生器
	 RCAP2H=0xff;   // 11.0592M晶振下,baud rate=9600  //2400
     RCAP2L=0xdc;   //0x70;
	 SCON1=0x58;   //工作在模式1,允许接收
     
     TR2=1;
     TR1=1;

	     Delay400Ms();
         Delay400Ms();
		 Delay400Ms();
         Delay400Ms();
		 Delay400Ms();
         Delay400Ms();
		 Delay400Ms();
         Delay400Ms();
	 init_GSM(); //初始化GSM 猫

	     Delay400Ms();
         Delay400Ms();
		 Delay400Ms();
         Delay400Ms();
		 Delay400Ms();
         Delay400Ms();
		 Delay400Ms();
         Delay400Ms();
  	     Delay400Ms();
         Delay400Ms();
		 Delay400Ms();
         Delay400Ms();
		 Delay400Ms();
         Delay400Ms();
		 Delay400Ms();
         Delay400Ms();
    for(j=0;j<5;j++)
	{
    P0_0=~P0_0;
	P0_1=~P0_1;
	P0_2=~P0_2;
	P0_3=~P0_3;
	P0_4=~P0_4;
	P0_5=~P0_5;
	P0_6=~P0_6;
	P0_7=~P0_7;
	Delay400Ms();
	Delay400Ms();
	}
     while(1)
     {
       
	     //查询新短信
		 //AT+CMGL
		 if(sms_mode!=-1){
		 send_char_com0('A');send_char_com0('T');send_char_com0('+');send_char_com0('C');send_char_com0('M');send_char_com0('G');send_char_com0('L');
   	     send_char_com0('\r');send_char_com0('\n');
		 Delay400Ms();
         Delay400Ms();
		 Delay400Ms();
         Delay400Ms();
		 }

		 Delay400Ms();
  	     Delay400Ms();
		 Delay400Ms();
  	     Delay400Ms();
		 Delay400Ms();
		 Delay400Ms();   

	   if(buf_full==0)                //无GPS信号时
        {
          P0_0=1;  //1表示没有信号
        }else
		{
       	  P0_0=0; //有信号
		   if(buf_full|0x01)
		   {
		      //GGA语句
			   if(lock=='0')
			   {
			     //如果未定位
				 P0_0=1;
			   }else
			   {
			    //如果已定位
				P0_0=0; 
			   }
		   }
		}
     }
}
void fw(void)
{
  //复位GSM
  //init_GSM();//复位GSM MODEM
}

void dw(void)
{
   //GPS 定位
   int i;
   for(i=0;i<10;i++)
   {
    P0_0=~P0_0;
	P0_1=~P0_1;
	P0_2=~P0_2;
	P0_3=~P0_3;
	Delay400Ms();
	Delay400Ms();
	}
    //init_GSM();//复位GSM MODEM
    //sms_mode=-1;  //定位
   //SendSM("AT+CMGS=\"+8613577062697\"\r\n$");

	SendSM("AT+CMGS=\"+86$");
	for(i=0;i<11;i++)
	{
	 send_char_com0(PhoneNum[i]);
	}
	SendSM("\"\r\n$");
  
    Delay400Ms();
	Delay400Ms();
    
	/*定位数据*/
    /*
    send_char_com0(JD_a);//经度方向
    for(i=0;i<10;i++)
	{
	send_char_com0(JD[i]);//经度
	}
    send_char_com0(WD_a);//纬度方向
    for(i=0;i<9;i++)
	{
	send_char_com0(WD[i]);//纬度
	}
	send_char_com0('T');  //时间
	for(i=0;i<6;i++)
	{
	send_char_com0(time[i]);//纬度
	}
	send_char_com0('S');  //速度
	send_char_com0('P');  //速度
	for(i=0;i<5;i++)
	{
	send_char_com0(speed[i]);//速度
	}
	send_char_com0('^');  //方位角
	for(i=0;i<5;i++)
	{
	send_char_com0(angle[i]);//速度
	}
    */
	/*定位数据*/
    /*----------------------*/
    send_char_com0('M');
    send_char_com0('i');
    send_char_com0('o');
    send_char_com0('_');
    send_char_com0('C');
    send_char_com0('H');
    send_char_com0('S');
    send_char_com0('#');
    send_char_com0(JD_a);//经度方向
    for(i=0;i<2;i++)
	{
	send_char_com0(JD[i]);//经度
	}
	send_char_com0(0x60);//度
    for(i=3;i<2;i++)
	{
	send_char_com0(JD[i]);//经度
	}
	send_char_com0(''');//经度

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -