Mengirim data floating point dari microcontroller ke PC

Mengirim data floating point dari microcontroller

contoh  dengan codevision:

 

Cara 1:

while (1)   //sudah terbukti :-)
{
// Place your code here
suhu=23.3*10;   // dikali 10 dulu ya

putchar(suhu/100  %10 + 0x30); //1
putchar(suhu/10   %10 + 0x30); //3
putchar(‘.’);
putchar(suhu      %10 + 0x30); //5
putchar(‘\r’);
putchar(‘\n’);
delay_ms(1000);
}

 

Cara 2:   (belum terbukti)

 

char  tx_index;

tx_buffer[50];

(float) data1 = 100,43;

(float) data2=150,76;

//masukan data float ke buffer tx_buffer
sprintf(tx_buffer," %3.2f, %3.2f \n\r",data1,data2);
UCSRB.5=1;  //aktifkan transmit interupt untuk mengirim data.

interrupt [USART_DRE] void uart_send() {

      data_char_dikirim = tx_buffer[++tx_index];

      if (data_char_dikirim == 0)
     {
      UCSRB.5=0;  // matikan UDRIE
      }

      else UDR = data_char_dikirim ;     //send the char

 }
Advertisements

About pccontrol

Berisi Tutorial Menggunakan PC untuk mengontrol Peralatan dengan cara mudah & praktis.

Posted on 30/12/2011, in Tips & Trik. Bookmark the permalink. Leave a comment.

Komentar ,Saran atau Pertanyaan

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: