hallo1 Sedikit bagi-bagi ilmu memprogram microkontroler seri MCS51 menggunakan Bascom8051, karena rata-rata di forum ini kebayakan hoby RF / Transmitter sy akan ide1 mencontohkan koding untuk PLL Veronica,
yoooo wesssss langsung gak usah banyak konek1 mengeluh langsung praktekkkkkkkkk corong1
Hardwer Utama yg dibutuhkan
-
AT89S52 : Microkontroler
-
24C02 : EEPROM
-
LCD 16x2 : Display
gak akan sampe 100rb kalkulasi1
Softwer
-
Bascom8051 : Coding dan Basic Compiler
-
Proteus : Simulator
Rangkaian yg digunakan
langsung ketik coding dibawah ini .........
$regfile = "8052.DAT"
$crystal = 12000000
' konfigurasi pin LCD 16 x 2
Config Lcdpin = Pin , Db4 = P2.4 , Db5 = P2.5 , Db6 = P2.6 , Db7 = P2.7 , E = P2.3 , Rs = P2.2
Config Lcd = 20 * 2
' konfigurasi pin EEPROM 24C02
Config Scl = P2.0
Config Sda = P2.1
' alamat write/read control EEPROM 24C02
Const Adresw = &HAE
Const Adresr = &HAF
' alamat penyimpanan data freq
Const Adresl = &H01
Const Adresh = &H02
' batas frequensi
Const Fmax = 1080
Const Fmin = 875
' carakter panah LCD
Deflcdchar 0 , 32 , 4 , 2 , 31 , 2 , 4 , 32 , 32
Deflcdchar 1 , 32 , 4 , 8 , 31 , 8 , 4 , 32 , 32
' variabel EPROM 24C02
Dim Data_adres As Byte
Dim Data_value As Byte
' variabel pll
Dim Lock_flag As Bit
Dim Set_flag As Bit
Dim Freq As Word
' matikan cursor pada LCD
' lalu bersihkan layar
Cursor Off Noblink
Cls
' pemanis LCD
Locate 1 , 1
Lcd "FREQ"
Locate 1 , 14
Lcd "MHz"
Locate 2 , 16
Lcd Chr(0)
Locate 2 , 1
Lcd Chr(1)
' isi loock flag
Lock_flag = Not P0.3
' load data awal
Gosub Load_freq
Gosub Freq_limit
Gosub Write_veronica
Gosub Freq_to_lcd
' main loop
Do
Debounce P0.0 , 0 , Freq_up , Sub
Debounce P0.1 , 0 , Freq_set , Sub
Debounce P0.2 , 0 , Freq_dw , Sub
Gosub Lock_detect
Loop
End
' deteksi lock
Lock_detect:
If P0.3 <> Lock_flag Then
Lock_flag = P0.3
If Set_flag = 1 Then
Locate 2 , 4
Lcd " SET FREQ "
Else
If Lock_flag = 0 Then
Locate 2 , 4
Lcd " PLL LOCK "
Else
Locate 2 , 4
Lcd "PLL UNLOCK"
End If
End If
End If
Return
' frekuensi naik
Freq_up:
If Set_flag = 1 Then
Do
Freq = Freq + 1
Gosub Freq_limit
Gosub Freq_to_lcd
Waitms 100
Loop Until P0.0 = 1
Gosub Write_veronica
End If
Return
' frekuensi turun
Freq_dw:
If Set_flag = 1 Then
Do
Freq = Freq - 1
Gosub Freq_limit
Gosub Freq_to_lcd
Waitms 100
Loop Until P0.2 = 1
Gosub Write_veronica
End If
Return
' set/enter frekuensi
Freq_set:
If Set_flag = 0 Then
Set_flag = 1
Else
Gosub Save_freq
Set_flag = 0
End If
Lock_flag = Not P0.3
Return
' batas atas dan bawah frekuensi
Freq_limit:
If Freq > Fmax Then Freq = Fmin
If Freq < Fmin Then Freq = Fmax
Return
' tampilkan frekuesni ke LCD
Freq_to_lcd:
Dim Str_freq As String * 4
Dim Str_len As Byte
Dim Str_1 As String * 3
Dim Str_2 As String * 1
Dim Str_3 As String * 1
Dim Str_lcd As String * 5
Str_freq = Str(freq)
Str_len = Len(str_freq)
If Str_len = 4 Then
Str_1 = Left(str_freq , 3)
Str_2 = ""
Else
Str_1 = Left(str_freq , 2)
Str_2 = " "
End If
Str_3 = Right(str_freq , 1)
Str_lcd = Str_2 + Str_1 + "," + Str_3
Locate 1 , 7
Lcd Str_lcd
Erase Str_freq
Erase Str_len
Erase Str_1
Erase Str_2
Erase Str_3
Erase Str_lcd
Return
' set data untuk veronica
Write_veronica:
Dim Tfreq As Word
P1 = Low(tfreq)
P3 = High(tfreq)
Erase Tfreq
Return
' simpan data ke EEPROM 24C02
Eeprom_write:
I2cstart
I2cwbyte Adresw
I2cwbyte Data_adres
I2cwbyte Data_value
I2cstop
Waitms 10
Return
' baca data ke EEPROM 24C02
Eeprom_read:
I2cstart
I2cwbyte Adresw
I2cwbyte Data_adres
I2cstart
I2cwbyte Adresr
I2crbyte Data_value , 9
I2cstop
Waitms 10
Return
' simpan frekuensi ke EEPROM 24C02
Save_freq:
Dim Datal As Byte
Dim Datah As Byte
Datal = Low(freq)
Data_adres = Adresl
Data_value = Datal
Gosub Eeprom_write
Datah = High(freq)
Data_adres = Adresh
Data_value = Datah
Gosub Eeprom_write
Erase Datal
Erase Datah
Return
' baca frekuensi ke EEPROM 24C02
Load_freq:
Dim Str_freq As String * 4
Dim Str_l As String * 2
Dim Str_h As String * 2
Data_adres = Adresl
Gosub Eeprom_read
Str_l = Hex(data_value)
Data_adres = Adresh
Gosub Eeprom_read
Str_h = Hex(data_value)
Str_freq = Str_h + Str_l
Freq = Hexval(str_freq)
Erase Str_freq
Erase Str_l
Erase Str_h
Return
ok gimana merasa susah ato gampang, yg masih binggung silahkan tanya . . . . . . yg udah jago bantu koreksi yah . . . . .