Microchip
直播中

李艺银

8年用户 1160经验值
私信 关注
[问答]

与uart通信的dspic

大家好,我想做一个简单的项目,用dSPIC30F2010测量12V电池电压,测量值通过UART端口发送。但是我没有得到确切的值。这里是我的MikROC代码,用于未签名的ADC^值;Char伏(4);空隙主(){PtURB= 0x000;TrISB.F1=1;//集。引脚作为ADC工作ADC1In()的输入;DelayIMS(1000);UART1OIIIT(9600);//初始化UART模块在9600 BPS DelayIMS(100);/ /等待UART模块稳定(1){AdCyVald= ADC1GETGHYLASH采样(1);ADCQUAL=ADCQUION/1023*17.4;ItoTSTR(ADCl值,Volt);/ /转换电压到ST环UART1X写文本(Volt);DelayIMS(100);}我做错了什么。请帮助我一些人。谢谢。

以上来自于百度翻译


      以下为原文

    hello everyone
i try to to make a simple project that is am measuring 12v battery voltage with dspic30f2010 and the measured value send through uart port.but i didn't get the exact value
here is my mikroc code for that

unsigned adc_value;
char volt[4];

void main() {
  PORTB = 0x0000;
  TRISB.F1 = 1;       // set pin as input - needed for ADC to work
  ADC1_Init();
  Delay_ms(1000);
  UART1_Init(9600); // Initialize UART module at 9600bps
  Delay_ms(100); // Wait for UART module to stabilize

  while(1)
  {
    adc_value= ADC1_Get_Sample(1);
    adc_value = adc_value/1023*17.4;
    inttostr(adc_value,volt);    // Convert voltage to string
    UART1_Write_Text(volt);
    Delay_ms(100);
  }
}

what i done wrong.please help me somebody.
thank u

回帖(2)

吴键洪

2018-9-5 16:39:06
你得到了什么?当你寻求帮助时,总是很好地揭示你实际得到的和你期望得到的。我猜“/1023”部分是问题所在,但我只能猜测如果你没有指出你得到的结果。

以上来自于百度翻译


      以下为原文

   
What did you get?
When asking for help, it's always a good idea to reveal what you actually got, and what you expected to get.
I'm guessing the "/1023" part is the problem, but I can only guess if you don't indicate what results you got.
 
举报

叶冬琳

2018-9-5 16:44:41
这是PIC I与NoDeMuCu(ESP8266)集成,并在串行监视器中显示结果。它的显示是255,但我的要求是电池的电压率,这是我的NoDECU-UART接收器程序,包括:L&StaseStudio.H&G.ValueStUpUP(){SINK(开始)(9600);/*定义串行通信的波特率*/}无效环(){INTION='0';IF(Sturial.Access()){{/*如果数据I在串行端口*/Stay.PrimTLN(“连接”)上可用;延迟(1000);接收=串行。();串行打印。(接收);/*打印字符被接收到串行监视器/串行。打印(“V”);延迟(1000);} {串行。打印(“未连接”);延迟(1000);}请帮助我。

以上来自于百度翻译


      以下为原文

    sorry
this pic i integrated with nodemcu(esp8266) and showing result in serial monitor.and the value is not what i expected. its showing 255 but my requirement is the voltage rate of battery that is 12.
here is my nodemcu uart receiver program
 
 
#include
void setup() {
 Serial.begin(9600);  /* Define baud rate for serial communication */
 
}

void loop() {
int received='0';
 
 if(Serial.available()){  /* If data is available on serial port */

    
    Serial.println("CONNECTED");
    delay(1000);
    received=Serial.read();
    Serial.print(received); /* Print character received on to the serial monitor */
     Serial.println("v");
    delay(1000);
    
  }
else{
  Serial.println("not connected");
  delay(1000);
}
}


please help me.
举报

更多回帖

发帖
×
20
完善资料,
赚取积分