Anda di halaman 1dari 6

PERCOBAAN 1

Membuat pewaktuan dengan menggunakan fungsi file delay.h


#include <mega128.h>
#include <delay.h>
// Declare your global variables here
void main(void)
{
PORTA=0x00;
DDRA=0xFF;
while (1)
{
PORTA.0=1;
delay_ms(500);
PORTA.0=0;
delay_ms(500);
}
}

Hasil Simulasi dengan menggunakan Proteus ( ISIS )

LED akan menyala selama 500 ms kemudian mati selama 500 ms juga secara bergantian

PERCOBAAN 2
Membuat pewaktuan dengan menggunakan fungsi timer/counter
#include <mega128.h>
bit a;
// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
TCNT0=0xFF;
if(a==1)
{
PORTA.0=1;
a=0;
}
else
{
PORTA.0=0;
a=1;
}
}

void main(void)
{
PORTA=0x00;
DDRA=0xFF;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 31.250 kHz
// Mode: Normal top=0xFF
// OC0 output: Disconnected
ASSR=0x00;
TCCR0=0x06;
TCNT0=0x00;
OCR0=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x01;
ETIMSK=0x00;
// Global enable interrupts
#asm("sei")
while (1)
{
// Place your code here
}
}

Hasil Simulasi dengan menggunakan Proteus ( ISIS )

_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________

PERCOBAAN 3
Membuat gelombang kotak dengan duty cycle 50% menggunakan fungsi delay. Untuk
Output non PWM
#include <mega128.h>
#include <delay.h>
void main(void)
{
PORTB=0x00;
DDRB=0xFF;
while (1)
{
PORTB.4=1;
delay_ms(10);
PORTB.4=0;
delay_ms(10);
}
}

Hasil Simulasi dengan menggunakan Proteus ( ISIS )

Lampu berkedip bergantian 10 ms

Bentuk Gelombang pada oscilloscope

_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________

PERCOBAAN 4
Membuat gelombang kotak dengan duty cycle 50% menggunakan fungsi delay. Untuk
Output PWM
#include <mega128.h>
void main(void)
{
PORTB=0x00;
DDRB=0xFF;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 7.813 kHz
// Mode: Phase correct PWM top=0xFF
// OC0 output: Non-Inverted PWM
ASSR=0x00;
TCCR0=0x67;
TCNT0=0x00;
OCR0=0x00;

while (1)
{
OCR0=0x80;
}
}

Hasil Simulasi dengan menggunakan Proteus ( ISIS )

Lampu berkedip bergantian

Bentuk Gelombang pada oscilloscope

_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________

_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________

Kesimpulan
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________

Anda mungkin juga menyukai