pic16f877 and vb6

Discussion in 'Embedded Systems and Microcontrollers' started by mikecy, May 14, 2010.

  1. mikecy

    Thread Starter New Member

    Apr 28, 2010
    8
    0
    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
    Code ( (Unknown Language)):
    1. while(TRUE){
    2.   set_adc_channel(0);
    3.   delay_ms(10);
    4. binary0=read_adc();
    5. value0=(((float)binary0/1023)*(5));
    6. printf("1");
    7. printf("%2.3f",value0);
    8. delay_ms(200);
    9. set_adc_channel(1);
    10. delay_ms(10);
    11. binary1=read_adc();
    12. value1=((float)binary1/1023)*(5);
    13. printf ("2");
    14. printf ("%2.3f",value1);
    15. delay_ms(200);
    16.  
    17. set_adc_channel(2);
    18.   delay_ms(10);
    19. binary2=read_adc();
    20. value2=(((float)binary2/1023)*(5));
    21. printf("3");
    22. printf("%2.3f",value2);
    23. delay_ms(200);
    24.  
    25. }
    26.  
    VB6 program
    Code ( (Unknown Language)):
    1.  
    2. i = MS1.Input
    3. If i = 1 Then
    4. MS1.InputLen = 5
    5. btr = 5
    6. Do
    7. DoEvents
    8. Loop Until MS1.InBufferCount >= btr
    9. datain = MS1.Input
    10. Label1.Caption = datain & "V"
    11. MS1.InputLen = 1
    12. End If
    13. If i = 2 Then
    14. MS1.InputLen = 5
    15. btr = 5
    16. Do
    17. DoEvents
    18. Loop Until MS1.InBufferCount >= btr
    19. datain = MS1.Input
    20. Label3.Caption = datain & "V"
    21. MS1.InputLen = 1
    22. End If
    23. If i = 3 Then
    24. MS1.InputLen = 5
    25. btr = 5
    26. Do
    27. DoEvents
    28. Loop Until MS1.InBufferCount >= btr
    29. datain = MS1.Input
    30. Label4.Caption = datain & "V"
    31. MS1.InputLen = 1
    32. End If
     
  2. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    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.
     
  3. mikecy

    Thread Starter New Member

    Apr 28, 2010
    8
    0
    I didn know that.I will keep it in mind
     
  4. mikecy

    Thread Starter New Member

    Apr 28, 2010
    8
    0
    Anything else?My main concern is how vb reads the data.Is that the correct way?
     
  5. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    Windows will not let you access the port directly. Are you using the proper dll's to engage the port access?
     
  6. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234

    the OP is using the mscomm control....;)
     
  7. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    .....I guess I should have looked further into the code than the PIC code.

    HEY there it is MS1.input..

    My bad.
     
Loading...