Anda di halaman 1dari 13

Politeknik Negeri JUDUL Pengampu : Syahid, S.T.

,
Semarang M.Eng.
Job Sheet : 2
Nama : Dwi Kurniawan Tanggal : 5 Mei 2020
Kelas : LT -2B PUSH BUTTON Semester : 4
NIM : 3.31.18.1.10 Paraf:
Matkul : Praktikum Kendali Mikro

BUAT SIMULASI DENGAN PROTEUS TUGAS PUSH BUTTON. HASILNYA DIKIRIM


MELALUI ELNINO YANG ISINYA DOKUMENTASI VIDEO , LISTING PROGRAM
DAN GAMBAR RANGKAIAN.
LATIHAN
 LATIHAN 1
Pada percobaan ini PORTB difungsikan sebagai input dan PORTC difungsikan
sebagai output.
a) Listing Program
#include <mega16.h>
void main(void)
{
DDRC=0xFF;
DDRB=0x00;
PORTB=0xFF;
while (1)
{
PORTC=PINB;
}
}

b) Gambar Rangkaian
 LATIHAN 2
Pada percobaan ini, anda akan belajar bagaimana mengambil data per bit. Dengan
menggunakan instruksi PINB.X, dengan X adalah nilai bit.
a) Listing Program
#include <mega16.h>
void main(void)
{
DDRC=0xFF;
DDRB=0x00;
PORTB=0xFF;
while(1)
{
if (PINB.0==0) {PORTC=0x01;}
else if (PINB.1==0){PORTC=0x02;}
else if (PINB.2==0){PORTC=0x04;}
else if (PINB.3==0){PORTC=0x08;}
else {PORTC=0x00;}
}
}
b) Gambar Rangkaian
 LATIHAN 3
Pada percobaan ini anda akan mengambil data dengan menggunakan SW push button,
setiap penekanan SW akan menampilkan pola LED tertentu.
a) Listing Program
#include <mega16.h>
#include <delay.h>

//declare global arrays for two patterns


unsigned char p1[4] = { 0b10000001,
0b01000010,
0b00100100,
0b00011000 };

unsigned char p2[4] = { 0b11111111,


0b01111110,
0b00111100,
0b00011000 };
void main()
{
unsigned char i; //loop counter

DDRC = 0xFF; //PB as output


PORTC= 0x00; //keep all LEDs off

DDRB = 0x00; //PC as input


PORTB.0 = 1; //enable pull ups for
PORTB.1 = 1; //only first two pins

while(1)
{
//# if SW0 is pressed show pattern 1
if(PINB.0==0)
{
for(i=0;i<4;i++)
{
PORTC=p1[i]; //output data
delay_ms(300); //wait for some time
}
PORTC=0; //turn off all LEDs
}

//# if SW1 is pressed show pattern 2


if(PINB.1==0)
{
for(i=0;i<4;i++)
{
PORTC=p2[i]; //output data
delay_ms(300); //wait for some time
}
PORTC=0; //turn off all LEDs
}

};
}

b) Gambar Rangkaian
TUGAS
 TUGAS 1
Buat program untuk menghidupkan LED dengan urutan nomor yang berbeda dengan
urutan nomor push button
a) Listing Program
#include <mega16.h>
void main(void)
{
DDRC=0xFF;
DDRB=0x00;
PORTB=0xFF;
while(1)
{
if (PINB.0==0) {PORTC=0x10;} else
if (PINB.1==0){PORTC=0x20;} else
if (PINB.2==0){PORTC=0x40;} else
if (PINB.3==0){PORTC=0x80;} else
if (PINB.4==0){PORTC=0x01;} else
if (PINB.5==0){PORTC=0x02;} else
if (PINB.6==0){PORTC=0x04;} else
if (PINB.7==0){PORTC=0x08;} else
{PORTC=0x00;}
}
}

b) Gambar Rangkaian
 TUGAS 2
Buat program untuk menjalankan LED secara bergantian dua-dua mulai dari LED no
1 sampai LED no 8 yang diaktifkan dengan SW no 4
a) Listing Program
#include <mega16.h>
#include <delay.h>
//declare global arrays for two patterns
unsigned char p1[4] = {0b00000011,
0b00001100,
0b00110000,
0b11000000};
void main()
{
unsigned char i; //loop counter

DDRC = 0xFF; //PB as output


PORTC= 0x00; //keep all LEDs off

DDRB = 0x00; //PC as input


PORTB.0 = 1; //enable pull ups for
PORTB.1 = 1; //only first two pins
while(1)
{
//# if SW4 is pressed show pattern 1
if(PINB.3==0)
{
for(i=0;i<4;i++)
{
PORTC=p1[i]; //output data
delay_ms(60); //wait for some time
}
PORTC=0; //turn off all LEDs
}
}
}
}

b) Gambar Rangkaian
 TUGAS 3
Buat program untuk menjalankan LED secara bergantian satu-satu mulai dari pinggir
ke tengah yang diaktifkan dengan SW no 3
a) Listing Program
#include <mega16.h>
#include <delay.h>
//declare global arrays for two patterns
unsigned char p1[8] = { 0b00000001,
0b10000000,
0b00000010,
0b01000000,
0b00000100,
0b00100000,
0b00001000,
0b00010000 };
void main()
{
unsigned char i; //loop counter

DDRC = 0xFF; //PB as output


PORTC= 0x00; //keep all LEDs off

DDRB = 0x00; //PC as input


PORTB.0 = 1; //enable pull ups for
PORTB.1 = 1; //only first two pins

while(1)
{
//# if SW3 is pressed show pattern 1
if(PINB.2==0)
{
for(i=0;i<8;i++)
{
PORTC=p1[i]; //output data
delay_ms(60); //wait for some time
}
PORTC=0; //turn off all LEDs
}
}
}
}
b) Gambar Rangkaian
 TUGAS 4
Buat program untuk menjalankan LED dari pinggir ke tengah kemudian balik lagi dari
tengah ke pinggir yang diaktifkan dengan SW no 7
a) Listing Program
#include <mega16.h>
#include <delay.h>
//declare global arrays for two patterns
unsigned char p1[8] = { 0b10000001,
0b01000010,
0b00100100,
0b00011000,
0b00011000,
0b00100100,
0b01000010,
0b10000001 };
void main()
{
unsigned char i; //loop counter

DDRC = 0xFF; //PB as output


PORTC= 0x00; //keep all LEDs off

DDRB = 0x00; //PC as input


PORTB.0 = 1; //enable pull ups for
PORTB.1 = 1; //only first two pins

while(1)
{
//# if SW7 is pressed show pattern 1
if(PINB.6==0)
{
for(i=0;i<8;i++)
{
PORTC=p1[i]; //output data
delay_ms(60); //wait for some time
}
PORTC=0; //turn off all LEDs
}
}
}
}
b) Gambar Rangkaian

Anda mungkin juga menyukai