100% found this document useful (1 vote)
119 views

Kode Program

This document contains several experiments related to controlling LEDs and displaying data on a port using an ATmega16 microcontroller. Experiment 1 blinks individual LEDs on ports C and D. Experiment 2 displays numeric patterns on ports A and B. Experiment 3 scrolls a numeric pattern on port A. Experiment 4 synchronously controls LEDs on ports A, B and D using delay.

Uploaded by

Haris Hunafa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
119 views

Kode Program

This document contains several experiments related to controlling LEDs and displaying data on a port using an ATmega16 microcontroller. Experiment 1 blinks individual LEDs on ports C and D. Experiment 2 displays numeric patterns on ports A and B. Experiment 3 scrolls a numeric pattern on port A. Experiment 4 synchronously controls LEDs on ports A, B and D using delay.

Uploaded by

Haris Hunafa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

PERCOBAAN 1

/*****************************************************

Chip type : ATmega16


Program type : Application
AVR Core Clock frequency : 12.000000 MHz
Memory model : Small
External RAM size :0
Data Stack size : 256

*****************************************************/

#include <mega16.h>
#include <delay.h>

void main(void)
{

PORTC=0x00;
DDRC=0xFF;
PORTD=0x00;
DDRD=0xFF;

while (1)
{
PORTC=0x01;
delay_ms(200);
PORTC=0x02;
delay_ms(200);
PORTC=0x04;
delay_ms(200);
PORTC=0x08;
delay_ms(200);
PORTC=0x10;
delay_ms(200);
PORTC=0x20;
delay_ms(200);
PORTC=0x40;
delay_ms(200);
PORTC=0x80;
delay_ms(200);
PORTD=0x01;
delay_ms(200);
PORTD=0x02;
delay_ms(200);
PORTD=0x04;
delay_ms(200);
PORTD=0x08;
delay_ms(200);
PORTD=0x10;
delay_ms(200);
PORTD=0x20;
delay_ms(200);
PORTD=0x40;
delay_ms(200);
PORTD=0x80;
delay_ms(200);

}
}
PERCOBAAN 2.1 DAN 2.2
/*****************************************************
Chip type : ATmega16
Program type : Application
AVR Core Clock frequency : 4.000000 MHz
Memory model : Small
External RAM size :0
Data Stack size : 256

*****************************************************/
#include <mega16.h>
#include <delay.h>

unsigned char angka [10]= {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};


void main(void)
{
int naik,i;
PORTA=0x00;
DDRA=0xFF;
PORTB=0x00;
DDRB=0xFF;

while (1)
{
naik=0;
for(naik=0;naik<10;naik++)
{
for(i=0;i<10;i++)
{
PORTA=angka[naik];
PORTB.0=0;
delay_ms(10);
}
}
};
}
PERCOBAAN 2.3
/*****************************************************
Chip type :ATmega16
Program type : Application
AVR Core Clock frequency : 4.000000 MHz
Memory model : Small
External RAM size :0
Data Stack size : 256

*****************************************************/
#include <mega16.h>
#include <delay.h>

void main(void)
{
int i;
char data [11]= {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x3f};

PORTA=0x00;
DDRA=0xFF;

while (1)
{
PORTA=data[i];
delay_ms(200);
if(i==11)
{
i=0;
}
i++;
};
}
PERCOBAAN 2.4
/*****************************************************

Chip type : ATmega16


Program type : Application
AVR Core Clock frequency : 4.000000 MHz
Memory model : Small
External RAM size :0
Data Stack size : 256

*****************************************************/

#include <mega16.h>
#include <delay.h>

char dataku1[10]= {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};

void main(void)
{
int i,j,k,l;

PORTC=0x00;
DDRC=0xFF;

PORTD=0x00;
DDRD=0xFF;

while (1)
{
for(l=0;l<10;l++)
{
for(k=0;k<10;k++)
{
for(j=0;j<10;j++)
{
for(i=0;i<10;i++)
{
PORTD= 0xfb;
PORTC=dataku1[i];
delay_ms(2);
PORTD=0xfd;
PORTC=dataku1[j];
delay_ms(2);
PORTD= 0xfe;
PORTC=dataku1[k];
delay_ms(2);
PORTD=0xf7;
PORTC=dataku1[l];
delay_ms(2);
}
}
}
}
};
}
PERCOBAAN 3.1 DAN 3.2
/*****************************************************

Chip type : ATmega16


Program type : Application
AVR Core Clock frequency : 12.000000 MHz
Memory model : Small
External RAM size :0
Data Stack size : 256

*****************************************************/

#include <mega16.h>
#include <delay.h>
#include <stdio.h>
#include <lcd.h>
#asm
.equ __lcd_port=0x12 ;PORTD
#endasm

unsigned char tmp[81];


unsigned char i;

void hitung()
{
int x;
for (x=0;x<=999;x++)
{
lcd_clear();
sprintf(tmp,"DATAKU %d",x);
lcd_puts(tmp);
delay_ms(10);
}
}

void kali()
{
float hasil;
lcd_clear();
hasil=79*30.1;
sprintf(tmp,"79 x 30.1=%.2f",hasil);
lcd_puts(tmp);
lcd_gotoxy(0,0);
}

void main(void)
{
lcd_init(20);
kali();
delay_ms(50);

while (1)
{
for(i=0;i<=20;i++)
{
hitung();
};
};
}
PERCOBAAN 4
/*****************************************************

Chip type : ATmega16


Program type : Application
AVR Core Clock frequency : 12.000000 MHz
Memory model : Small
External RAM size :0
Data Stack size : 256

*****************************************************/

#include <mega16.h>
#include <delay.h>

char data1[8]={0x0e,0x0e,0x0d,0x0d,0x0b,0x0b,0x07,0x07};
char data2[8]={0x00,0x01,0x00,0x02,0x00,0x04,0x00,0x08};
char data3[8]={0x01,0x00,0x02,0x00,0x04,0x00,0x08,0x00};

void main(void)
{
int i,j,k;
i=0;
j=0;
k=0;

PORTA=0x00;
DDRA=0xFF;

PORTB=0x00;
DDRB=0xFF;

PORTD=0x00;
DDRD=0xFF;

while (1)
{
if(i==8,j==8,k==8)
{
k=0;
i=0;
j=0;
}
PORTD=data3[k];
PORTB=data2[j];
PORTA=data1[i];
delay_ms(200);
i++;
j++;
k++;
};
}

You might also like