LAPORAN
PRAKTIKUM RANGKAIAN ELEKTRONIKA DAYA
PERCOBAAN ......
......................................................................................................................................................
NAMA
: ................................................................................................
NIM
: ................................................................................................
TGL PRAKTIKUM : ................................................................................................
FAKULTAS TEKNIK
JURUSAN TEKNIK ELEKTRO
PRODI S1 PENDIDIKAN TEKNIK ELEKTRO
UNIVERSITAS NEGERI MALANGFendi Rokhman wrote:
yang mau belajar uas mikro berdasar foto yang diupload lombok ini
kode programnya:
===============================
SOAL A
===============================
#include <mega8535.h>
void main(void)
{
PORTA=0x00;
DDRA=0xFF;
PORTB=0x00;
DDRB=0x00;
PORTC=0xFF;
DDRC=0x00;
PORTD=0x00;
DDRD=0x00;
while (1){
if(PINC.0==1){
PORTA.2=1;
PORTA.4=1;
}
else{
PORTA.2=0;
PORTA.4=0;
}
if(PINC.2==1){
PORTA.6=1;
PORTA.7=1;
}
else{
PORTA.6=0;
PORTA.7=0;
}
}
}
===============================
SOAL C
===============================
#include <mega8535.h>
#include <delay.h>
unsigned char keypad();
void main(void)
{
int a;
PORTA=0x00;
DDRA=0xFF;
PORTB=0xFF;
DDRB=0x0F;
PORTC=0x00;
DDRC=0x00;
PORTD=0x00;
DDRD=0x00;
while (1){
// Place your code here
if(keypad()==0){
for(a=0;a<=10;a++){
PORTA=a;
delay_ms(1000);
}
}
if(keypad()==1){
for(a=15;a>0;a--){
PORTA=a;
delay_ms(1000);
}
}
PORTA=0;
}
}
unsigned char keypad(){
PORTB = 0b11111110; //aktifkan baris1 (memberi logika 0 ke
baris1)
delay_ms(100);
if(PINB.7==0) return (10);
if(PINB.6==0) return (3);
if(PINB.5==0) return (2);
if(PINB.4==0) return (1);
//========================
PORTB = 0b11111101; //aktifkan baris2
delay_ms(100);
if(PINB.7==0) return (11);
if(PINB.6==0) return (6);
if(PINB.5==0) return (5);
if(PINB.4==0) return (4);
//========================
PORTB = 0b11111011; //aktifkan baris3
delay_ms(100);
if(PINB.7==0) return (12);
if(PINB.6==0) return (9);
if(PINB.5==0) return (8);
if(PINB.4==0) return (7);
//========================
PORTB = 0b11110111; //aktifkan baris4
delay_ms(100);
if(PINB.7==0) return (13);
if(PINB.6==0) return (15);
if(PINB.5==0) return (0);
if(PINB.4==0) return (14);
}
===============================
SOAL D
===============================
#include <mega8535.h>
#include <delay.h>
unsigned char keypad();
void main(void)
{
PORTA=0x00;
DDRA=0xFF;
PORTB=0xFF;
DDRB=0x0F;
PORTC=0x00;
DDRC=0x00;
PORTD=0x00;
DDRD=0x00;
while (1){
// Place your code here
if(keypad()==2){
PORTA=0b00001111;
delay_ms(1000);
PORTA=0b11110000;
}
if(keypad()==4){
PORTA=255;
delay_ms(1000);
}
PORTA=0;
}
}
unsigned char keypad(){
PORTB = 0b11111110; //aktifkan baris1 (memberi logika 0 ke
baris1)
delay_ms(100);
if(PINB.7==0) return (10);
if(PINB.6==0) return (3);
if(PINB.5==0) return (2);
if(PINB.4==0) return (1);
//========================
PORTB = 0b11111101; //aktifkan baris2
delay_ms(100);
if(PINB.7==0) return (11);
if(PINB.6==0) return (6);
if(PINB.5==0) return (5);
if(PINB.4==0) return (4);
//========================
PORTB = 0b11111011; //aktifkan baris3
delay_ms(100);
if(PINB.7==0) return (12);
if(PINB.6==0) return (9);
if(PINB.5==0) return (8);
if(PINB.4==0) return (7);
//========================
PORTB = 0b11110111; //aktifkan baris4
delay_ms(100);
if(PINB.7==0) return (13);
if(PINB.6==0) return (15);
if(PINB.5==0) return (0);
if(PINB.4==0) return (14);
}