contoh program avr
-
Upload
dwi-hermawan -
Category
Education
-
view
48 -
download
2
Transcript of contoh program avr
#include <mega16.h>#include <stdio.h>#include <stdlib.h>#include <delay.h>
// Alphanumeric LCD Module functions#asm .equ __lcd_port=0x18 ;PORTB#endasm#include <lcd.h>
unsigned char indeks=0;char temp1[16],temp2[16],temp3[16],temp4[16];unsigned char count;float waktu1,waktu2,percepatan,kecepatan,x;
// Timer 0 overflow interrupt service routineinterrupt [TIM0_OVF] void timer0_ovf_isr(void){TCNT0=0x8A;count++;}
void cepat1(){ percepatan=0.8/(0.5*(waktu1*waktu1)); lcd_gotoxy(2,1); ftoa(percepatan,2,temp1); lcd_puts(temp1);}
void cepat2(){ kecepatan=0.2/waktu2; lcd_gotoxy(12,1); ftoa(kecepatan,2,temp2); lcd_puts(temp2); }
void tampil_lcd1(){ waktu1=((float)count)/10; lcd_gotoxy(3,0); ftoa(waktu1,2,temp3); lcd_puts(temp3); }
void detek_tombol(){if (PINA.0==1 && (indeks==0 || indeks==2))//start timer { indeks=1; TIMSK=0x01;//memulai timer lcd_clear(); } if (PINA.1==1 && indeks==1)//stop timer { indeks=2; TIMSK=0x00;//menstop timer tampil_lcd1(); cepat1(); TIMSK=0x01; } if (PINA.2==1 && indeks==2)//reset timer { indeks=0;//semua data direset TIMSK=0x00;//menstop timer cepat2(); }}
void tampil_lcd2(){ lcd_gotoxy(0,0); lcd_putsf("t1="); lcd_gotoxy(0,1); lcd_putsf("a="); lcd_gotoxy(8,1); lcd_putsf("v="); lcd_gotoxy(8,0); lcd_putsf("t2="); x=((float)count)/10; waktu2=x-waktu1; lcd_gotoxy(12,0); ftoa(waktu2,2,temp4); lcd_puts(temp4); }
void main(void){PORTA=0x00;DDRA=0x00;
// Timer/Counter 0 initialization// Clock source: System Clock// Clock value: 11.719 kHz// Mode: Normal top=FFh// OC0 output: DisconnectedTCCR0=0x05;TCNT0=0x8A;OCR0=0x00;
// Analog Comparator initialization// Analog Comparator: Off// Analog Comparator Input Capture by Timer/Counter 1: OffACSR=0x80;SFIOR=0x00;
// LCD module initializationlcd_init(16);
// Global enable interrupts#asm("sei")
lcd_gotoxy(0,0);lcd_putsf("Lab. Fisika");lcd_gotoxy(0,1);lcd_putsf("FKIP-UNTAD");delay_ms(100);lcd_clear();lcd_gotoxy(0,0);lcd_putsf("Pesawat");lcd_gotoxy(0,1);lcd_putsf("Atwood");delay_ms(100);lcd_clear();
while (1) { detek_tombol(); tampil_lcd2(); };}