Coding dengan CVAVR :
//------------------------------------------------------
//Program rutin interupsi eksternal 0
//------------------------------------------------------
//------------------------------------------------------
//EKLARASI HEADER
//------------------------------------------------------
#include <mega16.h>
#include <delay.h>
#include <stdio.h>
//------------------------------------------------------
//EKLARASI VARIABEL
//------------------------------------------------------
unsigned char dt=0x01;
//------------------------------------------------------
//DEKLARASI SUB RUTIN
//------------------------------------------------------
void InisialisasiINT0();
//------------------------------------------------------
//PROGRAM UTAMA
//------------------------------------------------------
void main (void)
{
DDRA=0xff; InisialisasiINT0();
#asm ("sei");
while(1)
{
PORTA=dt;
delay_ms(100);
dt=dt<<1;
if (dt==0) {dt=0x01;}
}
}
//------------------------------------------------------
//SUB RUTIN INTERUPSI EXTERNAL0
//------------------------------------------------------
interrupt [EXT_INT0] void ext_int0_isr(void)
{
unsigned char rr=0;
while (rr<5)
{
PORTA=0x0f;
delay_ms(5);
PORTA=0xf0;
delay_ms(5);
++rr;
}
}
//------------------------------------------------------
//SUB RUTIN INISIALISASI INTERUPSI EXTERNAL0
//------------------------------------------------------
void InisialisasiINT0 ()
{
GICR|=0x80;
MCUCR=0x0C;
MCUCSR=0x00;
GIFR=0x80;
}
by : Siagian.P
Reff : Atmel.com
· Warnock, Ian G., Programmable Controllers. Prentice-Hall, 1988.
No comments:
Post a Comment