pic16f877 and vb6

Thread Starter

mikecy

Joined Apr 28, 2010
8
Hello guys.My project purpose was to measure voltages and show it through pc with visual basic 6.I finished it, it works fine but the way i did it seems wrong and complicated.Any suggestion to improve my code and learn more?
pic programm
Rich (BB code):
while(TRUE){
  set_adc_channel(0);
  delay_ms(10);
binary0=read_adc();
value0=(((float)binary0/1023)*(5));
printf("1");
printf("%2.3f",value0);
delay_ms(200);
set_adc_channel(1);
delay_ms(10);
binary1=read_adc();
value1=((float)binary1/1023)*(5);
printf ("2");
printf ("%2.3f",value1);
delay_ms(200);

set_adc_channel(2);
  delay_ms(10);
binary2=read_adc();
value2=(((float)binary2/1023)*(5));
printf("3");
printf("%2.3f",value2);
delay_ms(200);

}
VB6 program
Rich (BB code):
i = MS1.Input
If i = 1 Then
MS1.InputLen = 5
btr = 5
Do
DoEvents
Loop Until MS1.InBufferCount >= btr
datain = MS1.Input
Label1.Caption = datain & "V"
MS1.InputLen = 1
End If
If i = 2 Then
MS1.InputLen = 5
btr = 5
Do
DoEvents
Loop Until MS1.InBufferCount >= btr
datain = MS1.Input
Label3.Caption = datain & "V"
MS1.InputLen = 1
End If
If i = 3 Then
MS1.InputLen = 5
btr = 5
Do
DoEvents
Loop Until MS1.InBufferCount >= btr
datain = MS1.Input
Label4.Caption = datain & "V"
MS1.InputLen = 1
End If
 

AlexR

Joined Jan 16, 2008
732
This may not teach you anything more about programming the PIC but to my mind is the logical way to do it.
Doing floating point calculations in a PIC is very resource intensive and should be avoided if at all possible. Since you are already using the PC to display the data why not use it to do the calculations as well. Just have the PIC pass the raw AtoD values to the PC and then let the PC do all the hard word.
 
Top