Contoh Pemrograman Serial dengan AVR studio

 
/*
 * AVRGCC5.c
 *
 * Created: 5/9/2011 9:25:11 AM
 *  Author: pccontrol
Xtal = 8 Mhz , baud rate = 9600 bps , data = 8 bit
 */ 

#include <avr/io.h>

void inisialisasi_UART (void)
{
UCSRB = (1<<TXEN);
UCSRC = (1<<UCSZ1) | (1<<UCSZ0) | ( 1<<URSEL);
UBRRL =0x33;
}

void kirim_data (char huruf)
{
while(! (UCSRA & (1<<UDRE) ));
UDR = huruf;
}

int main(void)
{
	inisialisasi_UART();

    while(1)
    {
        //TODO:: Please write your application code
    kirim_data('a');
    }

return 0;
}

Menghitung nilai UBRR

Rumus mencari : baudrate = ( Freq_xtal / 16(UBRR+1) )

nilai baudrate yang kita inginkan tergantung Frekwensi Xtal dan nilai register UBRR.
jika kita tahu nilai Xtal dan baudrate yang kita nginkan maka nilai UBRR yg mesti
kita cari dengan rumus sbb:
UBRR =(Freq_Xtal/(16(baudrate)))-1.

jadi jika diketahui nilai Frekwensi Xtal = 8 Mhz dan baudrate 9600 maka
UBBR =(8000000/(16(9600)))-1 =51,08 = 51 (desimal) atau 33 hexa.

Advertisements

About pccontrol

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

Posted on 05/09/2011, in Pemrograman C AVR Studio. 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: