Discussion in "PIC Microcontroller Discussion" started by    norms    Feb 16, 2008.
Sat Feb 16 2008, 02:11 pm
#1
hi i'm a newbie in this one. can anyone help me with this? i'm using miKroC for programming the microcontroller. now i want to display the readings of the micocontroller in visual basic. for example i have a voltage output 4v read by the ucontroller and want to display the digital output in visual basic... thank you very much for sparing your time...
Sat Feb 16 2008, 02:31 pm
#2
send the value to PC using UART and then display it in VB software after reading from COM port. All you need to do is COM port programming in Visual Basic (search forum for more information)
Sat Feb 16 2008, 02:51 pm
#3
this is my c program for microcontroller... any help or suggestion? it doestn have an error though

unsigned int volts_out;
unsigned int get_adc;
unsigned int x;
unsigned int norms;
unsigned int value;
unsigned int temp1;
unsigned int temp2;

void main()
{
 int exit = 1;
 Usart_Init(9600);
 ADCON0 = 0x80;
 ADCON1 = 0x80;
 ADCON0.ADON = 1; // Enables A/D Conversion
 TRISB = 0;
 PORTB = 0;
 RCSTA = 0x90;
 TXSTA = 0x24;
 Delay_ms(100);
 
 for(;;)
  {
    if(Usart_Data_Ready())
    {
      exit=1;
      PORTB=0;
      volts_out=Usart_Read();
      Delay_ms(100);
      norms = (( 2.5 *1023)/5);
      if(volts_out==norms)  // Within the 240-220 voltage range
      {
       x = volts_out * (5/1023);
        do
        {
          PORTB.F2=1;
          PORTB.F3=1;
          PORTB.F4=1;
          PORTB.F5=1;
          Delay_ms(100);
          if(Usart_Data_Ready())
          {
            exit=0;
          }
        } while(exit);
      }
      else if(volts_out>
norms) // Greater than 240 Volts
      {
        x = volts_out * (5/1023);
        do
        {
            PORTB.F2=1;
            PORTB.F3=0;
            PORTB.F4=0;
            PORTB.F5=1;
            Delay_ms(100);
            if(Usart_Data_Ready())
          {
            exit=0;
          }
        } while(exit);
      }
      else if(volts_out<norms)
      {
        x = volts_out * (5/1023);
        do
        {
          PORTB.F2=0;
          PORTB.F3=1;
          PORTB.F4=1;
          PORTB.F5=0;
          Delay_ms(100);
          if(Usart_Data_Ready())
          {
            exit=0;
          }
        }
        while(exit);
      }
      else if(volts_out==get_adc)
      {
        do
        {
          ADRESH=0;
          ADRESL=0;
          PORTB.F1=1;
          ADCON0.GO=1;
          Delay_ms(100);
          value=Adc_Read(0);
          Delay_ms(100);
          exit=0;
          temp1=ADRESH;
          temp2=ADRESL;
          Delay_ms(100);
          PORTB.F1=0;
          Delay_ms(100);
          Eeprom_Write(0,temp1);
          Delay_ms(20);
          Eeprom_Write(1,temp2);
          Delay_ms(20);
          Delay_ms(50);
          Usart_Write(Eeprom_Read(0));
          Delay_ms(20);
          Usart_Write(Eeprom_Read(1));
          Delay_ms(50);
          if(Usart_Data_Ready())
          {
            exit=0;
          }
        } while(exit);
      }
    }
    else
    {
      PORTB=0xff;
    }
  }
 
}


[ Edited Sat Feb 16 2008, 02:56 pm ]
Sat Feb 16 2008, 02:53 pm
#4
how i am going to display the read value in visual basic in digital form?
Sat Feb 16 2008, 05:50 pm
#5
how actually you are displaying your ADC output and where?

also what do you mean by digital form? can you explain with example?
Sat Feb 16 2008, 07:46 pm
#6
the x = .... is the one i will be calling in the visual basic...
i mean decimal value, sorry...
Sat Feb 16 2008, 08:18 pm
#7
consider you have value=56 in microcontroller...now convert decimal to a string. and send seriially to vb.
it that wat you want
Sat Feb 16 2008, 10:07 pm
#8


consider you have value=56 in microcontroller...now convert decimal to a string. and send seriially to vb.
it that wat you want

abbas1707




yup...

this is how i am going to convert

2.5v is the output read from a certain load then i'll convert it to decimal like this:

norms = (( 2.5 *1023)/5);

then ill have this declaration:

if (volts_out==norms)

//ill convert the decimal to a voltage value

x = (volts_out * (5))/1023 // this is the voltage that ill be calling to the visual basic program, am i right?

in vb

the value of x will be multiply to the ratio of the transformer like this

y = (x*220)/5

so y is the final value that i will like to be display in vb...

so is it ok?
Sat Feb 16 2008, 11:01 pm
#9
Do you mean something like this:
Sat Feb 16 2008, 11:40 pm
#10
yup but the voltage vill be converted to 220v from 8.7 for example. so insted of 8.7v in display it will now display 220V


[ Edited Sat Feb 16 2008, 11:43 pm ]

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Michailqfh
Fri Mar 29 2024, 01:53 am
Bobbyerilar
Thu Mar 28 2024, 08:08 am
pb58
Thu Mar 28 2024, 05:54 am
Clarazkafup
Thu Mar 28 2024, 02:24 am
Walterkic
Thu Mar 28 2024, 01:19 am
Davidusawn
Wed Mar 27 2024, 08:30 pm
Richardsop
Tue Mar 26 2024, 10:33 pm
Stevencog
Tue Mar 26 2024, 04:26 pm