|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2010-1-27 19:23:55
|
显示全部楼层
$regfile = "M8DEF.DAT"
'$regfile = "attiny2313.DAT"
$crystal = 1000000
Config Lcdpin = Pin , Db4 = Portc.0 , Db5 = Portc.1 , Db6 = Portc.2 , Db7 = Portc.3 , E = Portb.1 , Rs = Portb.0
Config Lcd = 24 * 2
Cls : Cursor Off
Config Scl = Portc.5
Config Sda = Portc.4
Config I2cdelay = 400
Config Portb.0 = Output
Config Portb.2 = Input
Config Portb.3 = Input
Config Portb.4 = Input
Config Portb.5 = Input
Config Portd.4 = Output
Portb.2 = 1
Portb.3 = 1
Portb.4 = 1
Portb.5 = 1
K_dn Alias Pinb.2
K_ok Alias Pinb.3
K_ex Alias Pinb.4
K_up Alias Pinb.5
Led Alias Portd.4
Dim Bufout(5) As Word , Bufin(5) As Byte , Sd As Byte , Dat As Byte , Pll(2) As Long , Temp As Long , Tea_auto As Bit
Dim Tea_mute As Bit , Tea_r_ready As Bit , Tea_r_limit As Bit , Tea_r_str As Bit , Tea_r_signal As Byte , E As Byte , Tea_set As Long
Dim I As Byte , Fd100 As Integer , Fd1 As Integer , Menu(9) As String * 10 , Sl As Byte , Bt As Byte , Cg As Bit , Ken As Bit
Dim Mbuf(2) As String * 10 , Upen As Bit , Loen As Bit , Tea_mono As Bit , Emem(30) As Eram Long , Mem(30) As Long , Memsl As Byte
Dim Tea_su As Bit , Tim_k As Byte , Tim_serch As Long , Sold As Long , Logot As Long , Dangqian As Eram Long , Tmper As Long
Cg = 1 : Sl = 1 : Loen = 0 : Memsl = 1
Tmper = Dangqian
If Dangqian > 8800 Then
Tea_set = Dangqian
Else
Tea_set = 8900
End If
Waitms 200
Gosub Tea_init
Tea_mute = 1
Gosub Tea_tone
Gosub Logo
Cls
Tea_mute = 0
Gosub Tea_tone
Gosub Updmenu
Dim Sbt As Byte , Sba As Byte
Sbt = 5 : Sba = 5
Do
If Sbt <> 0 Then Gosub Update
Gosub Key
If Sbt <> 0 Then Sbt = Sbt - 1
Loop
End
Key:
If Ken = 0 Then
If K_up = 0 Then
Ken = 1 : Sl = Sl - 1 : Gosub Cmenu
Sbt = Sba
End If
If K_dn = 0 Then
Ken = 1 : Sl = Sl + 1 : Gosub Cmenu
Sbt = Sba
End If
If K_ok = 0 Then
Ken = 1
Sbt = Sba
Gosub Kopt_b
Gosub Kopt_ab
End If
If K_ex = 0 Then
Ken = 1
Sbt = Sba
Gosub Kopt_a
Gosub Kopt_ab
End If
If Sl > 8 Then Sl = 8
If Sl < 1 Then Sl = 1
End If
If K_up = 1 And K_dn = 1 And K_ok = 1 And K_ex = 1 Then
Ken = 0 : Tim_k = 0
End If
If Sl = 2 Or Sl = 3 Or Sl = 4 Then
Ken = 0
If Tim_k < 6 Then Waitms 200
Waitms 1
End If
'Locate 2 , 16 : Lcd Sl
Return
Updmenu:
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\
If Tea_mute = 0 Then
Menu(1) = "Normal"
Else
Menu(1) = "Mute"
End If
If Tea_mono = 0 Then
Menu(7) = "Stereo"
Else
Menu(7) = "Mono"
End If
Menu(2) = "PLL1: - +"
Menu(3) = "PLL10: - +"
Menu(4) = "PLL100:- +"
Menu(5) = "AutoSearch"
Menu(8) = "ADVSearch"
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Return
Cmenu:
Locate 1 , 14 : Lcd " "
Locate 2 , 14 : Lcd " "
Cg = 1 : Gosub Updmenu : Gosub Update
Return
Update:
Gosub Tea_r
If Upen = 0 Then
Deflcdchar 0 , 31 , 10 , 4 , 4 , 4 , 4 , 4 , 4 'ant
Deflcdchar 1 , 32 , 32 , 1 , 1 , 5 , 5 , 21 , 21 ' SIG
Deflcdchar 3 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 ' |
Deflcdchar 4 , 31 , 17 , 31 , 21 , 21 , 17 , 10 , 4 ' UTUNE
Deflcdchar 5 , 31 , 31 , 17 , 27 , 27 , 31 , 14 , 4 ' TUNE
Deflcdchar 6 , 3 , 7 , 29 , 25 , 29 , 7 , 3 , 32 'SP
Upen = 1 : Loen = 0
End If
Locate 1 , 1 : Lcd Chr(0); 'ANT
If Tea_r_signal > 4 Then Lcd Chr(1)
If Tea_r_signal <= 4 Then Lcd " "
Locate 2 , 1
If Tea_r_str = 1 Then Lcd Chr(5)
If Tea_r_str = 0 Then Lcd Chr(4)
Locate 1 , 9
If Tea_r_str = 1 Then Lcd "STE"
If Tea_r_str = 0 Then Lcd "MON"
Locate 1 , 4
If Tea_mute = 1 Then Lcd Chr(6) ; "x"
If Tea_mute = 0 Then Lcd Chr(6) ; ")"
Gosub Fj
Locate 2 , 2 : Lcd "=" ; Fd100 ; "." ; Fd1 ; " "
Locate 2 , 9 : Lcd "MHZ"
Locate 1 , 12 : Lcd "|"
Locate 2 , 12 : Lcd "|"
If Cg = 1 Then
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\单次
If Sl = 1 Or Sl = 2 Then
Mbuf(1) = Menu(1)
Mbuf(2) = Menu(2)
End If
If Sl = 3 Or Sl = 4 Then
Mbuf(1) = Menu(3)
Mbuf(2) = Menu(4)
End If
If Sl = 5 Or Sl = 6 Then
Mbuf(1) = Menu(5)
Mbuf(2) = Menu(6)
End If
If Sl = 7 Or Sl = 8 Then
Mbuf(1) = Menu(7)
Mbuf(2) = Menu(8)
End If
If Sl = 9 Then
Mbuf(1) = Menu(9)
Mbuf(2) = ""
End If
Locate 1 , 14 : Lcd Mbuf(1)
Locate 2 , 14 : Lcd Mbuf(2)
If Sl = 5 Or Sl = 6 Then
Mbuf(1) = Menu(5)
Locate 2 , 14 : Lcd "EEPROM:" ; Memsl
End If
If Sl = 1 Or Sl = 3 Or Sl = 5 Or Sl = 7 Then
Locate 1 , 13 : Lcd "<" : Locate 1 , 24 : Lcd ">"
Else
Locate 1 , 13 : Lcd " " : Locate 1 , 24 : Lcd " "
End If
If Sl = 2 Or Sl = 4 Or Sl = 6 Or Sl = 8 Then
Locate 2 , 13 : Lcd "<" : Locate 2 , 24 : Lcd ">"
Else
Locate 2 , 13 : Lcd " " : Locate 2 , 24 : Lcd " "
End If
Cg = 0
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
End If
Return
Fj:
Fd100 = Pll(1) / 100
Fd1 = Fd100 * 100
Fd1 = Pll(1) - Fd1
Return
Loading:
'Cls
If Loen = 0 Then
Deflcdchar 0 , 31 , 25 , 19 , 19 , 7 , 7 , 14 , 31 ' replace ? with number (0-7)
Deflcdchar 1 , 31 , 28 , 25 , 25 , 19 , 19 , 7 , 31 ' replace ? with number (0-7)
Deflcdchar 2 , 31 , 14 , 28 , 28 , 25 , 25 , 19 , 31 ' replace ? with number (0-7)
Deflcdchar 3 , 31 , 7 , 14 , 14 , 28 , 28 , 25 , 31 ' replace ? with number (0-7)
Deflcdchar 4 , 31 , 3 , 7 , 7 , 14 , 14 , 28 , 31 ' replace ? with number (0-7)
Loen = 1 : Upen = 0
End If
Locate 1 , 5 : Lcd Chr(i) ; Chr(i) ; Chr(i) ; Chr(i) ; Chr(i) ; Chr(i) ; Chr(i) ; Chr(i) ; Chr(i) ; Chr(i) ; Chr(i) ; Chr(i) ; Chr(i) ; Chr(i) ; Chr(i) ;
I = I + 1
If I = 5 Then I = 0
Waitms 200
Return
Kopt_ab:
If Memsl > 30 Then Memsl = 30
If Memsl < 1 Then Memsl = 1
Tim_k = Tim_k + 1
Gosub Tea_tone : Gosub Cmenu : Tea_auto = 0
If Sl = 8 Then
Gosub Schmd
End If
Return
Kopt_a:
If Sl = 1 Then Tea_mute = 1
If Sl = 7 Then Tea_mono = 1
If Sl = 2 Then
Tea_set = Tea_set + 1
End If
If Sl = 3 Then
Tea_set = Tea_set + 10
End If
If Sl = 4 Then
Tea_set = Tea_set + 100
End If
If Sl = 5 Then
Tea_su = 1 : Tea_auto = 1 : Tea_set = Tea_set + 90
If Tea_set < 10900 Then Gosub Tea_tone
Tea_su = 1 : Tea_auto = 0
End If
If Sl = 6 Then
Memsl = Memsl + 1
Tea_set = Emem(memsl)
If Tea_set < 8800 Then
Memsl = Memsl - 1
Tea_set = Emem(memsl)
End If
Gosub Tea_tone
End If
Return
Kopt_b:
If Sl = 1 Then Tea_mute = 0
If Sl = 7 Then Tea_mono = 0
If Sl = 2 Then
Tea_set = Tea_set - 1
End If
If Sl = 3 Then
Tea_set = Tea_set - 10
End If
If Sl = 4 Then
Tea_set = Tea_set - 100
End If
If Sl = 5 Then
Tea_su = 0 : Tea_auto = 1 : Tea_set = Tea_set - 90
If Tea_set > 800 Then Gosub Tea_tone
Tea_su = 0 : Tea_auto = 0
End If
If Sl = 6 Then
Memsl = Memsl - 1
Tea_set = Emem(memsl)
If Tea_set > 8800 Then Gosub Tea_tone
End If
Return
Schmd:
Tea_set = 8900 : Cls
Tim_serch = 0 : Memsl = 0 : Loen = 0
Tea_su = 1 : Tea_auto = 1 : Gosub Tea_tone : Waitms 10 : Gosub Tea_r : Gosub Fj
Do
Do
Gosub Loading
Gosub Tea_r
Gosub Fj
Tim_serch = Tim_serch + 1
If Tim_serch = 5 Then
Tim_serch = 0 : Exit Do '
End If
If Sold = Fd100 Or Tea_r_ready = 1 Then Exit Do
Loop
Waitms 100
If Sold <> Fd100 Then Memsl = Memsl + 1
Emem(memsl) = Pll(1)
Tea_set = Tea_set + 100
Tea_su = 1 : Tea_auto = 1
Gosub Fj : Sold = Fd100
Gosub Tea_tone
Waitms 100
Locate 2 , 1 : Lcd ; "Searching for:" ; Memsl ; " " ; Fd100 ; "." ; Fd1 ;
If Pll(1) > 10800 Or Memsl > 29 Then Exit Do
Loop
Tea_su = 1 : Tea_auto = 0 : Memsl = 1
Pll(1) = Emem(1) : Gosub Tea_tone
Cls : Gosub Cmenu
Return
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Tea_tone:
Pll(1) = Tea_set
Pll(2) = Pll(1) * 10
Pll(2) = Pll(2) - 225
Pll(2) = Pll(2) * 4000
Pll(2) = Pll(2) / 32768
Bufout(1) = Pll(2) / 256
If Tea_mute = 1 Then Bufout(1) = Bufout(1) + 128
If Tea_auto = 1 Then Bufout(1) = Bufout(1) + 64
Bufout(3) = &B00100000
If Tea_su = 1 Then Bufout(3) = Bufout(3) + 128
If Tea_mono = 1 Then Bufout(3) = Bufout(3) + 8
Temp = Bufout(1) * 256
Bufout(2) = Pll(2) - Temp
Gosub Tea_w
Dangqian = Tea_set
Return
Tea_init:
Cls
Tea_mute = 1
Bufout(3) = &B10100000
Bufout(4) = &B10010110
Bufout(5) = &B00000000
Gosub Tea_tone
Return
Tea_w:
Led = 1
I2cinit : I2cstart
I2cwbyte &B11000000
For Sd = 1 To 5
Dat = Bufout(sd)
Waitus 100
I2cwbyte Dat
Next Sd
I2cstop : Waitus 100
Led = 0
Return
Tea_r:
Tea_r_str = 0 : Tea_r_ready = 0 : Tea_r_signal = 0
I2cinit : I2cstart
I2cwbyte &B11000001
For Sd = 1 To 4
Waitus 100
I2crbyte Bufin(sd) , Ack
Next Sd
I2crbyte Bufin(5) , Nack
I2cstop : Waitus 100
Pll(1) = Bufin(1) / 128
If Pll(1) = 1 Then
Bufin(1) = Bufin(1) - 128
Tea_r_ready = 1
End If
Pll(2) = Bufin(1) * 256
Pll(2) = Pll(2) + Bufin(2)
Pll(2) = Pll(2) * 32768
Pll(2) = Pll(2) / 4000
Pll(2) = Pll(2) + 225
Pll(1) = Pll(2) / 10
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Pll(2) = Bufin(3) / 128
If Pll(2) = 1 Then Tea_r_str = 1
Pll(2) = Bufin(4) / 128
If Pll(2) = 1 Then Tea_r_signal = Tea_r_signal + 8
Pll(2) = Bufin(4) / 64
If Pll(2) = 1 Then Tea_r_signal = Tea_r_signal + 4
Pll(2) = Bufin(4) / 32
If Pll(2) = 1 Then Tea_r_signal = Tea_r_signal + 2
Pll(2) = Bufin(4) / 16
If Pll(2) = 1 Then Tea_r_signal = Tea_r_signal + 1
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Return
Logo:
Locate 2 , 6
Do
Gosub Loading
If Logot = 35 Then Exit Do
If Logot = 10 Then
Locate 2 , 7 : Lcd "SDoux Radio."
End If
Logot = Logot + 1
Loop
Return |
|