Professional Documents
Culture Documents
#define LDP PORTC Mengubah target pada makefile sesuai nama file
sourcecode
#define LCP PORTC
#define LDDR DDRC Melakukan kompilasi source code
5. KESIMPULAN
Dari percobaan ini didapat kesimpulan sebagai
berikut :
1. Dalam melakukan problem solving
dengan ATMega8535, kita harus terlebih
dahulu memahami datasheetnya terlebih
dahulu sehingga kita bisa mendesain
solusi denngan benar
Gambar 4-13 Flowchart tugas 4C4
2. Dalam melakukan problem solving, kita
1. Teknik scanning digunakan saat memakai dapat memanfaatkan penggunaan
seven segment dan keypad untuk mikrokontroler (dalam hal ini ATMega)
meminimalisir penggunaan PORT ketika dan dikombinasikan dengan penggunaan
menentukan masukan mana yang diterima dan LCD, Seven segment, maupun keypad
keluaran apa yang diharapkan. yang dapat digunakan sebagai output dan
2. Scanning keypad dilakukan per kolom sehingga input dengan menghubungkannya ke
saat keypad dalam satu baris ditekan tidak akan PORT tertentu. Metode scanning dapat
berpengaruh terhadap keluaran. Adapun jika dgunakan untuk membuat seven segment
keypad dalam satu kolom ditekan, keypad menyala bergantian dengan sangat cepat.
diatas tombol yang ditekan akan mati yaitu Scanning pada keypad juga dapat
mengikuti keadaan keypad yang ditekan karena dilakukan per kolom untuk membaca
bersifat seri. masukannya. Dan kita juga bisa
menggunakan LCD dengan bantuan
library yang sudah ada untuk mendesain
sesuai yang kita inginkan.
char angka;
char kodehex;
unsigned int SSegmen(char angka);
int main(void)
{
DDRA = 0xFF;
DDRD = 0XFF;
while (1)
{
PORTD = (0<<PD7) | (1<<PD6);
PORTA = SSegmen('7') | (1<<7);
_delay_ms(1);
PORTD = (1<<PD7) | (0<<PD6);
PORTA = SSegmen('2');
_delay_ms(1);
}
return 0;
}
tugas4a2.c
#include <avr/io.h>
Laporan Praktikum - Laboratorium Dasar Teknik Elektro – STEI ITB 8
#define F_CPU 7372800UL
#include <util/delay.h>
char angka;
char kodehex;
unsigned int SSegmen(int angka);
int main(void)
{
DDRA = 0xFF;
DDRD = 0XFF;
int i,j;
while (1)
{
for(i=5;i>0;i--)
{
for(j=0;j<500;j++)
{
PORTD = (0<<PD7) | (1<<PD6);
PORTA = SSegmen(i);
_delay_ms(1);
PORTD = (1<<PD7) | (0<<PD6);
PORTA = SSegmen(0) | (1<<7);
_delay_ms(1);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<250;j++)
{
PORTD = (0<<PD7) | (1<<PD6);
PORTA = 0xF1;
_delay_ms(1);
PORTD = (1<<PD7) | (0<<PD6);
PORTA = 0xF1;
_delay_ms(1);
}
for(j=0;j<250;j++)
{
PORTD = (0<<PD7) | (1<<PD6);
PORTA = 0x00;
_delay_ms(1);
PORTD = (1<<PD7) | (0<<PD6);
PORTA = 0x00;
_delay_ms(1);
}
}
}
return 0;
}
tugas4b1.c
#include <avr/io.h>
#define F_CPU 7372800UL
#include <util/delay.h>
int main(void)
{
DDRA = 0xFF;
PORTA = 0x00;
DDRD = (1<<PD4) | (1<<PD5);
SFIOR = (0<<PUD);
while (1)
{
PORTD = (1<<PD4) | (0<<PD5);
if (bit_is_clear(PIND, 0))
PORTA = 0b00000001;
_delay_ms(50);
if (bit_is_clear(PIND, 1))
PORTA = 0b00001111;
_delay_ms(50);
tugas4b2.c
#include <avr/io.h>
#define F_CPU 7372800UL
#include <util/delay.h>
char angka;
char kodehex;
unsigned int SSegmen(char angka);
int main(void)
{
DDRA = 0xFF;
DDRD = (1<<PD4) | (1<<PD5);
SFIOR = (0<<PUD);
Laporan Praktikum - Laboratorium Dasar Teknik Elektro – STEI ITB 1
0
// Keadaan awal
PORTD = (0<<PC7) | (1<<PC6);
PORTA = SSegmen('0');
_delay_ms(1);
PORTD = (1<<PC7) | (0<<PC6);
PORTA = SSegmen('0');
_delay_ms(1);
while (1)
{
PORTD = (1<<PD4) | (0<<PD5);
if (bit_is_clear(PIND, 0))
{
PORTA = SSegmen('1');
_delay_ms(1);
PORTA = SSegmen('1');
_delay_ms(1);
}
if (bit_is_clear(PIND, 1))
{
PORTA = SSegmen('4');
_delay_ms(1);
PORTA = SSegmen('4');
_delay_ms(1);
}
tugas4c1.c
//*****************************************************************************
//
// File Name : 'main.c'
// Title : LCD demo
// Author : Scienceprog.com - Copyright (C) 2007
// Created : 2007-03-29
// Revised : 2007-08-28
// Version : 1.0
// Target MCU : Atmel AVR series
//
// This code is distributed under the GNU Public License
// which can be found at http://www.gnu.org/licenses/gpl.txt
//
//*****************************************************************************
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include "lcd_lib.h"
int main(void)
{
LCDinit();//init LCD bit, dual line, cursor right
LCDclr();//clears LCD
while(1)//loop demos
{
progress();
delay1s();
demoanimation();
}
return 0;
}
tugas4c2.c
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include "lcd_lib.h"
// delay 1s
void delay1s(void)
{
uint8_t i;
for (i=0; i<100; i++)
int main(void)
{
LCDinit(); // initialize LCD bit, dual line, cursor right
LCDclr(); // clear LCD
DDRA = 0xFF;
PORTA = 0x00;
DDRD = (1<<PD4) | (1<<PD5) | (1<<PC7) | (1<<PC6);
SFIOR = (0<<PUD);
delay1s();
LCDGotoXY(0, 1);
delay1s();
if (bit_is_clear(PIND, 1))
{
LCDclr();
LCDGotoXY(8, 1);
LCDsendChar('a');
delay1s();
LCDclr();
}
_delay_ms(50);
if (bit_is_clear(PIND, 1))
{
LCDclr();
LCDGotoXY(8, 1);
LCDsendChar('7');
delay1s();
LCDclr();
}
_delay_ms(50);
}
return 0;
}
// delay 1s
void delay1s(void)
{
uint8_t i;
for (i=0; i<100; i++)
{
_delay_ms(10);
}
}
int main(void)
{
LCDinit(); // initialize LCD bit, dual line, cursor right
LCDclr(); // clear LCD
DDRA = 0xFF;
PORTA = 0x00;
DDRD = (1<<PD4) | (1<<PD5) | (1<<PC7) | (1<<PC6);
SFIOR = (0<<PUD);
int posisi = 0;
int hitung = 1;
delay1s();
LCDGotoXY(0, 1);
delay1s();
CopyStringtoLCD(LCDtombol1, 0, 0);
if (bit_is_clear(PIND, 1))
{
//LCDclr();
LCDGotoXY(posisi, 1);
LCDsendChar('4');
delay1s();
posisi++; hitung++;
//LCDclr();
}
_delay_ms(50);
if (bit_is_clear(PIND, 1))
{
//LCDclr();
LCDGotoXY(posisi, 1);
LCDsendChar('3');
delay1s();
posisi++; hitung++;
//LCDclr();
}
_delay_ms(50);
if ((hitung%5)==0)
{
LCDshiftRight(2);
hitung = 1;
}
}
return 0;
}
tugas4c4.c
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include "lcd_lib.h"
//Strings stored in AVR Flash memory
const uint8_t LCDawal[] PROGMEM="Percobaan LCD\0";
int main(void)
{
static int count = 0;
LCDinit();//init LCD bit, dual line, cursor right
LCDclr();//clears LCD
DDRA=0xFF;
PORTA=0x00;
DDRD=0x00;
PORTD=0x0F;
SFIOR=(0<<PUD);
LCDGotoXY(0, 0);
CopyStringtoLCD(LCDawal, 0, 0);
LCDGotoXY(0, 1);
while(1)//loop demos
{
if (count >= 4) {
LCDshiftRight(2);
count = 0;
}
if (bit_is_clear(PIND,0)) {
if (i == 0x10)
LCDsendChar('1');
else if (i == 0x20)
LCDsendChar('4');
else if (i == 0x40)
LCDsendChar('7');
else if (i == 0x80)
count++;
}
if (bit_is_clear(PIND,1)) {
if (i == 0x10)
LCDsendChar('2');
else if (i == 0x20)
LCDsendChar('5');
else if (i == 0x40)
LCDsendChar('8');
else if (i == 0x80)
LCDsendChar('0');
_delay_ms(200);
count++;
}
if (bit_is_clear(PIND,2)) {
if (i == 0x10)
LCDsendChar('3');
else if (i == 0x20)
LCDsendChar('6');
else if (i == 0x40)
LCDsendChar('9');
else if (i == 0x80)
LCDsendChar('#');
_delay_ms(200);
count++;
}
if (bit_is_clear(PIND,3)) {
if (i == 0x10)
LCDsendChar('A');
else if (i == 0x20)
LCDsendChar('B');
else if (i == 0x40)
LCDsendChar('C');
else if (i == 0x80)
LCDsendChar('D');
_delay_ms(200);
count++;
}
i=(i<<1);
}
}
return 0;
}