LAMPIRAN

Listing program mikrokontroler

#include<avr/io.h>
#include<avr/interrupt.h>
#include<compat/deprecated.h>
#include<avr/eeprom.h>

#define NILAI_SUB 42
#define NILAI_DETIK 10
#define NILAI_MENIT 1  

unsigned char subdetik,detik,menit,sign=0;
unsigned int EEMEM mydata[511],sum;
unsigned int eeprom_read_word(const unsigned int *addr);
unsigned long data_count1,data_count0,data_count_total;
unsigned int nm,i,kar,hitung0;
void eeprom_write_word (unsigned int *addr, unsigned int value);

void init_serial(void)
{

UCSRB=((1<<RXCIE)|(1<<RXEN)|(1<<TXEN));
UCSRC=((1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0));
UBRRH=0;
UBRRL=17;
}

void transmit_serial(unsigned char nilai)
{

while(bit_is_clear(UCSRA,UDRE));
UDR=nilai;

}

void cek_tombol(void)
{

if(bit_is_clear(PINA,0))
      {
     
            for(i=0;i<nm;i++)
                  {
                        kar=eeprom_read_word(&mydata[i]);
                        transmit_serial(kar);                    
                  }
                  nm=0;
                  eeprom_write_word(&sum,nm);
      }
if(bit_is_clear(PINA,1))
      {
            nm=0;
            eeprom_write_word(&sum,nm);
      }
}

// sub program timer
ISR(TIMER2_OVF_vect)
{
//cek_tombol();
subdetik=subdetik-1;
if(subdetik==0)
      {
            subdetik=NILAI_SUB;
            detik=detik-1;
            if(detik==0)
                  {
                        detik=NILAI_DETIK;
                        menit=menit-1;
                        if(menit==0)
                              {
                                    menit=NILAI_MENIT;
                                    TCCR2=((1<<CS22)|(1<<CS21)|(1<<CS20));
                                    sign=1;
                              }
                  }
      }
TIFR|=(1<<TOV2);
}

// sub program register Usart pin input
ISR(USART_RXC_vect)
{
if(UDR=='Y')
      {
            transmit_serial('Y');
      }
if(UDR=='S')
      {

            for(i=0;i<nm;i++)
                  {

                        kar=eeprom_read_word(&mydata[i]);
                        transmit_serial(kar);
                       
                  }
                  nm=0;
                  eeprom_write_word(&sum,nm);

      }

if(UDR=='R')
      {
            nm=0;
            eeprom_write_word(&sum,nm);
      }

UCSRA=(1<<RXC);

}

// sub program interupt timer

ISR(TIMER0_OVF_vect)
{
hitung0++;

TIFR|=(1<<TOV0);
}


// program utama

int main(void)
{
      // inisialisasi pin avr
DDRA=0;
DDRD=0xfe;
DDRB=0xfc;
PORTB=0xff;
PORTA=0xff;

      // aktifkan satu timer
TIMSK=(1<<TOIE2);

      // pengisian nilai2 variabel
subdetik=NILAI_SUB;
detik=NILAI_DETIK;
menit=NILAI_MENIT;
hitung0=0;

      // pengaktifan register counter
TCCR0=(1<<CS02)|(1<<CS01)|(1<<CS00);

TCCR1A=0;
TCCR1B=(1<<CS12)|(1<<CS11)|(1<<CS10);

TCCR2=((1<<CS22)|(1<<CS21)|(1<<CS20));

      // panggil sub program inisialisasi port serial
init_serial();

hitung0=0;
data_count1=0;
data_count0=0;
data_count_total=0;

nm=eeprom_read_word(&sum);
sign=0;

      // pengiriman data dan pembacaan data

sei();
while(1)
{


      // pengecekan apakah masih ada data di eeprom, jika ada terus kirim,
      // jika tidak beritahu reggister data habis

sign=0;
while(sign==0);
data_count0= (hitung0 * 256) + TCNT0;
data_count1=TCNT1;
data_count_total = data_count0 + data_count1;
TCNT0=0;
TCNT1=0;
eeprom_write_word(&mydata[nm],data_count_total);
eeprom_write_word(&sum,nm);
nm++;

}
return 0;
}



LAMPIRAN


Listing program Visual Basic

Dim datax As String
Dim sum As Integer
Dim vx As Integer
Dim buffering As String
Dim pathfile As String
Dim db As Connection
Dim ambil As Recordset
Dim ambil2 As Recordset
Dim sdata(30000) As Single
Dim values1() As Integer
Dim nil As Integer
Dim hit As Integer
'Dim intens As Double
Private Sub cmdambil_Click()
serial.Output = "S"
End Sub

Private Sub cmddelete_Click()

msg = MsgBox("Anda yakin akan Menghapus SEMUA DATA...?", vbOKCancel, "Konfirmasi")
If msg = vbCancel Then Exit Sub
If ambil.RecordCount <> 0 Then ambil.MoveFirst
While ambil.EOF = False
ambil.Delete
ambil.MoveNext
Wend
sum = 0
End Sub

Private Sub cmdexit_Click()
Unload Me
End
End Sub

Private Sub cmdok_Click()
connecting
End Sub

Private Sub cmdprinting_Click()
On Error GoTo kensel
chart.EditCopy
Printer.Print " "
Printer.PaintPicture Clipboard.GetData(), 0, 0
Printer.EndDoc
kensel:
End Sub

Private Sub cmdreset_Click()
serial.Output = "R"
End Sub

Private Sub cmdsavepicture_Click()
Save_Graph
End Sub
Private Sub Command1_Click()
msg = MsgBox("Anda yakin memasukkan tanggal baru", vbOKCancel, "Konfirmasi")
If msg = vbCancel Then Exit Sub

lbltime.Caption = Now
If ambil2.RecordCount <> 0 Then ambil2.MoveFirst
While ambil2.EOF = False
ambil2.Delete
ambil2.MoveNext
Wend
    ambil2.AddNew
    ambil2!onDATE = Now
End Sub

Private Sub dg_hujan_Click()

End Sub

Private Sub Form_Load()
Set db = New Connection
    db.CursorLocation = adUseClient
    db.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\data_counting.mdb;"
    Set ambil = New Recordset
    ambil.Open "select Nomor, Waktu,Intensitas from COUNTS", db, adOpenStatic, adLockOptimistic
    Set dg_hujan.DataSource = ambil

    Set ambil2 = New Recordset
    ambil2.Open "select onDATE from tanggal", db, adOpenStatic, adLockOptimistic
    Set dg_tanggal.DataSource = ambil2
    dg_tanggal.Width = 10000
    If ambil2.RecordCount <> 0 Then
    ambil2.MoveFirst
    lbltime.Caption = ambil2!onDATE
    End If

    With cmbport
.AddItem "COM 1"
.AddItem "COM 2"
.AddItem "COM 3"
.AddItem "COM 4"
.AddItem "COM 5"
.AddItem "COM 6"
.AddItem "COM 7"
.AddItem "COM 8"
.AddItem "COM 9"
.AddItem "COM 10"
.AddItem "COM 11"
.AddItem "COM 12"
.AddItem "COM 13"
.AddItem "COM 14"
.AddItem "COM 15"
End With
With cmbbaud
.AddItem "4800"
.AddItem "9600"
.AddItem "19200"
.AddItem "38400"
.AddItem "57600"
End With
cmbport.ListIndex = 3
cmbbaud.ListIndex = 3
nomor = 1
buffering = ""

If ambil.RecordCount <> 0 Then
    ambil.MoveLast
    sum = Val(ambil!nomor)
Else
    sum = 0
End If

chart.Plot.UniformAxis = False
chart.Plot.Axis(VtChAxisIdX).ValueScale.Auto = True
chart.Plot.Axis(VtChAxisIdY).ValueScale.Auto = True
chart.Plot.Axis(VtChAxisIdX).AxisTitle.Text = "WAKTU"
chart.Plot.Axis(VtChAxisIdY).AxisTitle.Text = "INTENSITAS"
chart.Title.Text = " Grafik Waktu Terhadap Intensitas "
'nil = 0
cmdambil.Enabled = False
cmdreset.Enabled = False
hit = 0
End Sub

Sub connecting()
On Error GoTo kensel

If cmbport.List(cmbport.ListIndex) = "COM 1" Then numerik = 1
If cmbport.List(cmbport.ListIndex) = "COM 2" Then numerik = 2
If cmbport.List(cmbport.ListIndex) = "COM 3" Then numerik = 3
If cmbport.List(cmbport.ListIndex) = "COM 4" Then numerik = 4
If cmbport.List(cmbport.ListIndex) = "COM 5" Then numerik = 5
If cmbport.List(cmbport.ListIndex) = "COM 6" Then numerik = 6
If cmbport.List(cmbport.ListIndex) = "COM 7" Then numerik = 7
If cmbport.List(cmbport.ListIndex) = "COM 8" Then numerik = 8
If cmbport.List(cmbport.ListIndex) = "COM 9" Then numerik = 9
If cmbport.List(cmbport.ListIndex) = "COM 10" Then numerik = 10
If cmbport.List(cmbport.ListIndex) = "COM 11" Then numerik = 11
If cmbport.List(cmbport.ListIndex) = "COM 12" Then numerik = 12
If cmbport.List(cmbport.ListIndex) = "COM 13" Then numerik = 13
If cmbport.List(cmbport.ListIndex) = "COM 14" Then numerik = 14
If cmbport.List(cmbport.ListIndex) = "COM 15" Then numerik = 15

If serial.PortOpen = False Then
    serial.CommPort = numerik
    serial.RThreshold = 1  '    setelah 1 karakter langsung tampil
    serial.InputLen = 1    '    tampil setiap 1 karakter
    serial.Settings = cmbbaud.List(cmbbaud.ListIndex) & ",N,8,1"
    serial.PortOpen = True
    cmdok.Caption = "Disconnect"
    serial.Output = "Y"
    Timer1.Enabled = True
Else
serial.PortOpen = False
cmdok.Caption = "Connect"
cmdambil.Enabled = False
cmdreset.Enabled = False
End If
kensel:

End Sub

Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)

End Sub

Private Sub serial_OnComm()
On Error GoTo X
If serial.CommEvent <> comEventFrame Then
    If serial.CommEvent = comEvReceive Then
        DoEvents
        datax = serial.Input
        'Text1.Text = Text1.Text & Asc(datax) & vbCrLf
       
        If cmdambil.Enabled = False Then
            cmdambil.Enabled = True
            cmdreset.Enabled = True
            Exit Sub
        End If
        sum = sum + 1
        sdata(sum) = (Asc(datax) * (11.4 / 200.96)) + sdata(sum - 1)

    ambil.AddNew
    ambil!nomor = sum
    ambil!Waktu = sum * 15
    ambil!Intensitas = (sdata(sum))
         Graphics                  
    End If
End If
X:
hit = 0
End Sub

Sub Graphics()
If ambil.RecordCount <> 0 Then numpoints = ambil.RecordCount
If ambil.RecordCount = 0 Then Exit Sub
ReDim values1(1 To numpoints, 1 To 2)
    For vx = 1 To numpoints
        values1(vx, 1) = (vx * 15)
        values1(vx, 2) = sdata(vx)
        
    Next vx
   
        chart.chartType = VtChChartType2dXY
        chart.RowCount = numpoints
        chart.ColumnCount = 2
        chart.ChartData = values1
End Sub

Sub Save_Graph()
Dim strsavefile As String
With dialog ' CommonDialog object
.Filter = "Pictures (*.wmf)|*.wmf"
.DefaultExt = "wmf"
'.CancelError = True
.ShowSave
strsavefile = .FileName
If strsavefile = "" Then Exit Sub
End With
chart.EditCopy
SavePicture Clipboard.GetData(vbCFMetafile), strsavefile

End Sub

Private Sub Timer1_Timer()
Label3.Caption = hit
hit = hit + 1
End Sub

Post a Comment

Top