Anda di halaman 1dari 10

Hasanuddin University

ELECTRICAL ENGINEERING, UNDERGRADUATE PROGRAM


Mikroprosesor dan Antarmuka

TUGAS
MIKRO PROSESOR DAN ANTARMUKA

Wempi
D411 14 003
1. Buatlah program membaca dipswitch dan menjalankan led (8)
Jawab
Sinytax

ORG 00
SJMP MAIN

ORG 100
MAIN: SETB P1.0
SETB P1.1
SETB P1.2
SETB P1.3
SETB P1.4
SETB P1.5
SETB P1.6
SETB P1.7
CLR P2.0
CLR P2.1
CLR P2.2
CLR P2.3
CLR P2.4
CLR P2.5
CLR P2.6
CLR P2.7

CEK0: JB P1.0, OFF0


SETB P2.0

CEK1: JB P1.1, OFF1


SETB P2.1

CEK2: JB P1.2, OFF2


SETB P2.2

CEK3: JB P1.3, OFF3


SETB P2.3

CEK4: JB P1.4, OFF4


SETB P2.4

CEK5: JB P1.5, OFF5


SETB P2.5

CEK6: JB P1.6, OFF6


SETB P2.6

CEK7: JB P1.7, OFF7


SETB P2.7
SJMP CEK0

OFF0: CLR P2.0


SJMP CEK1
OFF1: CLR P2.1
SJMP CEK2

OFF2: CLR P2.2


SJMP CEK3

OFF3: CLR P2.3


SJMP CEK4

OFF4: CLR P2.4


SJMP CEK5

OFF5: CLR P2.5


SJMP CEK6

OFF6: CLR P2.6


SJMP CEK7

OFF7: CLR P2.7


SJMP CEK0

END
Gambar Rangkaian
2. Buatlah program yang menampilkan STB dan Nama ada LCD
Jawab
syntax
org 0000h

port_ini:

mov p1,#00h

setb p3.4

setb p3.5

setb p3.6

acall delay_1s

Lcd_ini:

mov a,#38h

acall command

mov a,#06h

acall command

mov a,#0ch

acall command

mov a,#01h

acall command

mov a,#80h

acall command

acall delay_1s

Display:

mov a,#'W'

acall write

mov a,#'E'

acall write

mov a,#'M'

acall write

mov a,#'P'

acall write

mov a,#'I'

acall write

mov a,#'/'
acall write

mov a,#'D'

acall write

mov a,#'4'

acall write

mov a,#'1'

acall write

mov a,#'1'

acall write

mov a,#'1'

acall write

mov a,#'4'

acall write

mov a,#'0'

acall write

mov a,#'0'

acall write

mov a,#'3'

acall write

here:

sjmp here

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

command:

mov p1,a

clr p3.4

clr p3.5

setb p3.6

acall delay

clr p3.6

acall delay

acall delay

ret

write:

lcall ready

mov p1,a
setb p3.4

clr p3.5

setb p3.6

acall delay

clr p3.6

acall delay

acall delay

ret

ready:

setb p1.7

clr p3.4

setb p3.5

wait:

clr p3.6

acall delay

setb p3.6

jb p1.7,wait

ret

delay:

mov r0,#1ch

rep:

djnz r0,rep

ret

delay_1s:

mov r3,#08h

df1s:

mov r2,#0ffh

d1s:

mov r1,#0ffh

de1s:

djnz r1,de1s

djnz r2,d1s

djnz r3,df1s

ret

end
Gambar rangkaian dan ouput LCD

3. Buatlah program membaca nilai sensor LM35 dan di tampilkan pada LCD
JAWAB
Syntax
.include "m328Pdef.inc"

start:

SBI DDRB,5

blink: LDI r20,250

CALL delay

SBI PORTB,5

LDI r20,250

CALL delay

CBI PORTB,5

JMP blink
delay:

ldi r18, 26

ldi r19, 94

ldi r20, 111

L1: dec r20

brne L1

dec r19

brne L1

dec r18

brne L1

nop

Gambar rangkaian

4. Buatlah program bebas untuk atmega 328p !


jawab

Program pendeteksi gas berbasis mikrokontroller ATEMEGA 328P dengan fitur sms kebocoran

syntax
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 13, 11, 10, 9, 8); //RS, E, D4-D7
SoftwareSerial mySerial(5, 6); //gsm module
float sensor=A0;
float gas_value;
int buzzer=2;
int motor_DC=3;
int exhaust=4;
int Gas_alert_val, Gas_shut_val,voltage_sensor,per_gas_value;
int Gas_Leak_Status;
int sms_count=0;

void setup()
{

pinMode(sensor,INPUT);
pinMode(buzzer,OUTPUT);
pinMode(motor_DC,OUTPUT);
pinMode(exhaust,OUTPUT);
mySerial.begin(9600);
Serial.begin(9600);
lcd.begin(16,2);
delay(500);

void loop()
{
CheckGas();
}

void CheckGas()
{

gas_value=analogRead(sensor);
per_gas_value=gas_value/1023*100;
Serial.print("Persen_Kebocoran_LPG: ");
Serial.print(per_gas_value);
Serial.print("%");

Serial.print(" ---> ");


Serial.print("Status: ");
if (per_gas_value<=50)
{

Serial.println("Aman terkendali.");
Serial.print("Buzzer: OFF ");
Serial.print("Motor Stepper: OFF ");
Serial.println("Exhaust Fan: OFF");
Serial.println("------------------------------------------------------");
digitalWrite(buzzer,LOW);
digitalWrite(motor_DC,LOW);
digitalWrite(exhaust,LOW);
}

else
{

Serial.println("BOCOR!!!");
Serial.print("Buzzer: ON ");
Serial.print("Motor Stepper: ON ");
Serial.println("Exhaust Fan: ON");
Serial.println("SMS PERINGATAN TERKIRIM!!");
Serial.println("------------------------------------------------------");
digitalWrite(buzzer,HIGH);
digitalWrite(exhaust,HIGH);
digitalWrite(motor_DC,HIGH);
void SendTextMessage();// Function to send SMS Alerts
}
}

void SendTextMessage()
{
mySerial.println("AT+CMGF=1"); //To send SMS in Text Mode

mySerial.println("AT+CMGS=\"+6282299768805\"\r"); // change to the phone number you using

mySerial.println("BOCOR WOYYY!!");//the content of the message

mySerial.println((char)26);//the stopping character

mySerial.println("AT+CMGS=\"+6282346108706\"\r"); // change to the phone number you using

mySerial.println("BOCOOOOR!! BOCOOOR!!!");//the content of the message

mySerial.println((char)26);//the message stopping character

sms_count++;
}

gambar rangkaian dan output