导航: 老古网老古论坛XMOS公共讨论区XMOS开源项目区单片机程序设计嵌入式系统广告区域
→请教一个程序的问题

* 38867: 请教一个程序的问题

   jonson1 
jonson1发表的帖子 

 请教一个程序的问题
各位大虾,小弟请教一个程序问题:

程序在 p = strchr(str,'*'); 执行的结果是NULL
可是STR中确有此字符。不知是否可告知一二,谢谢!

#pragma optimize(8,size)
#pragma SYMBOLS


/*----------------INCLUDE --------------------------------------*/
#include "upsd_hardware.h"  // environment hardware specific defines
#include "upsd3200.h"   // special function register declarations for UPSD
//#include "upsd_uart.h"
#include "datatype.h"
#include "string.h"
//#include "GPS_Pars.h"

/*--------------------------------------------------------------------*/
// Enable one for Uart1 for debug
//#include "ISD51_U1.h"  // Header for ISD51 debugger using uPSD Uart1 


//xdata PSD_REGS PSD8xx_reg _at_ PSD_REG_ADDR;  // Define PSD registers at address "csiop" spa
#define FRAMELEN 128
UCHAR xdata gps_frame[FRAMELEN];

//"$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A";     //Data Buffer for UART0 Receiver
char main(void)
{
  unsigned char xdata *str="$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A";

 UCHAR i,len;
 UCHAR check[2],data *p;
 UCHAR xor_chk,val;
 


 p = strchr(str,'*');
 if( p == NULL ) return 0;

 strncpy(check,p+1,2);
 //need modify
 len = p-str + 2;
// for(i=0;i  <len;i++)
//  gps_frame[i] = uPSD_UART_Getchar(0); 
 
 strncpy(gps_frame,str,len); //here should read from buffer one by one
 gps_frame[len] = 0;  //
 
 
 xor_chk = 0x00;
 for(i=0; ;i++){
  if(i >   FRAMELEN)
       break;    //void dead loop;
  if(gps_frame[i] =='$') 
       xor_chk='$';
  else if(gps_frame[i] == '*')
   break;
  xor_chk ^=gps_frame[i];
  
 }
 if((check[0] >  ='0') &&(check[0]   <='9')){
  val = check[0] -'0';
  val  <  <=4;
 }
 else {
  val = check[0]-0x37;
  val  <  <=4;
 }
 if((check[1] >  ='0') && (check[1]   <='9'))
  val +=check[1]-0x37;
  
 if(val == xor_chk)
  return 1;
 else
  return 0;
    
  

    
 
 

}
 




发表时间:2003年7月31日12:14:12

  
回复该帖

本主题共有 2 帖,分页:>>>>>该主题的所有内容[2]条

 *树形目录 只列出部分跟帖的标题以及简单的摘要信息 该主题的部分跟帖如下:

  38871.[详细]你的函数调用是不是错了? p = strchr(str,'*..
摘要:......(无内容)
- [mjianghong][1192次] 2003年7月31日

[上一篇帖子]:公司名?工钱?
[下一篇帖子]:哪位高人能给我说一下硬件看门狗小弟急用,请帮忙