0% found this document useful (0 votes)
19 views

AVR

The document contains code for an Arduino program that controls motors and LEDs on a microcontroller board. It defines constants for button inputs and sets port directions. Functions are declared to run motors in different directions, blink LEDs in increasing/decreasing patterns, display text on an LCD by clearing and writing in different positions over time, and toggle all LEDs on and off. The main program sets ports, then runs the appropriate function when each button is pressed while in a continuous loop.

Uploaded by

Riyo Nandika
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

AVR

The document contains code for an Arduino program that controls motors and LEDs on a microcontroller board. It defines constants for button inputs and sets port directions. Functions are declared to run motors in different directions, blink LEDs in increasing/decreasing patterns, display text on an LCD by clearing and writing in different positions over time, and toggle all LEDs on and off. The main program sets ports, then runs the appropriate function when each button is pressed while in a continuous loop.

Uploaded by

Riyo Nandika
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <mega16.

h> // library atmega16


#include <delay.h> // library delay
#include <string.h>
#include <alcd.h>
#define BUTTON1 PINA.0
#define BUTTON2 PINA.1
#define BUTTON3 PINA.2
#define BUTTON4 PINA.3
#define BUTTON5 PINA.4
#define BUTTON6 PINA.5
#define BUTTON7 PINA.6
#define BUTTON8 PINA.7

int b;

// int b
void motor(){
PORTD.0=1;
PORTD.1=1;
PORTD.2=0;
}

void motor2(){
PORTD.0=1;
PORTD.1=0;
PORTD.2=1;
}

void led_berjalan(){
for(b = 1; b <= 128; b = b*2){
PORTB = b;
delay_ms(50);
}
for(b = 128; b >= 1; b = b/2){
PORTB = b;
delay_ms(50);

}
for(b = 1; b <= 128; b = b*2){
PORTB = b;
delay_ms(50);
}
for(b = 128; b >= 1; b = b/2){
PORTB = b;
delay_ms(50);

}
for(b = 1; b <= 128; b = b*2){
PORTB = b;
delay_ms(50);
}
for(b = 128; b >= 1; b = b/2){
PORTB = b;
delay_ms(50);
}
for(b = 1; b <= 128; b = b*2){
PORTB = b;
delay_ms(50);
}
for(b = 128; b >= 1; b = b/2){
PORTB = b;
delay_ms(50);

}
for(b = 1; b <= 128; b = b*2){
PORTB = b;
delay_ms(50);
}
for(b = 128; b >= 1; b = b/2){
PORTB = b;
delay_ms(50);

}
}

void flip_flop(){
lcd_clear();
for (b=1; b<=10; b++){
PORTB = 0X00;
lcd_gotoxy(0,0);
delay_ms(5000);
PORTB = 0XFF;
lcd_putsf("akuu");
delay_ms(5000);
}
}

void flip_flop2(){
for (b=1; b<=15; b++){
PORTB = 0h0f;
delay_ms(1000);
PORTB = 0b1101 1010;
delay_ms(1000);
}
}

void lcd(){
for(b=0; b<=15; b++){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("RIYO");
lcd_gotoxy(b,1);
lcd_putsf("GANTENG");
delay_ms(50);
}
}

void main (void){


PORTA = 0X00;
DDRA = 0Xff;
PORTB = 0Xff;
DDRB = 0X00 ;
PORTC = 0X00;
DDRC = 0XFF;
PORTD = 0X00;
DDRD = 0XFF;

while(1){

PORTB = 0X00;
if(BUTTON1 == 0){
motor();
}
if(BUTTON2 == 0){
motor2();
}
if(BUTTON3 == 0){
flip_flop2();
}
if(BUTTON4 == 0){
led_berjalan();

}
if(BUTTON6 == 0){
flip_flop2();

if(BUTTON7 == 0){
;
}

if(BUTTON8 == 0){

}
}
}
}

You might also like