Anda di halaman 1dari 4

TUGAS MATA KULIAH TEKNIK ANTARMUKA MIKROKONTROLER

PENGUKURAN PRESSUREDENGAN TAMPILAN KOMPUTER

Oleh:
Nama:Fahrul Rozi
NPM:061540341503
Kelas:4ELA

Dosen Pembimbing :Amperawan

TEKNIK ELEKTRO
POLITEKNIK NEGRI SRIWIJAYA
PALEMBANG
2017
LCD2
LM041L

M1 U1

VDD
VSS

VEE
MPX4115 9 22

RW
RS

D0
D1
D2
D3
D4
D5
D6
D7
RESET PC0/SCL

E
23
PC1/SDA
13 24
XTAL1 PC2/TCK

1
2
3

4
5
6

7
8
9
10
11
12
13
14
22.0 12 25
XTAL2 PC3/TMS
26
PC4/TDO
40 27
PA0/ADC0 PC5/TDI
39 28
PA1/ADC1 PC6/TOSC1
38 29
PA2/ADC2 PC7/TOSC2
37
PA3/ADC3
1 2 3 4 5 6 36 14
PA4/ADC4 PD0/RXD
35 15
PA5/ADC5 PD1/TXD
34 16
PA6/ADC6 PD2/INT0
33 17
PA7/ADC7 PD3/INT1
18
PD4/OC1B
1 19
PB0/T0/XCK PD5/OC1A
2 20
PB1/T1 PD6/ICP1
3 21
PB2/AIN0/INT2 PD7/OC2
4
PB3/AIN1/OC0
5
PB4/SS
6
PB5/MOSI
7 32
PB6/MISO AREF
8 30
PB7/SCK AVCC
ATMEGA32

#include <avr/io.h>
#include <inttypes.h>
#include <util/delay.h>
#include "lcd.h"

void InitADC()
{
ADMUX=(1<<REFS0); // For Aref=AVcc;
ADCSRA=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); //Rrescalar div factor =128
}

uint16_t ReadADC(uint8_t ch)


{
//Select ADC Channel ch must be 0-7

ADMUX=(ADMUX&0xE0)|ch;
//Start Single conversion
ADCSRA|=(1<<ADSC);

//Wait for conversion to complete


while(!(ADCSRA & (1<<ADIF)));

ADCSRA|=(1<<ADIF);

return(ADC);
}

int main(void)
{

float adc_result;

DDRB = 0x00;
//Initialize LCD
InitLCD(LS_BLINK|LS_ULINE);
LCDClear();

//Initialize ADC
InitADC();

LCDWriteString("Pressure monitor");

_delay_ms(1000);
while(1)
{

LCDClear();

LCDWriteStringXY(0,1,"Pressure=")
adc_result= (5.0/1023.0)*ReadADC(0); // Read
Analog value from channel-0

adc_result=((adc_result/5.0)+0.095)/0.009-1;

LCDWriteIntXY(9,1,adc_result,3); //Print the value in 4th


column second line

LCDWriteStringXY(12,1,"Kpa");

_delay_ms(10000);

return 1;
}