Jumat, 21 Oktober 2016

Contoh Program Aktifkan Led

Tulis program berikut dengan Code Vision AVR :

/Program 1: Menghidupkan LED di Port B
//OK
#include <mega8535.h>
void main()
{
 DDRB=0b11111111;
 PORTB=0b01010101;
 while(1);
}


//Program 2: LED Blink
#include <mega8535.h>
#include <delay.h>
void main()
{
 DDRB=0b11111111;
 while(1)
 {
  PORTB=0b11111111;
  delay_ms(1000);
  PORTB=0b00000000;
  delay_ms(1000);
 }

}


//Program 3: LED Berjalan
//OK
#include <mega8535.h>
#include <delay.h>
void main()
{
 DDRB=0b11111111;
 while(1)
 {
  PORTB=0b00000001;
  delay_ms(1000);
  PORTB=0b00000010;
  delay_ms(1000);
  PORTB=0b00000100;
  delay_ms(1000);
  PORTB=0b00001000;
  delay_ms(1000);
  PORTB=0b00010000;
  delay_ms(1000);
  PORTB=0b00100000;
  delay_ms(1000);
  PORTB=0b01000000;
  delay_ms(1000);
  PORTB=0b10000000;
  delay_ms(1000);
 }

}

Tidak ada komentar: