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

 *第15058篇: 请教一个程序的问题

  
楼 主:jonson1 2003年7月31日12:14
 请教一个程序的问题
各位大虾,小弟请教一个程序问题:

程序在 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;
    
  

    
 
 

}
 


  
2楼:mjianghong 2003年7月31日12:59
 你的函数调用是不是错了? p = strchr(str,'*');是不是应该改为 p = strrchr(str,'*');啊?

>>>>>>对该主题发表你的看法

本主题贴数2,分页: [第1页]


[上一篇主题]:吧str贴出来!

[下一篇主题]:哪位高人能给我说一下硬件看门狗