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

📄 can_c.lst

📁 单片机和GPS接收机构成的车载卫星定位系统
💻 LST
📖 第 1 页 / 共 3 页
字号:
 408   1                                                         //自身节点ID号为00000000!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 409   1           do{;}while(BCAN_SET_OUTCLK(0xda,0x08));       //设置输出控制寄存器OC,时钟分频器CDR
 410   1           do{;}while(BCAN_QUIT_RETMODEL());             //进入工作模式
 411   1      }
C51 COMPILER V8.05a   CAN_C                                                                06/20/2008 07:43:20 PAGE 9   

 412          
 413          void  DataReceive()  interrupt 0  using 1
 414          {
 415   1            red=0;                        //接受指示
 416   1            EX0=0;
 417   1            SJA_BCANAdr=REG_INTERRUPT;    //读取中断寄存器值,判断中断类型
*** ERROR C202 IN LINE 417 OF CAN_C.C: 'SJA_BCANAdr': undefined identifier
 418   1            interrupt_flag=*SJA_BCANAdr;
*** ERROR C202 IN LINE 418 OF CAN_C.C: 'SJA_BCANAdr': undefined identifier
 419   1            if((interrupt_flag&0x01)==1)//接收中断
 420   1               {
 421   2                BCAN_DATA_RECEIVE(SystemBuf); //读取缓冲区数据
 422   2                BCAN_CMD_PRG(RRB_CMD);        //释放接收缓冲区
*** ERROR C202 IN LINE 422 OF CAN_C.C: 'RRB_CMD': undefined identifier
 423   2                request_flag=1;
 424   2                }
 425   1             if((interrupt_flag&0x04)==1)//错误中断
 426   1                {
 427   2                 SJA_reset=0; //复位
 428   2                 }
 429   1         EX0=1;
 430   1      }
 431          void request_data()
 432          {
 433   1           green=0;           //发送指示
 434   1           SendBuf[0]=0x00;   //主节点ID!!!!!!!!!!!!!!!!!!!!!!!!!
 435   1           SendBuf[1]=0x08;
 436   1           SendBuf[2]=0x01;   //自身ID
 437   1           SendBuf[3]='A';
 438   1           SendBuf[4]='B';
 439   1           SendBuf[5]='C';
 440   1           SendBuf[6]=0x01;         //测试用
 441   1           SendBuf[7]=0x01;         //测试用
 442   1           SendBuf[8]=0x01;         //测试用
 443   1           SendBuf[9]=0x01;          //测试用
 444   1           BCAN_DATA_WRITE(SendBuf);
 445   1           BCAN_CMD_PRG(TR_CMD);
*** ERROR C202 IN LINE 445 OF CAN_C.C: 'TR_CMD': undefined identifier
 446   1      }
 447          /***************************lcd********************************/
 448          void bit8_serial_input(uchar ix) //~~液晶八位串输入信号行
 449          {                                //~~ix串行输入的数
 450   1      data uchar i,j,nc;
 451   1      P_E=0;    //clk=0;
 452   1      ab=ix;
 453   1      for(i=0;i<8;i++){
 454   2              P_RW=abit7;    //din=abit7;       ~~输入最高位
 455   2              ab<<=1;
 456   2              P_E=1;                                 //~~锁存输入一位
 457   2              for(j=0;j<10;j++)nc=0;//~~  延时
 458   2              P_E=0;
 459   2              }
 460   1      }
 461          /*---------------------------------------------------------*/
 462          void instruct(uchar dat) //??光标显示,显示控制
 463          {
 464   1      data uchar ch;
 465   1      P_RS=1;   //选通
 466   1      ch=0xf8;      //~~???
 467   1      bit8_serial_input(ch);
 468   1      ch=dat&0xf0;  //~~高四位不变低四位请零
 469   1      bit8_serial_input(ch);
C51 COMPILER V8.05a   CAN_C                                                                06/20/2008 07:43:20 PAGE 10  

 470   1      ch=dat<<4;
 471   1      bit8_serial_input(ch);
 472   1      P_RS=0;  //结束作业
 473   1      }
 474          void write_abyte(uchar dat) //~~写入一位数据
 475          {
 476   1      data uchar ch;
 477   1      P_RS=1;  //读数据--不选通
 478   1      ch=0xfa;  //RS=1 RW=0; ~~莫非还有寄存器CH就为写状态字的
 479   1      bit8_serial_input(ch);
 480   1      ch=dat&0xf0;  //RS=1 RW=0; ~~??写两次还是状态字高几位q
 481   1      bit8_serial_input(ch);
 482   1      ch=dat<<4;
 483   1      bit8_serial_input(ch);
 484   1      P_RS=0;  //结束作业
 485   1      }
 486          
 487          
 488          /*
 489             写一个汉字到x,Y坐标处其中X为8列y为4行
 490             */
 491          void  write_word(uint w)
 492          {
 493   1      data  uchar ch,cl;
 494   1      ch=w>>8; //取高八位ch怎么看不出来
 495   1      cl=w;
 496   1      write_abyte(ch);
 497   1      write_abyte(cl);
 498   1      }
 499          /*-------------------------------------------*/
 500          /*-------------------------------------------*/
 501          dis_hz_str(uchar x, uchar y, uchar *p_hz)  //~~显示函数可
 502          {                //~~能是显示文字(也可是字母)串一共
 503   1      data uchar loc,*p;  //可显示4行汉字由x决定
 504   1      data uint   xi;
 505   1      code uchar xline[5]={0,1,3,2,4};
 506   1      x=xline[x];
 507   1      instruct(home);
 508   1      loc=((x<<3)+y-9)|0x80;//~~
 509   1      instruct(loc); p=p_hz;
 510   1      xi=((*p++)<<8)|*p++;
 511   1      while(xi){
 512   2           write_word(xi);   //*p++;// );
 513   2           xi=((*p++)<<8)|*p++;   //*p++; xi=xi|*p++;
 514   2           }
 515   1      }
 516          /*显示字母数字在x,y处
 517          */
 518          void dis_str(uchar x, uchar y, uchar *str)
 519          {
 520   1      data uchar loc,*p;
 521   1      code uchar xline[5]={0,1,3,2,4};
 522   1      p=str;
 523   1      x=xline[x];
 524   1      instruct(home);
 525   1      loc=(16*(x-1)+y-1);
 526   1      if(loc&0x01){
 527   2             loc/=2;
 528   2             instruct(loc|0x80);
 529   2             //ch=' ';   //字符串前加空格(0x20 )
 530   2             write_abyte(' ');
 531   2             }else{
C51 COMPILER V8.05a   CAN_C                                                                06/20/2008 07:43:20 PAGE 11  

 532   2             loc/=2;
 533   2             instruct(loc|0x80);
 534   2             }
 535   1      while(*p){
 536   2             write_abyte(*p++);
 537   2             }
 538   1      //instruct(0x9e); write_abyte(' ');
 539   1      }
 540          void initial_screen(void)//~~初始化显示屏
 541          {
 542   1      data uchar i,j;
 543   1      P0=0xff;
 544   1      P_RS=0;           //串行--不选通
 545   1      //P_PSB=0;
 546   1      P_E=0;   //串行方式
 547   1      instruct(f_set);    //0x30;     //8位并行接口 基本指令
 548   1      for(i=0;i<30;i++){}   //~~~延时何用???
 549   1      for(i=0;i<250;i++){}
 550   1      for(i=0;i<250;i++){}
 551   1      instruct(f_set);    //0x30;     //8位并行接口 基本指令
 552   1      for(i=0;i<30;i++){}
 553   1      for(i=0;i<250;i++){}
 554   1      for(i=0;i<250;i++){}
 555   1      instruct(dis_on);     //0x0f);     //开启屏幕 光标 闪烁
 556   1      for(i=0;i<30;i++){}
 557   1      instruct(clear);     //0x01);     //清屏幕 clear
 558   1      for(j=0;j<10;j++){
 559   2         for(i=0;i<250;i++){}
 560   2         }
 561   1      instruct(in_mode);     //0x06);    //光标右移、地址增1 方式
 562   1      for(i=0;i<30;i++){}
 563   1      instruct(home);
 564   1      }
 565          /*---------------------------------------------------------*/
 566          /*---------------------------------------------------------*/
 567          void itoa(int x,unsigned char *str)//BCD码到ASCII码
 568          {
 569   1      unsigned int n;
 570   1      unsigned char chn,*p,str1[5];
 571   1      data unsigned char i,j;
 572   1      if(x<0){
 573   2              *str++='-';
 574   2              x=-x;
 575   2              }
 576   1      n=x;
 577   1      p=str1;
 578   1      j=0;
 579   1      while(n!=0){
 580   2              chn=n%10;
 581   2              n=n/10;
 582   2              *p++=chn+'0';
 583   2              j++;
 584   2              }
 585   1      if(j!=0){
 586   2              p--;
 587   2              for(i=0;i<j;i++)*str++=*p--;
 588   2              }
 589   1      else    *str++='0';
 590   1      *str=0;
 591   1      return;
 592   1      }
 593          //------------------------------------------------------------------
C51 COMPILER V8.05a   CAN_C                                                                06/20/2008 07:43:20 PAGE 12  

 594          
 595          void   b2hex(char ch,char *p)
 596          {
 597   1      char c1,c2;
 598   1          c1=((ch&0xf0)>>4)&0x0f;
 599   1         //c1=c1>>4;
 600   1          c2=ch&0x0f;   //二进制变16进制
 601   1          if(c1<=9)c1=c1+'0'; else c1=c1-10+'A';
 602   1          if(c2<=9)c2=c2+'0'; else c2=c2-10+'A';
 603   1          *p++=c1;  *p=c2;
 604   1      }
 605          //------------------------------------------------------------------
 606          void dis_bin(uchar *buff,uchar n)
 607          {
 608   1      data uchar i,j,ch,*p,*p1;
 609   1      idata uchar str[20],str1[3];
 610   1      p=buff; p1=str; j=0;
 611   1      for(i=0;i<n;i++){
 612   2          ch=*p++;
 613   2          b2hex(ch,str1);  //char ch,char *p)
 614   2          *p1++=str1[0]; *p1++=str1[1];
 615   2          j=j+2;
 616   2          }
 617   1      p=buff;
 618   1      
 619   1      for(i=0;i<j;i++)*p++=str[i];
 620   1      }
 621          /*-----------------------------------------------------------------*/
 622          void main(void)
 623          {  uint i;
 624   1         i=0;
 625   1         red=1;
 626   1         green=1;
 627   1         initial_screen();
 628   1         instruct(0x0c); //关闭光标
 629   1         InitialCAN();
 630   1         EX0=1;   // 开外部中断
 631   1         IT0=0;   // 外部中断源采用边沿触发方式
 632   1         EA=1;    //总线初始化后开中断
 633   1           while(1)
 634   1           { dis_str(1,4,"CAN");
 635   2             dis_hz_str(1,4,"总线从\0\0");
 636   2             if(request_flag==1)
 637   2             {
 638   3               itoa(i++,str);
 639   3               dis_str(4,13,str);
 640   3               dis_bin(SystemBuf,10);
 641   3               dis_str(2,1,SystemBuf);
 642   3               request_data();
 643   3               request_flag=0;
 644   3              }
 645   2           }
 646   1      }

C51 COMPILATION COMPLETE.  1 WARNING(S),  77 ERROR(S)

⌨️ 快捷键说明

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