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

📄 can_gps.c

📁 单片机和GPS接收机构成的车载卫星定位系统
💻 C
📖 第 1 页 / 共 4 页
字号:
   {wrbyt24(*p1); get_ACK24(); p1++;}
stop24();
}

uchar read_abyte24(uint loc,uchar aa,uchar bb)
{
data uchar i;
bit flag;
stop24();
flag=1; i=0;
while(flag){
     i++; if(i>250)return 0xff;
     start24();
     wrbyt24(aa);
     flag=get_ACK24();
     if(flag)stop24();
     }
i=loc>>8;
wrbyt24(i);
get_ACK24();
i=loc;
wrbyt24(i);
get_ACK24();
start24();
wrbyt24(bb);
get_ACK24();
i=rdbyt24();
SDA24=1;  //NO ACK24
stop24();
return i;
}
void read_nbyte24(uint loc,uchar *p,uchar aa,uchar bb)  //n=16
{
data uchar i,*p1;
bit flag;
p1=p;
stop24();
flag=1; i=0;
while(flag){
     i++; if(i>250)return;;
     start24();
     wrbyt24(aa);
     flag=get_ACK24();
     if(flag)stop24();
     }
i=loc>>8;
wrbyt24(i);
get_ACK24();
i=loc;
wrbyt24(i);
get_ACK24();
start24();
wrbyt24(bb);
get_ACK24();
for(i=0;i<64;i++) //一页写的字节个数 64个
   {*p1=rdbyt24(); tack24(); p1++;}
rdbyt24();
SDA24=1;
stop24();
}

/*----------------------------------------------------------------------*/
/*---------------------------------------------------------*/

void get_24_buff(char *buff,uint n)  //n是页数
{
//1片AT24C512有62K字节的容量,可以分成512页,每页64个字节
//1片AT24C256有32K字节的容量,可以分成512页,每页64个字节
//1片AT24C128有16K字节的容量,可以分成256页,每页64个字节
data char *p1;
data uint base;  /*xdata*/
p1=buff;
base=0x40+((n-1)<<6); //一页写的字节个数 64个
if((1536<n)&(n<=2048))read_nbyte24(base,p1,0xa6,0xa7);
if((1024<n)&(n<=1536))read_nbyte24(base,p1,0xa4,0xa5);
if(( 512<n)&(n<=1024))read_nbyte24(base,p1,0xa2,0xa3);
if(n<=512)            read_nbyte24(base,p1,0xa0,0xa1);

//*(p1+12)=read_abyte24(base+12); //trap_set
}
/*---------------------------------------*/
/*n==1--7*/
void save_24_buff(char *buff,uint n1)
{
//1片AT24C512有62K字节的容量,可以分成512页,每页64个字节
//1片AT24C256有32K字节的容量,可以分成512页,每页64个字节
//1片AT24C128有16K字节的容量,可以分成256页,每页64个字节
data char *p;
data uint base,n;
p=buff;
n=n1; //ip=*(p+14);    //ip1;
base=0x40+((n-1)<<6); //一页写的字节个数 64个
if((1536<n)&(n<=2048))write_nbyte24(base,p,0xa6);
if((1024<n)&(n<=1536))write_nbyte24(base,p,0xa4);
if(( 512<n)&(n<=1024))write_nbyte24(base,p,0xa2);
if(n<=512)            write_nbyte24(base,p,0xa0);
//write_abyte24(base+14,ip);
//write_abyte24(base+15,0x55);
}
/*************************************************************/
/********************** LCD **********************************/
/*************************************************************/
void bit8_serial_input(uchar ix) //~~液晶八位串输入信号行
{                                //~~ix串行输入的数
idata uchar i;
P_E=0;    //clk=0;
ab=ix;
for(i=0;i<8;i++){
	P_RW=abit7;    //din=abit7;       ~~输入最高位
	ab<<=1;
	P_E=1;  	   //~~锁存输入一位                             
	P_E=0;
	}
}
/*---------------------------------------------------------*/
void instruct(uchar dat) //??光标显示,显示控制
{
P_RS=1;   //选通
bit8_serial_input(0xf8);
bit8_serial_input(dat&0xf0);
bit8_serial_input(dat<<4);
P_RS=0;  //结束作业
}
void write_abyte(uchar dat) //~~写入一位数据
{
P_RS=1;  //读数据--不选通
bit8_serial_input(0xfa);
bit8_serial_input(dat&0xf0);
bit8_serial_input(dat<<4);
P_RS=0;  //结束作业
}
/*写一个汉字到x,Y坐标处其中X为8列y为4行*/
void  write_word(uint w)
{
write_abyte(w>>8);
write_abyte(w);
}
/*-------------------------------------------*/
/*-------------------------------------------*/
dis_hz_str(uchar x, uchar y, uchar *p_hz,uchar number)  //~~显示函数可
{                //~~能是显示文字(也可是字母)串一共
idata uchar loc,*p;  //可显示4行汉字由x决定
idata uint  xi;
code uchar xline[5]={0,1,3,2,4};
x=xline[x];
instruct(home);
loc=((x<<3)+y-9)|0x80;//~~
instruct(loc); p=p_hz;
xi=((*p++)<<8)|*p++;
while(number--){
     write_word(xi);   //*p++;// );
     xi=((*p++)<<8)|*p++;   //*p++; xi=xi|*p++;
     }
}
/*显示字母数字在x,y处*/
void dis_str(uchar x, uchar y, uchar *str,uchar number)
{
idata uchar loc,*p;
code uchar xline[5]={0,1,3,2,4};
p=str;
x=xline[x];
instruct(home);
loc=(16*(x-1)+y-1);
if(loc&0x01){
       loc/=2;
       instruct(loc|0x80);
       write_abyte(' ');
       }else{
       loc/=2;
       instruct(loc|0x80);
       }
while(number--){
       write_abyte(*p++);
       }
}
/*----------------------------------------*/
void screen_cls(void)	 //清屏
{
 instruct(clear);
 delay_us(200);   //清屏幕,约1.6ms
}
/*----------------------------------------*/
void initial_screen(void)//~~初始化显示屏
{
P_RS=0;                         //串行--不选通
P_E=0;                          //串行方式
instruct(f_set);    //0x30;     //8位并行接口 基本指令
instruct(f_set);    //0x30;     //8位并行接口 基本指令
instruct(dis_on);   //0x0f;     //开启屏幕 光标 闪烁
instruct(dis_cur);  //0x0f;     //
instruct(clear);    //0x01);     //清屏幕 clear
delay_us(100);
instruct(in_mode);  //0x06);    //光标右移、地址增1 方式
instruct(home);
}
void   b2hex(char ch,char *p)
{
char c1,c2;
    c1=((ch&0xf0)>>4)&0x0f;
   //c1=c1>>4;
    c2=ch&0x0f;   //二进制变16进制
    if(c1<=9)c1=c1+'0'; else c1=c1-10+'A';
    if(c2<=9)c2=c2+'0'; else c2=c2-10+'A';
    *p++=c1;  *p=c2;
}
//------------------------------------------------------------------
void dis_bin(uchar *buff,uchar n)
{
data uchar i,j,ch,*p,*p1;
idata uchar str[20],str1[3];
p=buff; p1=str; j=0;
for(i=0;i<n;i++){
    ch=*p++;
    b2hex(ch,str1);  //char ch,char *p)
    *p1++=str1[0]; *p1++=str1[1];
    j=j+2;
    }
p=buff;

for(i=0;i<j;i++)*p++=str[i];
}
/*************************************************************/
/********************** 串口 *********************************/
/*************************************************************/
/*----------------------------------------- */
void comm(uchar tt)
{
SBUF=tt;
EA = 0;
while(TI==0);
TI=0;
EA = 1;
}
/*----------------------------------------*/
void comm_buff(uchar *tt,n)      //从1发送
{int i;
 for(i=0;i<n;i++)comm(tt[i]);
}
/*************************************************************/
/********************** 其他 *********************************/
/*************************************************************/
/*---------------------------------------*/
void init(void)
{
TR1=1;
TMOD=0x21;      /* T0为方式1,T1方式2*/
TH1=0x0fd;
             /*11.0592M   PCON=0x80加倍  PCON=0x00 不加倍
				  0x0fd    19200			 9600
				  0x0fa     9600			 4800
				  0x0f4     4800			 2400
				  0x0e8     2400			 1200
				  0x0d0     1200			  600
				   12M 	  PCON=0x80加倍  PCON=0x00 不加倍
				  0x0f3     4800			 2400
				  0x0e6     2400			 1200
				  0x0cc     1200			  600
			 */
PCON=0x80;      /*PCON=0x00波特率=4800*/  //PCON=0x80波特率翻倍/*波特率=9600*/
SCON=0x50;
SM2=0;
TR1=1;          /*串行口设置为方式1,REN=1*/
REN=1;
ES=1;
EA=1;           /*开总中断*/
RI=0;           /*接收数据为开启*/
}
void SYS_init(void)
{
machine_NUM	   =0x02;
function_code  =0x04;
data_NUMER     =0x10;

WD_a[0]=JD_a[0]='"';
seg_count=0;        //逗号计数器
dot_count=0;        //小数点计数器
byte_count=0;       //位数计数器
cmd_number=0;       //命令类型,数据类型:1、GGA 2、GSV 3、RMC
mode=0;             //0:结束模式,1:命令模式(判断数据类型)2:数据模式(数据接受和处理)
buf_full=0;         //1:整句接收完成,相应数据有效。0:缓存数据无效。

initial_screen();
screen_cls();
dis_hz_str(1,2,"卫星定位系统",6);
dis_hz_str(3,1,"不大点电子实验室",8);
dis_hz_str(4,2,"东北农业大学",6);
delay_us(60000);
instruct(clear);delay_us(100);
init();
dis_str(2,4,"Connect...",10);
delay_us(65000);
screen_cls();
}
/**************************************************************************************************/
/********************** 主函数 ********************************************************************/
/**************************************************************************************************/
void main(void)
{
 uchar key_val;
 //code uchar buff0[]="a1234567890";
 //code uchar buff1[]={'a','0','1','2','3','4','5','6','7','8','9'};
 //uchar str[6];
              
SYS_init();		   /*系统初始化*/
InitialCAN();
EX0=1;   // 开外部中断
IT0=0;   // 外部中断源采用边沿触发方式

while(1)
 {	 
     //key_val=keys();
	 switch(key_val)
	  {
	   case	1: /*get_24_buff(buff_send_SPI,1);comm_buff(buff_send_SPI,17);*/;break;
	   case	2: machine_NUM++;break;
	   case	3: machine_NUM--;break;
	   case	4: break;
	   default:break;
	   }
     if(buf_full==0)                //无GPS信号时
      {
            dsp_count++;
            if(dsp_count>=1000)
            	{
                screen_cls();            //清屏
                dis_str(2,1,"No GPS Connect..",16);
                while(buf_full==0)
				  {
				   delay_us(30000);
				   //spi_out(NO_GPS,19);
				   request_data(NO_GPS,19);
				  }
                screen_cls();    
                dsp_count=0;
            	}
       }
     else
      {                        //有GPS信号时 
	  if(lock=='0')		//未定位
	    //spi_out(NO_position,19);
		request_data(NO_position,19);	     
	  else
		{			    //已定位
		 //data_dispose();
	     //spi_out(buff_send_SPI,19);

⌨️ 快捷键说明

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