"Orang berilmu binasa kecuali orang yang mengamalkan ilmunya. Orang yang mengamalkan ilmunya binasa kecuali orang yang ikhlas". (Ibnu Qudamah)

Selasa, 13 Januari 2015

Akses USART ATmega 8535 Menggunakan CV AVR 2.05.3



Rangkaian pada Proteus 7.10 SP0

Membuat project. File, New, Project, Oke. Kemudian memilih Chip ATmega 8535.
Mengatur konfigurasi sebagai berikut yaitu konfigurasi CHIP, PORT dan USART. 

Sesuaikan clock dengan clock hardware yang anda buat. Usahakan clocknya yang errornya = 0.
 Pemilihan clock yang paling baik antara 11.0592 MHz dan 14.7456 MHz.


Konfigurasi PORTA sebagai keluaran

Konfigurasu USART

Klik icon gear, Generate program, save and exit. Kemudian beri nama, misalkan usart.







Kemudian muncul lembar kerja program.
Berikut ini contoh program USART.

/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.3 Standard
Automatic Program Generator
© Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project :USART
Version : 1
Date    : 1/13/2015
Author  : share-ilmu-ilmu
Company : share-ilmu-ilmu.blogspot.com
Comments:


Chip type               : ATmega8535
Program type            : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 128
*****************************************************/

#include <mega8535.h>

// Standard Input/Output functions
#include <stdio.h>
// Declare your global variables here

void main(void)
{
// Declare your local variables here

// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=Out Func0=Out
// State7=T State6=T State5=T State4=T State3=T State2=T State1=1 State0=1
PORTA=0x03;
DDRA=0x03;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;

// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 9600
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x33;

while (1)
{
    // Place your code here
    if (getchar()=='a')    //jika tombol keyboard a ditekan
    {
 PORTA=0x02;            //aktifkan led 1
 putchar('a');          //kirim huruf a pada komputer
    }                                                      
    else if(getchar()=='b') //jika tombol keyboard b ditekan
    {
 PORTA=0x00;            //aktifkan led 1 dan 2
 putchar('b');          //kirim huruf b pada komputer
    }                                                      
    else
    {
 PORTA=0x03;            //matikan 1 dan 2
 putchar('?');          //kirim huruf ? pada komputer
    }
}
}


Hasilnya seperti berikut ini.
Ketika ditekan tombol a pada terminal. LED1 aktif dan LED 2 mati.


Ketika ditekan tombol b pada terminal. LED1 dan LED 2 aktif.

Ketika ditekan selain tombol a dan b pada terminal. LED1 dan LED 2 mati.
 


Sekian pembahasan USART ini.
Terima kasih atas perhatiannya.
Semoga bermanfaat.

Tidak ada komentar: