Tengah malam yang sunyi dan menyejukkan jiwa, kali ini saya akan menjelaskan mengenai bagaimana cara mengakses device VINCULUM VNC1L USB Host Controller dengan menggunakan mikrokontroller ATMega16 dengan Crystal 12Mhz dan bahasa Bascom AVR, memang bagi kaum awam akan terasa sulit namun saya akan berusaha menjelaskannya sedetail mungkin sehingga bisa dicerna oleh siapa saja, Alat yang akan dibuat kali ini yaitu terdapat sebuah tombol yang akan memerintahkan mikrokontroller untuk menyimpan data ke Flashdisk, kalau biasanya penyimpanan / data logger menggunakan SD card, sekarang bisa menggunakan Flashdisk. Spesifikasi Flashdisk yang dipakai yaitu FAT32 dengan ukuran 4GB. data yang akan ditampung oleh flashdisk bisa diatur melalui file todo.txt, pada contoh data yang tersimpan adalah 6 x 8 data, bisa saja dirubah menjadi 1 x 1 atau 2 x 2 juga bisa, tergantung kebutuhan. yang harus diperhatikan pada alat ini yaitu bagaimana memasukkan firmware Vinculum dan bagaimana cara mengakses file todo.txt. Berikut adalah program, skema dan langkah-langkahnya.
1. Siapkan modul berikut
- Minimum System ATMega16, Crystal 12Mhz
- Serial Modul RS232
- Vinculum Module
2. Siapkan sebuah Flashdisk lalu format dengan FAT32
3. Download Software Firmware di link berikut LINK
4. Masukkan file berikut ke flashdisk
5. Install dengan klik dua kali VncFwMod.exe dari drive komputer
6. Cari file VDAPFUL_V03_68.ROM yang tadi dimasukkan ke Flashdisk
7. Firmware telah siap digunakan
8. Buat file.txt dengan nama "todo.txt" didalam flash disk lalu isikan seperti berikut
9. Jika sudah maka akan tampak seperti berikut (isi file dalam flashdisk)
10. Kemudian flashdisk siap digunakan
11. Program Bascom AVR
$regfile = "m16def.dat"
$crystal = 12000000
$baud = 9600
Open "comd.7:9600,8,n,1" For Output As #1
Open "comc.7:9600,8,n,1" For Input As #2
Config Lcdpin = Pin , Rs = Portc.0 , E = Portc.1 , Db4 = Portc.2
Config Lcdpin = Pin , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5
Config Lcd = 16 * 2
Cls
Cursor Off
Ddrb.0 = 0
Portb.0 = 1
Const Max_line_number = 15
Print "Ready"
Dim I As Byte
Dim Ending_loop As Byte
Dim Usb_stick_present As Byte
Dim N As Integer
Dim Ad As Integer
Dim Samples As Word
Dim Delayms As Word
Dim Channels As Word
Dim Inp_str(max_line_number) As String * 26
Dim Command_str As String * 20
Dim Vinc_str As String * 20
Dim S As String * 80
Dim S_length As Byte
Start Adc
Echo Off
Main:
Cls
Do
Command_str = ""
Gosub Execute_command
Ad = Getadc(7)
Upperline
Lcd "adc = " ; Ad
If Pinb.0 = 0 Then
Gosub Commands
End If
If Usb_stick_present = 1 Then
Print "USB stick connected"
Lowerline
Lcd "CONNECTED"
Wait 1
Else
Print "USB stick not connected"
Lowerline
Lcd "DISCONNECTED"
End If
Wait 5
Cls
Loop
Close #2
Close #1
End
Commands:
Cls
Upperline
Lcd "saving..... !!!"
Lowerline
Lcd "CONNECTED"
Wait 3
Print #1 , "Rd todo.txt" ; Chr(13) ;
Input #2 , Samples
Get #2 , I
Input #2 , Delayms
Get #2 , I
Input #2 , Channels
Get #2 , I
Input #2 , Vinc_str
Print Vinc_str ; " (file was read) " ; Samples ; " " ; Delayms ; " " ; Channels
Decr Channels
'samples = jumlah baris
'channel = panjang data tiap baris
' open the file log.txt
Print #1 , "OPW log.txt" ; Chr(13);
Input #2 , Vinc_str
Print Vinc_str ; " (file was opened)"
'write data to file
For N = 1 To Samples
S = ""
For I = 0 To Channels
Ad = Getadc(7)
S = S + Str(ad)
If I < Channels Then S = S + Chr(32) Else S = S + Chr(13) + Chr(10)
Next I
S_length = Len(s)
Print "Data " ; N ; ": " ; S ; S_length
Print #1 , "WRF " ; Str(s_length) ; Chr(13) ; S;
Input #2 , Vinc_str
Print Vinc_str ; " (data line was sent)"
Waitms Delayms
Next N
' close file
Print #1 , "CLF log.txt" ; Chr(13);
Input #2 , Vinc_str
Print Vinc_str ; " (file was closed)"
' diplay DIRECTORY on USB stick
Command_str = "DIR"
Gosub Execute_command
' diplay USB stick information
'Command_str = "IDD"
'Gosub Execute_command
' display firmware version of Vinculum
'Command_str = "FWV"
'Gosub Execute_command
Goto Main
Return
Execute_command:
I = 0
Ending_loop = 0
Print #1 , Command_str ; Chr(13);
Do
Incr I
Input #2 , Inp_str(i)
If Inp_str(i) = "D:\>" Then Set Ending_loop
If Inp_str(i) = "No Disk" Then Set Ending_loop
If Inp_str(i) = "Bad Command" Then Set Ending_loop
Loop Until Ending_loop = 1
Print
Reset Usb_stick_present
For I = 1 To Max_line_number
If Inp_str(i) <> "" Then
If Inp_str(i) = "D:\>" Then Set Usb_stick_present
Print Inp_str(i)
End If
Inp_str(i) = ""
Next I
Return
$crystal = 12000000
$baud = 9600
Open "comd.7:9600,8,n,1" For Output As #1
Open "comc.7:9600,8,n,1" For Input As #2
Config Lcdpin = Pin , Rs = Portc.0 , E = Portc.1 , Db4 = Portc.2
Config Lcdpin = Pin , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5
Config Lcd = 16 * 2
Cls
Cursor Off
Ddrb.0 = 0
Portb.0 = 1
Const Max_line_number = 15
Print "Ready"
Dim I As Byte
Dim Ending_loop As Byte
Dim Usb_stick_present As Byte
Dim N As Integer
Dim Ad As Integer
Dim Samples As Word
Dim Delayms As Word
Dim Channels As Word
Dim Inp_str(max_line_number) As String * 26
Dim Command_str As String * 20
Dim Vinc_str As String * 20
Dim S As String * 80
Dim S_length As Byte
Start Adc
Echo Off
Main:
Cls
Do
Command_str = ""
Gosub Execute_command
Ad = Getadc(7)
Upperline
Lcd "adc = " ; Ad
If Pinb.0 = 0 Then
Gosub Commands
End If
If Usb_stick_present = 1 Then
Print "USB stick connected"
Lowerline
Lcd "CONNECTED"
Wait 1
Else
Print "USB stick not connected"
Lowerline
Lcd "DISCONNECTED"
End If
Wait 5
Cls
Loop
Close #2
Close #1
End
Commands:
Cls
Upperline
Lcd "saving..... !!!"
Lowerline
Lcd "CONNECTED"
Wait 3
Print #1 , "Rd todo.txt" ; Chr(13) ;
Input #2 , Samples
Get #2 , I
Input #2 , Delayms
Get #2 , I
Input #2 , Channels
Get #2 , I
Input #2 , Vinc_str
Print Vinc_str ; " (file was read) " ; Samples ; " " ; Delayms ; " " ; Channels
Decr Channels
'samples = jumlah baris
'channel = panjang data tiap baris
' open the file log.txt
Print #1 , "OPW log.txt" ; Chr(13);
Input #2 , Vinc_str
Print Vinc_str ; " (file was opened)"
'write data to file
For N = 1 To Samples
S = ""
For I = 0 To Channels
Ad = Getadc(7)
S = S + Str(ad)
If I < Channels Then S = S + Chr(32) Else S = S + Chr(13) + Chr(10)
Next I
S_length = Len(s)
Print "Data " ; N ; ": " ; S ; S_length
Print #1 , "WRF " ; Str(s_length) ; Chr(13) ; S;
Input #2 , Vinc_str
Print Vinc_str ; " (data line was sent)"
Waitms Delayms
Next N
' close file
Print #1 , "CLF log.txt" ; Chr(13);
Input #2 , Vinc_str
Print Vinc_str ; " (file was closed)"
' diplay DIRECTORY on USB stick
Command_str = "DIR"
Gosub Execute_command
' diplay USB stick information
'Command_str = "IDD"
'Gosub Execute_command
' display firmware version of Vinculum
'Command_str = "FWV"
'Gosub Execute_command
Goto Main
Return
Execute_command:
I = 0
Ending_loop = 0
Print #1 , Command_str ; Chr(13);
Do
Incr I
Input #2 , Inp_str(i)
If Inp_str(i) = "D:\>" Then Set Ending_loop
If Inp_str(i) = "No Disk" Then Set Ending_loop
If Inp_str(i) = "Bad Command" Then Set Ending_loop
Loop Until Ending_loop = 1
Reset Usb_stick_present
For I = 1 To Max_line_number
If Inp_str(i) <> "" Then
If Inp_str(i) = "D:\>" Then Set Usb_stick_present
Print Inp_str(i)
End If
Inp_str(i) = ""
Next I
Return
13. Jika berhasil maka hasilnya akan seperti berikut (contoh)
14. VIDEO HASILNYA
No comments:
Post a Comment