Pages

10.7.12

simple project of microcontroller atmega16


minimum system atmega16 menggunakan isis proteus 7.6

program C menggunakan CodeVision

#include <mega16.h>
#include <delay.h>
#include <stdio.h>
// Alphanumeric LCD Module functions
#asm
   .equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>
// Declare your global variables here
char cetak[16];
void buka()
{
    int e;
    for(e=0;e<3;e++)
    {
    lcd_clear();
    delay_ms(1500);
    lcd_gotoxy(1,0);
    lcd_putsf("LED Programmed");
    lcd_gotoxy(1,1);
    lcd_putsf("by JMHutabarat");
    delay_ms(1500);
    }
}
     
void geserkiri()
{
    unsigned char x=0x80;
    int i;
    for(i=0; i<9; i++)
    {
        lcd_clear();
        lcd_gotoxy(0,0);
        sprintf(cetak,"LED Value: 0x%x",x);
        lcd_puts(cetak);
        lcd_gotoxy(0,1);
        lcd_putsf("Mode: Shift Left");
        PORTA=x;
        delay_ms(500);
        x=x>>1;
        delay_ms(500);
    }
}

void geserkanan()
{
    unsigned char y=0x01;
    int j;
    for(j=0; j<9; j++)
    {
        lcd_clear();
        lcd_gotoxy(0,0);
        sprintf(cetak,"LED Value: 0x%x",y);
        lcd_puts(cetak);
        lcd_gotoxy(0,1);
        lcd_putsf("Mode:Shift Right");
        PORTB=y;
        delay_ms(500);
        y=y<<1;
        delay_ms(500);
    }
}

void incdec()
{
    unsigned char z=0x00;
    int b;
    int a;
    for(a=0; a<256; a++)
    {
        lcd_clear();
        z++;
        PORTD=z;
        lcd_gotoxy(0,0);
        sprintf(cetak,"LED Value: 0x%x",z);
        lcd_puts(cetak);
        lcd_gotoxy(0,1);
        lcd_putsf("Mode: Increment");
        delay_ms(700);
        if(z==0xff)
        {
            for(b=0; b<256; b++)
            {
                lcd_clear();
                z--;
                PORTD=z;
                lcd_gotoxy(0,0);
                sprintf(cetak,"LED Value: 0x%x",z);
                lcd_puts(cetak);
                lcd_gotoxy(0,1);
                lcd_putsf("Mode: Decrement");
                delay_ms(700);
            }
        }
    }
}

void main(void)
{
PORTA=0x00;
DDRA=0xff;

PORTB=0x00;
DDRB=0xFF;

PORTC=0x00;
DDRC=0x00;

PORTD=0x00;
DDRD=0xff;

ACSR=0x80;
SFIOR=0x00;
lcd_init(16);

while (1)
      {
      buka();
      geserkiri();
      geserkanan();
      incdec();
      }
}

No comments:

Post a Comment