Home >Documents >MIKROKONTROLER ATMEGA BERBASIS CODEVISION AVR (SERIAL · PDF fileTeori U(S)ART U(S)ART =...

MIKROKONTROLER ATMEGA BERBASIS CODEVISION AVR (SERIAL · PDF fileTeori U(S)ART U(S)ART =...

Date post:10-Jun-2019
Category:
View:218 times
Download:0 times
Share this document with a friend
Transcript:

MIKROKONTROLER ATMEGA BERBASIS

CODEVISION AVR(SERIAL U(S)ART)

D E P O K I N S T R U M E N T S dins

Teori U(S)ART

U(S)ART = Universal (Syncronous) Asyncronous Rx Txadalah standar komunikasi serial

Serial vs Parallel:

Fitur U(S)ART C. ATmega16A

PIND.0 = RXD PORTD.1 = TXD RS232 = Protokol standar tegangan untuk komunikasi

berjarak sedang. USB TO RS232 = Konverter komunikasi USB ke RS232.

DI-Smart AVR.16 System(Sistem Plus C. ATmega16A)

Y111059200

C1

20pFC2

20pF

R1

1K

SW1RST

VCCX1

X2RST

RST

PB0PB1PB2PB3PB4PB5PB6PB7

PA0PA1PA2PA3PA4PA5PA6PA7

PD0PD1PD2PD3PD4PD5PD6PD7 PC0

PC1PC2PC3PC4PC5PC6PC7

X1X2

12345678910

P1PORTB

12345678910

P3PORTD

12345678910

P0PORTA

12345678910

P2PORTC

VCC

VCCVCC

VCC PB0PB1PB2PB3PB4PB5PB6PB7

PA0PA1PA2PA3PA4PA5PA6PA7

PC0PC1PC2PC3PC4PC5PC6PC7R1 IN

13R2 IN8T1 IN11

T2 IN10

GN

D15

V+

2

V-

6

VCC

16

R1 OUT 12R2 OUT 9T1 OUT 14

T2 OUT 7C1+1C1 -3

C2+ 4C2 - 5

U2

MAX232CPE

+

C91uF

+

C131uF

+

C111uF

+

C101uF

VCC

162738495

DB1SERIAL

+C4470uF

Vin1

GN

D2

+5V 3U0 LM7805CT

+ C510uF

+ C6100nF

C7100nF

VCCD14002

C3

100nf

R3

2K2L10POWER

VCC

VCC

11

23

W 2

VR1

10K

AREF

AREF

VCC

PD0PD1PD2PD3PD4PD5PD6PD7

AGND 31X113X212

RESET9

PD2 (INT0)16

PD3 (INT1)17PD4 (OC1B)18PD5 (OC1A)19

PB0 (T0)1

PB1 (T1)2PB2 (AIN0)3PB3 (AIN1)4

PB4 (SS)5

PB5 (MOSI)6PB6 (MISO)7

PB7 (SCK)8

PA0 (ADC0) 40

PA1 (ADC1) 39PA2 (ADC2) 38PA3 (ADC3) 37

PA4 (ADC4) 36

PA5 (ADC5) 35PA6 (ADC6) 34

PA7 (ADC7) 33

PC0 22PC1 23PC2 24PC3 25PC4 26PC5 27

(TOSC1) PC6 28(TOSC2) PC7 29

PD7 (OC2)21PD6 (ICP)20

AREF 32

AVCC 30

PD1 (TDX)15PD0 (RXD)14

IC1 AT MEGA

PB5

PB6PB7

VCC

LEDRST

1 23 45 67 89 10

P4ISP PROG

S2

PD2

S3

PD3

PD2

PD3

L8PC0

VCC

L7PC1

L6PC2

L5PC3

L4PC4

L3PC5

L2PC6

L1PC7

PC0

PC1

PC2

PC3

PC4

PC5

PC6

PC7

C17100nF

D0D1D2D3D4

D6D5

D7

D0

D1

D2

D3

D4

D6

D5

D7

PD0 PD1TXD SERIAL

TXD ISP

RXD SERIAL

RXD ISP

+ C121uF

123

JP1123

JP2

123456789

RP1

12

JP3LED CONNECTED

TXD ISPRXD ISP

TXD SERIAL

RXD SERIAL

POWER9-12VDC

1

2 34

56

7

8

9

DI-Smart AVR.16 System

1. ATmega16A2. Crystal3. Reset4. ISP5. Power6. Vref ADC7. RS2328. LED Array9. Push Button

1

2

34

56

8

7

9

Serial RS232

PD0=RXPD1=TX

Pemrograman U(S)ART pada CVAVR

Inisialisasi WizardAktivasi ReceiverAktivasi TransmitterPemilihan Baud Rate yang akan digunakanPemilihan Communication ParametersMode Serial

Pemrograman U(S)ART(Setup Wizard)

1

3

2

Inisialisasi USART sesuai dengan yang diinputkan saat Wizard.

Pemrograman U(S)ART(Inisialisasi U(S)ART Hasil Wizard)

Pemrograman U(S)ART(Sintaks Program U(S)ART - RX)

getchar(void); //Membaca buffer serial penerima. unsigned char char_data;

void main(void) {char_data = getchar()}

scanf(char flash *fmtstr,...); //Membaca buffer serial penerima. unsigned char char_data;

void main(void) {scanf("%d",&char_data);}

char_data = Alamat di RAM yang dialokasikan untuk menyimpan data sementara.

Pemrograman U(S)ART(Sintaks Program U(S)ART - TX)

putchar([char]); //= Put Char-Byte (0-255). putchar(A); //= putchar(0x41)

putsf([string]); //= Put String on Flash. putsf(-SELAMAT DATANG-);

puts([*RAM]); // Lihat berikutnya. printf([char flash *fmtstr [ , arg1, arg2, ...]]); //Lihat berikutnya.

Pemrograman U(S)ART (Sintaks sprintf)

sprintf([char *str, char flash *fmtstr [ , arg1, arg2, ...]]); #include //Library serial dan konversi karakter

unsigned char cdata=0, cstr[16];

void main(void)

{

sprintf(cstr,"Nilai Data: %04d",cdata++); puts(cstr);

}

cdata = Alamat di RAM yang dialokasikan untuk menyimpan data sementara.

cstr[16] = Alamat di RAM yang tersusun secara berurutan yang dialokasikan sebagai hasil konversi dari sintaks sprintf.

%d = Decimal; %x = Hexadesimal; %c = Character; %s = Strings

Pemrograman U(S)ART (Sintaks printf)

printf([char flash *fmtstr [ , arg1, arg2, ...]]); #include //Library serial dan konversi karakter

unsigned char cdata=0, cstr[16];

void main(void)

{

Printf("Nilai Data: %04d",cdata++); }

cdata = Alamat di RAM yang dialokasikan untuk menyimpan data sementara.

cstr[16] = Alamat di RAM yang tersusun secara berurutan yang dialokasikan sebagai hasil konversi dari sintaks sprintf.

%d = Decimal; %x = Hexadesimal; %c = Character; %s = Strings

#include

#include

unsigned char char_data;

void main(void)

{

// USART initialization

// 8D-1S-NoParity; RX: On; TX: On; Async; 9600 BPS

UCSRA=0x00; UCSRB=0x18; UCSRC=0x86;

UBRRH=0x00; UBRRL=0x47;

while (1) {

char_data = getchar(); //Receive

putchar(char_data); //Transmit

}

}

Pemrograman U(S)ART (Echo)

LM35DZ adalah sensor temperatur analog ekonomis namun cukup baik dalam mengukur temperatur. Jangkauan: 0 100 oCSensitivitas: 10 mV/ oCOperasional: 4 30 V

Aplikasi U(S)ARTData Logger Temperatur berbasis LM35DZ

Fungsi Transfer Sensor LM35DZ

Tinjau-ulang dasar ADC:Data_ADC = (Vin/Vref)*(Maksimal_Data_Bit)Data_ADC = Hasil konversi ADC internal ATmega16AVin = Tegangan LM35Vref = Sesuai pengaturan di Wizard CVAVR = 5VMaksimal_Data_Bit = 10 Bit = 1023

Sensitivitas LM35 = 10 mV/ oC Temperatur terukur (T):

T = (Vin/10 mV) oC T = ((Data_ADC*5V/1023)/10 mV) oC

Data Logger Temperatur berbasis LM35DZ (Setup Wizard) [1/2]

1 2

Data Logger Temperatur berbasis LM35DZ (Setup Wizard) [2/2]

4

5

3

Data Logger berbasis Sensor LM35DZ(Skrip Program CVAVR) [1/3]

#include

#include

#include

#define ADC_VREF_TYPE 0x00

unsigned int read_adc(unsigned char adc_input)

{

ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);

delay_us(10);

ADCSRA|=0x40;

while ((ADCSRA & 0x10)==0);

ADCSRA|=0x10;

return ADCW;

}

Data Logger berbasis Sensor LM35DZ(Skrip Program CVAVR) [2/3]

unsigned char T; //T = Temperatur

unsigned int idata;

float fdata; //Nilai pecahan agar perhitungan baik.

void main(void)

{

UCSRA=0x00; UCSRB=0x18; UCSRC=0x86;

UBRRH=0x00; UBRRL=0x47;

ADMUX=ADC_VREF_TYPE & 0xff; ADCSRA=0xA6; SFIOR&=0x1F;

while (1) {

idata = read_adc(0);

Printf("Data ADC: %04d",idata);

Data Logger berbasis Sensor LM35DZ(Skrip Program CVAVR) [3/3]

fdata = (((float)idata*5)/1023)/0.01;

T = (char)fdata;

Printf("Temperatur: %02d C",T);

delay_ms(250); }

}

E-BOOK DINS

http://depokinstruments.com/category/3-e-book/

http://depokinstruments.com/category/3-e-book/

Click here to load reader

Reader Image
Embed Size (px)
Recommended