使用上位机软件直接接收78M6613串口发送过来的数据,板载USB转UART的芯片,直接将该板子与PC相连,打开超级终端,可以收到该板子发送过来的数据。
一、
将该板子插到arduino板子上,并且插上液晶,接入负载和电源,arduino可以将串口接收的数据显示在液晶屏上。
测试代码:
#include<LiquidCrystal.h>
//LCD RS->A5
//LCD EN->A4
//LCD D4->D7
//LCD D5->D6
//LCD D6->D5
//LCD D7->D4
LiquidCrystallcd(A5,A4,7,6,5,4);
bytedata[28]={0};
byte number=0;
byteslow[8]={0x5D,0x31,0x38,0x3D,0x2B,0x33,0x30,0x0D};
unsigned longvoltage;
unsigned longcurrent;
unsigned longpower;
unsigned longfactor;
unsigned longfrequence;
void setup()
{
pinMode(A1, INPUT); //KEY
pinMode(A2, INPUT); //KEY
pinMode(A3, OUTPUT); //CONTRAL
lcd.begin(16,2);
Serial.begin(38400);
Serial.write(26);
delay(100);
Serial.write(slow,8);
delay(100);
Serial.write(26);
delay(100);
}
void loop()
{
if(!digitalRead(A1))
digitalWrite(A3, LOW);
else if(!digitalRead(A2))
digitalWrite(A3, HIGH);
///////////////////////////////////////////
while(1)
{
if(Serial.read()==0x0A)
break;
}
for(number=0;number<28;number++)
{
while(!(Serial.available() > 0));
data[number]=Serial.read();
}
lcd.clear();
lcd.setCursor(0,0);
number=0;
lcd.print("V:");
while(data[number]!=0x09)
//voltage
{
lcd.write(data[number]);
number++;
}
number++;
lcd.print("I:");
while(data[number]!=0x09)
//current
{
lcd.write(data[number]);
number++;
}
lcd.setCursor(0,1);
number++;
lcd.print("P:");
while(data[number]!=0x09)
//power
{
lcd.write(data[number]);
number++;
}
number++;
while(data[number++]!=0x09);
//factor
lcd.print("F:");
while(data[number]!=0x20)
//frequence
{
lcd.write(data[number]);
number++;
}
////////////////////////////////////////////////////////
完整的文件见附件。
}
|