1 / 22

Bahasa c untuk pemrogramman avr

Bahasa c untuk pemrogramman avr. Sistem mikroprosessor – by rizal suryana. Alat Bantu. Applikasi + Compiler = CodeVision AVR Proteus. Tipe Data. Pendefinisian Variabel. Mengacu pada type data. Type_data nama variabel Unsigned int data; Unsigned int DATA; Data equ 23H.

long
Download Presentation

Bahasa c untuk pemrogramman avr

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Bahasa c untukpemrogrammanavr Sistemmikroprosessor – by rizalsuryana

  2. Alat Bantu • Applikasi + Compiler = CodeVision AVR • Proteus

  3. Tipe Data

  4. PendefinisianVariabel • Mengacupada type data. • Type_datanamavariabel • Unsigned int data; • Unsigned int DATA; • Data equ 23H

  5. Konstanta • Sebuahvariabel yang nilainyatetap • const int b=1234 • constint pi=3.14

  6. OPERATOR • Aritmatika • *, +, -, /, %, ++, -- • Logika • &&, ||, • Pembanding • >,<,==,=>,=<,!= • Shift • >>,<<,>>=,<<= • Bitwise • &, |, ~,^,! • Compound Assignment • +=,-=,*=,/=,%=,&=,^=

  7. Operator Aritmatika • C = b + a • D = c – a • A = c * d • B = d / a • Ab = a%c

  8. Operator Logika • && • a == b && c >d • || • c > d || d < a

  9. Operator Pembanding • 4 > 2 • 3 < 10 • 4 >= 2 • 5 == 5, A = 12 • 10 <= 12 • 7 != 5

  10. Operator Shift • 2 >> • 3<< • 2>>=2 • 3<<=4

  11. Operator Bitwise • 25H & 12H • 09H | 2AH • ! 1H • ~ 25H • 07H ^ 2H

  12. Operator Compound Assignment • A+=3 • A-=3 • A*=3 • A/=3 • A%=3 • A = A + 3 • A = A – 3 • A = A * 3 • A = A / 3 • A = A % 3

  13. Function • Merupakansuatusubroutin program • intalfa(char par1, int par2, long par3) { /* Write some statements here */} • Running_led () { Please code here } • Void lcd_Clear (void) { /write code here } • Pemanggilan function • lcd_Claer( ) ;

  14. Void Hitung_delay(int a, char f){ • c= d+a; • H = c * f; • } • Hitung_delay (nilaiA, waktu)

  15. Komentar • // untuksatubarisperintah • /* */ untukbanyakperintahbaris /* PORTA=25; */

  16. Akses Port I/O • DDRx Menentukanfungsidari I/O • PORTX AKSES I/O • Akses PORT sebagai Output menggunakanvariabel PORT (PORTC=25, PORTC.1=1) • Akses PORT sebagai INPUT menggunakan Variable PINx.Contoh • If (PINA.1==0){ //write code here dataPortA = PINA dataBitPortD = PIND.7 }

  17. Percabangan • If • If … else • If … else if … else • while • Do … while • for • Switch () { • Case : }

  18. Percabangan IF • If (PINA.1==0){ PORTC=255; Hitung_delay(); } • If (PINA == 100){ PORTC.2=1 } Else if (PINA == 50) { PORTC.2=0 } Looping : • If (PINA.1 == 0){ PORTC.2=1 } Else if (PINA.1==1) { PORTC.2=0 } Else if (PINA.2==0) } PORTB==0 }

  19. Percabangan while dan do … while • While(NilaiA==10) { PORTA=100; } • NilaiA=1; Do { PORTC=I; i++; NilaiA++; }while(NilaiA<10)

  20. Percabangan for • for (i=10;i==50;i++;){ printf("%d\r\n",data_ori); delay_ms(100); }

  21. PercabanganSwitch • inputan=1; • switch(inputan){ case ‘5' : data_ori = read_adc(1); printf("%d\r\n",data_ori); delay_ms(100); case ‘1' : data_ori = read_adc(1); printf("%d\r\n",data_ori); delay_ms(100); case ‘2' : data_ori = read_adc(1); printf("%d\r\n",data_ori); delay_ms(100); }

More Related