You are on page 1of 12

Aplikasi Pemantauan Suhu menggunakan Mikrokontroler ATMega8535

Tahap I : Membuat Program di CVAVR


Langkah-langkah :
1. Buka program CVAVR

2. File > New Kemudian Pilih Project > OK > Yes

3. Pilih jenis Mikrokontroler kemudian OK

4. Setting Mikrokontroller sebagai berikut

http://riyanto04.wordpress.com
5. Klik File > Save Generate and Exit

http://riyanto04.wordpress.com
/*****************************************************
This program was produced by the
CodeWizardAVR V2.04.6 Evaluation
Automatic Program Generator
© Copyright 1998-2010 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project :
Version :
Date : 8/30/2010
Author : Freeware, for evaluation and non-commercial use only
Company :
Comments:

Chip type : ATmega8535


Program type : Application
AVR Core Clock frequency: 16.000000 MHz
Memory model : Small
External RAM size :0
Data Stack size : 128
*****************************************************/

#include <mega8535.h>

#include <delay.h>

#ifndef RXB8
#define RXB8 1
#endif

#ifndef TXB8
#define TXB8 0
#endif

#ifndef UPE
#define UPE 2
#endif

#ifndef DOR
#define DOR 3
#endif

#ifndef FE
#define FE 4
#endif

http://riyanto04.wordpress.com
#ifndef UDRE
#define UDRE 5
#endif

#ifndef RXC
#define RXC 7
#endif

#define FRAMING_ERROR (1<<FE)


#define PARITY_ERROR (1<<UPE)
#define DATA_OVERRUN (1<<DOR)
#define DATA_REGISTER_EMPTY (1<<UDRE)
#define RX_COMPLETE (1<<RXC)

// Get a character from the USART Receiver


#ifndef _DEBUG_TERMINAL_IO_
#define _ALTERNATE_GETCHAR_
#pragma used+
char getchar(void)
{
char status,data;
while (1)
{
while (((status=UCSRA) & RX_COMPLETE)==0);
data=UDR;
if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0)
return data;
}
}
#pragma used-
#endif

// Write a character to the USART Transmitter


#ifndef _DEBUG_TERMINAL_IO_
#define _ALTERNATE_PUTCHAR_
#pragma used+
void putchar(char c)
{
while ((UCSRA & DATA_REGISTER_EMPTY)==0);
UDR=c;
}
#pragma used-
#endif

// Standard Input/Output functions

http://riyanto04.wordpress.com
#include <stdio.h>

#define ADC_VREF_TYPE 0x20

// Read the 8 most significant bits


// of the AD conversion result
unsigned char read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCH;
}

// Declare your global variables here

void main(void)
{
// Declare your local variables here

// Input/Output Ports initialization


// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;

// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;

// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

http://riyanto04.wordpress.com
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

http://riyanto04.wordpress.com
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization


TIMSK=0x00;

// USART initialization
// Communication Parameters: 8 Data, 2 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 19200
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x8E;
UBRRH=0x00;
UBRRL=0x33;

// Analog Comparator initialization


// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// ADC initialization
// ADC Clock frequency: 1000.000 kHz
// ADC Voltage Reference: AREF pin
// ADC High Speed Mode: Off
// ADC Auto Trigger Source: Free Running
// Only the 8 most significant bits of
// the AD conversion result are used
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0xA4;
SFIOR&=0x0F;

while (1)
{
// Place your code here
putchar(read_adc(0));
delay_ms(1000);
}
}

http://riyanto04.wordpress.com
Tahap II : Membuat Database di M.Acces 2003
Langkah-langkah :
1. Buka program M.Acces 2003
2. Klik File > New > Blank Database
3. Simpan file misal db1.mdb
4. Double Klik Create Table in Design View

5. Isikan Nama Field dan Tipe Data

6. Simpan Tabel misal Tabel1

http://riyanto04.wordpress.com
Tahap III : Membuat Program di Visual Basic 6
Langkah-langkah :
1. Buka program VB 6
2. Ambil komponent yang diperlukan yaitu :

No Komponent Property Nilai Ket


1. Command1 Caption connect
2. Command2 Caption Hapus
3. Command3 Caption Exit
4. Text1 Text kosongkan
5. Text2 Text kosongkan
6. Check1 Caption Simpan ke database
7. Frame1 Caption Data Masuk
8. Timer1 Enable True
Interval 1000 1 detik
9. Adodc1 CommandType 2-adCmdTable
ConnectionStrin Provider=Microsoft.Jet.OLEDB.4.0;D
g ata Source=C:\data.mdb;Persist
Security Info=False
RecordSource Table1
10 DataGrid1 DataSource Adodc1

http://riyanto04.wordpress.com
Source Code :

Private Sub MSComm1_OnComm()


Text1.Text = Round(Asc(MSComm1.Input) * 500 / 255)
End Sub
Private Sub Command1_Click()
If Command1.Caption = "connect" Then
MSComm1.PortOpen = True
Command1.Caption = "disconnect"
Else
MSComm1.PortOpen = False
Command1.Caption = "connect"
End If
End Sub
Private Sub Timer1_Timer()
Text2.Text = Time
If Check1 Then
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields(0).Value = Text2.Text
Adodc1.Recordset.Fields(1).Value = Text1.Text
Adodc1.Recordset.Update
End If
End Sub
Private Sub Command3_Click()
Adodc1.Recordset.Delete
End Sub
Private Sub Command2_Click()
Unload Me
End Sub

http://riyanto04.wordpress.com
Menghubungkan Adodc ke database M.Acces:

1. Pada komponen Adodc1 klik property ConnectionString …


2. Pilih build > pilih provider kemudian isikan nama databasenya

3. Tes Connection > OK

http://riyanto04.wordpress.com
Hardware :

1. Modul Mikrokontroler ATMega8535


2. Downloader AVR
3. Sensor Suhu LM35
4. Kabel Serial RS232

http://riyanto04.wordpress.com

You might also like