咨询ch372传输数据格式的问题

现在准备用ch372b+msp430f149做a/d采集,然后把数据送到pc显示,现在430发送字节,pc采用提供的ch372debug界面可以接收到该字节,我的问题是我想显示的不是字节,而是10进制的数字,该怎么修改?谢谢

ch372debug显示的就是数字 只是16进制的


请把你写的下位机程序写下来好吗


好的#include #include "CH372V_Init_MSP430.h" unsigned char WatchPoint,itemp; unsigned char buffer[64],buffer1[64]; unsigned int k=0; unsigned char temp1,temp2; double temp; //发送单字节命令 void CH372V_SendCMD1(unsigned char Command) { CH372V_DIR = 0xFF; CH372V_OUT = Command; //发送数据 CH372V_A0_HI; //A0=1命令 CH372V_CS_LO; //CS有效 CH372V_WR_LO; //WR有效 _NOP();_NOP();_NOP(); CH372V_WR_HI; //WR无效 CH372V_CS_HI; //CS无效 } //发送单字节数据 void CH372V_SendData(unsigned char data) { CH372V_DIR = 0xFF; CH372V_OUT = data; //发送数据 CH372V_A0_LO; //A0=数 CH372V_CS_LO; //CS有效 CH372V_WR_LO; //WR有效 _NOP();_NOP();_NOP(); CH372V_WR_HI; //WR无效 CH372V_CS_HI; //CS无效 }

//接收数据 unsigned char CH372V_RecData(void) { unsigned char data; CH372V_DIR = 0x00; CH372V_A0_LO; //A0=1命令 CH372V_CS_LO; //CS有效 CH372V_RD_LO; //WR有效 _NOP();_NOP();_NOP(); data=CH372V_IN; CH372V_RD_HI; //WR无效 CH372V_CS_HI; //CS无效 _NOP(); return data; } //设置VID和PID void CH372V_SetVIDPID(void) { CH372V_DIR = 0xFF; CH372V_OUT = 0x12; CH372V_CS_LO; //CS有效 CH372V_A0_HI; //A0=1命令 CH372V_WR_LO; //WR有效 _NOP();_NOP();_NOP(); CH372V_WR_HI; //WR无效 _NOP();_NOP();_NOP(); itemp = (unsigned char)(CH372V_VID&0xff); //VID低字节 CH372V_OUT = 0x48;//itemp; CH372V_A0_LO; //A0=0数据 CH372V_WR_LO; //WR有效 _NOP();_NOP();_NOP(); CH372V_WR_HI; //WR无效 _NOP();_NOP();_NOP(); itemp = (unsigned char)((CH372V_VID>>8)&0xff); //VID高字节 CH372V_OUT = 0x43;//itemp; CH372V_A0_LO; //A0=0数据 CH372V_WR_LO; //WR有效 _NOP();_NOP();_NOP(); CH372V_WR_HI; //WR无效 _NOP();_NOP();_NOP(); itemp = (unsigned char)(CH372V_PID&0xff); //PID低字节 CH372V_OUT = 0x37;//itemp; CH372V_A0_LO; //A0=0数据 CH372V_WR_LO; //WR有效 _NOP();_NOP();_NOP(); CH372V_WR_HI; //WR无效 _NOP();_NOP();_NOP(); itemp = (unsigned char)((CH372V_PID>>8)&0xff); //PID高字节 CH372V_OUT = 0x55;//itemp; CH372V_A0_LO; //A0=0数据 CH372V_WR_LO; //WR有效 _NOP();_NOP();_NOP(); CH372V_WR_HI; //WR无效 CH372V_CS_HI; //CS无效 _NOP();_NOP();_NOP(); }

//发送带有返回的单字节命令 unsigned char CH372V_SendCMD2(unsigned char Command,unsigned char Parameter) { unsigned char result; CH372V_DIR = 0xFF; CH372V_OUT = Command; //发送数据 CH372V_CS_LO; //CS有效 CH372V_A0_HI; //A0=1命令 CH372V_WR_LO; //WR有效 _NOP();_NOP();_NOP(); CH372V_WR_HI; //WR无效 _NOP();_NOP();_NOP(); CH372V_OUT = Parameter; //发送数据 CH372V_A0_LO; //A0=0命令 CH372V_WR_LO; //WR有效 _NOP();_NOP();_NOP(); CH372V_WR_HI; //WR无效 Delayt(2); CH372V_DIR = 0x00; CH372V_RD_LO; //RD有效 _NOP();_NOP();_NOP(); result = CH372V_IN; //读取数据 CH372V_RD_HI; //RD无效 CH372V_CS_HI; //CS无效 CH372V_DIR = 0xFF; return result; }

void Delayt(unsigned int dtime) { unsigned int i,j; for(j=0;j for(i=0;i<((MCLK/500)-3);i++); } }

void InitOSC(void) { //MCLK=SMLCLK=4MHz,ACLK=32768 unsigned char i,j; //设置系统时钟 BCSCTL1 = 0x00; //启动XT2晶振,ACLK为XT1(32KHz) BCSCTL2 = 0x88; //MCLK为XT2不分频;SMCLK为XT2,4MHz j=0; while(1) { IFG1 &= ~OFIFG; //清OSCFault标志 for (i=0xFF;i>0;--i); //延时等待 if ((IFG1 & OFIFG)!=0) { BCSCTL1 = 0x00; //启动XT2晶振,ACLK为XT1(32KHz) BCSCTL2 = 0X88; //MCLK为XT2不分频,SMCLK为XT2不分频 j++; //如果检测到振荡器失效,则计数 if (j>10) //如果计数值超过10次,则认为是硬件问题 ; //OSCFault(); } else { for (i=0xFF;i>0;--i); //等待振荡器达到足够的幅度 IFG1 &= ~OFIFG; //清OSCFault标志 IE1 |= OFIE + ACCVIE; //振荡器故障,FLASH非法访问中断允许 break; } } }

void CH372V_Init(void) { //首先初始化端口 CH372V_DIR |= 0xFF; CH372V_WR_HI; //WR无效 CH372V_WR_DIR |= CH372V_WR; CH372V_RD_HI; //RD无效 CH372V_RD_DIR |= CH372V_RD; CH372V_CS_HI; //CS无效 CH372V_CS_DIR |= CH372V_CS; CH372V_A0_HI; //A0=1命令 CH372V_A0_DIR |= CH372V_A0; //第一部分硬件复位 CH372V_SendCMD1(0x05); Delayt(4000); //延时40ms //第二部分设置VID和PID CH372V_SetVIDPID(); //第三部分设置USB工作模式 WatchPoint = CH372V_SendCMD2(0x15,0x02); _NOP(); //在这里加入断点观察WatchPoint }

void main(void) { unsigned char i; WDTCTL = WDTPW + WDTHOLD; P6SEL|=BIT0; ADC12CTL0 = SHT0_8 + ADC12ON+MSC; ADC12CTL1 = SHP+CONSEQ_1; ADC12MCTL0=INCH_0+EOS; ADC12IE=BIT0; //允许中断 ADC12CTL0 |= ENC; P3DIR|=0XFF; P2IE|=BIT5; P2SEL|=BIT5; P2IES|=BIT5; InitOSC(); CH372V_Init(); // CH372V_SendCMD1(0x06); //CH372V_SendData(0x55); //P3OUT=CH372V_RecData(); //CH372V_SendCMD1(0x06); //CH372V_SendData(0xaa); //P3OUT=CH372V_RecData(); _BIS_SR(GIE); while(1) { ADC12CTL0|= ADC12SC; if(k>=64) { CH372V_SendCMD1(0x2b); CH372V_SendData(64); for(i=0;i<64;i++) {//CH372V_SendData(0x01); CH372V_SendData(buffer1[i]); } } } } #pragma vector=PORT2_VECTOR __interrupt void P2ISR(void) { unsigned char status,length,i;

CH372V_SendCMD1(0X22); status=CH372V_RecData(); /*switch(status) { case 0x02: { CH372V_SendCMD1(0x28); length=CH372V_RecData(); for(i=0;ibuffer[i]=CH372V_RecData(); break; } case 0x0a:{ CH372V_SendCMD1(0x23); break; } default:{ CH372V_SendCMD1(0x23); break; } } */ if(status==0x0a) CH372V_SendCMD1(0x23); } #pragma vector=ADC_VECTOR __interrupt void ADC12_ISR (void) { ADC12CTL0&=~ENC; temp=ADC12MEM0; temp1=temp&0x0ff; temp2=(temp&0xf00)>>8; buffer1[k]=temp1; buffer1[k+1]=temp2; k++; }


#include #include "CH372V_Init_MSP430.h" unsigned char WatchPoint,itemp; unsigned char buffer[64],buffer1[64]; unsigned int k=0; unsigned char temp1,temp2; double temp; //发送单字节命令 void CH372V_SendCMD1(unsigned char Command) { CH372V_DIR = 0xFF; CH372V_OUT = Command; //发送数据 CH372V_A0_HI; //A0=1命令 CH372V_CS_LO; //CS有效 CH372V_WR_LO; //WR有效 _NOP();_NOP();_NOP(); CH372V_WR_HI; //WR无效 CH372V_CS_HI; //CS无效 } //发送单字节数据 void CH372V_SendData(unsigned char data) { CH372V_DIR = 0xFF; CH372V_OUT = data; //发送数据 CH372V_A0_LO; //A0=数 CH372V_CS_LO; //CS有效 CH372V_WR_LO; //WR有效 _NOP();_NOP();_NOP(); CH372V_WR_HI; //WR无效 CH372V_CS_HI; //CS无效 }

//接收数据 unsigned char CH372V_RecData(void) { unsigned char data; CH372V_DIR = 0x00; CH372V_A0_LO; //A0=1命令 CH372V_CS_LO; //CS有效 CH372V_RD_LO; //WR有效 _NOP();_NOP();_NOP(); data=CH372V_IN; CH372V_RD_HI; //WR无效 CH372V_CS_HI; //CS无效 _NOP(); return data; } //设置VID和PID void CH372V_SetVIDPID(void) { CH372V_DIR = 0xFF; CH372V_OUT = 0x12; CH372V_CS_LO; //CS有效 CH372V_A0_HI; //A0=1命令 CH372V_WR_LO; //WR有效 _NOP();_NOP();_NOP(); CH372V_WR_HI; //WR无效 _NOP();_NOP();_NOP();

itemp = (unsigned char)(CH372V_VID&0xff); //VID低字节 CH372V_OUT = 0x48;//itemp; CH372V_A0_LO; //A0=0数据 CH372V_WR_LO; //WR有效 _NOP();_NOP();_NOP(); CH372V_WR_HI; //WR无效 _NOP();_NOP();_NOP();

itemp = (unsigned char)((CH372V_VID>>8)&0xff); //VID高字节 CH372V_OUT = 0x43;//itemp; CH372V_A0_LO; //A0=0数据 CH372V_WR_LO; //WR有效 _NOP();_NOP();_NOP(); CH372V_WR_HI; //WR无效 _NOP();_NOP();_NOP();

itemp = (unsigned char)(CH372V_PID&0xff); //PID低字节 CH372V_OUT = 0x37;//itemp; CH372V_A0_LO; //A0=0数据 CH372V_WR_LO; //WR有效 _NOP();_NOP();_NOP(); CH372V_WR_HI; //WR无效 _NOP();_NOP();_NOP();

itemp = (unsigned char)((CH372V_PID>>8)&0xff); //PID高字节 CH372V_OUT = 0x55;//itemp; CH372V_A0_LO; //A0=0数据 CH372V_WR_LO; //WR有效 _NOP();_NOP();_NOP(); CH372V_WR_HI; //WR无效 CH372V_CS_HI; //CS无效 _NOP();_NOP();_NOP(); }

//发送带有返回的单字节命令 unsigned char CH372V_SendCMD2(unsigned char Command,unsigned char Parameter) { unsigned char result;

CH372V_DIR = 0xFF; CH372V_OUT = Command; //发送数据 CH372V_CS_LO; //CS有效 CH372V_A0_HI; //A0=1命令 CH372V_WR_LO; //WR有效 _NOP();_NOP();_NOP(); CH372V_WR_HI; //WR无效

_NOP();_NOP();_NOP();

CH372V_OUT = Parameter; //发送数据 CH372V_A0_LO; //A0=0命令 CH372V_WR_LO; //WR有效 _NOP();_NOP();_NOP(); CH372V_WR_HI; //WR无效

Delayt(2);

CH372V_DIR = 0x00; CH372V_RD_LO; //RD有效 _NOP();_NOP();_NOP(); result = CH372V_IN; //读取数据 CH372V_RD_HI; //RD无效 CH372V_CS_HI; //CS无效 CH372V_DIR = 0xFF; return result; }

void Delayt(unsigned int dtime) { unsigned int i,j; for(j=0;jfor(i=0;i<((MCLK/500)-3);i++); } }

void InitOSC(void) { //MCLK=SMLCLK=4MHz,ACLK=32768 unsigned char i,j; //设置系统时钟 BCSCTL1 = 0x00; //启动XT2晶振,ACLK为XT1(32KHz) BCSCTL2 = 0x88; //MCLK为XT2不分频;SMCLK为XT2,4MHz j=0; while(1) { IFG1 &= ~OFIFG; //清OSCFault标志 for (i=0xFF;i>0;--i); //延时等待 if ((IFG1 & OFIFG)!=0) { BCSCTL1 = 0x00; //启动XT2晶振,ACLK为XT1(32KHz) BCSCTL2 = 0X88; //MCLK为XT2不分频,SMCLK为XT2不分频 j++; //如果检测到振荡器失效,则计数 if (j>10) //如果计数值超过10次,则认为是硬件问题 ; //OSCFault(); } else { for (i=0xFF;i>0;--i); //等待振荡器达到足够的幅度 IFG1 &= ~OFIFG; //清OSCFault标志 IE1 |= OFIE + ACCVIE; //振荡器故障,FLASH非法访问中断允许 break; } } }

void CH372V_Init(void) { //首先初始化端口 CH372V_DIR |= 0xFF; CH372V_WR_HI; //WR无效 CH372V_WR_DIR |= CH372V_WR; CH372V_RD_HI; //RD无效 CH372V_RD_DIR |= CH372V_RD; CH372V_CS_HI; //CS无效 CH372V_CS_DIR |= CH372V_CS; CH372V_A0_HI; //A0=1命令 CH372V_A0_DIR |= CH372V_A0; //第一部分硬件复位 CH372V_SendCMD1(0x05); Delayt(4000); //延时40ms //第二部分设置VID和PID CH372V_SetVIDPID(); //第三部分设置USB工作模式 WatchPoint = CH372V_SendCMD2(0x15,0x02); _NOP(); //在这里加入断点观察WatchPoint }

void main(void) { unsigned char i; WDTCTL = WDTPW + WDTHOLD; P2IE|=BIT5; P2SEL|=BIT5; P2IES|=BIT5; InitOSC(); CH372V_Init(); _BIS_SR(GIE); while(1) { CH372V_SendCMD1(0x2b); CH372V_SendData(64); for(i=0;i<64;i++) { CH372V_SendData(0xff); } } } #pragma vector=PORT2_VECTOR __interrupt void P2ISR(void) { unsigned char status,length,i;

CH372V_SendCMD1(0X22); status=CH372V_RecData(); /*switch(status) { case 0x02: { CH372V_SendCMD1(0x28); length=CH372V_RecData(); for(i=0;ibuffer=CH372V_RecData(); break; } case 0x0a:{ CH372V_SendCMD1(0x23); break; } default:{ CH372V_SendCMD1(0x23); break; } } */ if(status==0x0a) CH372V_SendCMD1(0x23); }


用下面那个,上面加了ad


谢谢,麻烦你把上位机的程序也写下来,好吗,


只有登录才能回复,可以选择微信账号登录