Quantcast
Channel: MCS Electronics Forum
Viewing all articles
Browse latest Browse all 20599

BASCOM-AVR : Print HEX values UART : REPLY

$
0
0
Hi all I have been playing and trying lots of things.. But i can not seem to find what goes wrong here.. I have written a little description in the code. [code:1:092b55df09] '$sim $regfile = "m128def.dat" $crystal = 11059200 $hwstack = 128 $swstack = 128 $framesize = 128 Waitms 100 Config Com1 = 4800 , Synchrone = 0 , Parity = None , Stopbits = 2 , Databits = 8 , Clockpol = 0 Config Com2 = 4800 , Synchrone = 0 , Parity = None , Stopbits = 2 , Databits = 8 , Clockpol = 0 Open "com1:" For Binary As #1 Open "com2:" For Binary As #2 ' if display is used Config Lcd = 20 * 4 Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E = Portc.3 , Rs = Portc.2 Cursor Off Noblink Cls Waitms 500 Config Portf = Input : Toets1 Alias Pinf.0 Dim Freq1 As Long 'in Hz Dim Readcat1 As Long Dim Readcat2 As Long Dim Rx1(5) As Byte Declare Sub Send_freq(byval Freq As Long , Byval Port As Byte) ' UPDATE freq Declare Sub Disp_freq(byval Freq As Long , Byval Row As Byte) 'UPDATE LCD if used Declare Sub Read_freq(byval Port As Byte) Dim Downlink_freq As Long Dim Downlink_freq_temp As Long Dim Uplink_freq As Long Dim Uplink_freq_temp As Long Dim Firstboot As Byte Dim Offset As Long Dim Plusmin As Byte Firstboot = 1 '========== START ========== Do Call Read_freq(0) 'Reads the downlink frequency Downlink_freq = Readcat1 If Firstboot = 1 Then Downlink_freq_temp = Downlink_freq Firstboot = 0 End If Locate 1 , 1 : Lcd Downlink_freq While Toets1 = 1 : Wend While Toets1 = 0 : Wend Waitms 500 '========= Here i have a wrong readout after "SETUPLINK ROUTINE" has run, other wise it reads out fine loop after loop 'Normal readout for example: 432112233, but when it goes wrong, it returns a shorter value like: 43211223 'What can be wrong here? Call Read_freq(1) 'Reads the uplink frequency Uplink_freq = Readcat2 Locate 2 , 1 : Lcd Uplink_freq While Toets1 = 1 : Wend While Toets1 = 0 : Wend Waitms 500 '"SETUPLINK ROUTINE" '============= IF This routine has run,, the readout from above goes wrong.. If Downlink_freq <> Downlink_freq_temp Then 'Checking if the downlink frequency has changed, if so proceed If Downlink_freq < Downlink_freq_temp Then 'if the downlink freq is lower then the Temp freq, then calculate offset - or +, and set a bit for it. Offset = Downlink_freq_temp - Downlink_freq Plusmin = 0 Elseif Downlink_freq > Downlink_freq_temp Then Offset = Downlink_freq - Downlink_freq_temp Plusmin = 1 Else Offset = 0 End If Locate 3 , 1 : Lcd Offset ; " " Downlink_freq_temp = Downlink_freq_temp 'update the new temp frequency While Toets1 = 1 : Wend While Toets1 = 0 : Wend Waitms 500 If Plusmin = 0 Then 'Check if the offset was lower or higher, and increase or decrease the new uplink frequency and put it in a new temp variable Uplink_freq_temp = Uplink_freq - Offset Elseif Plusmin = 1 Then Uplink_freq_temp = Uplink_freq + Offset End If 'clear the original uplink freq variable.. Uplink_freq = 0 While Toets1 = 1 : Wend While Toets1 = 0 : Wend Waitms 500 Locate 4 , 1 : Lcd Uplink_freq_temp Call Send_freq(uplink_freq_temp , 1) 'Send the new uplink frequency to the uplink radio Readcat1 = 0 Readcat2 = 0 Uplink_freq_temp = 0 While Toets1 = 1 : Wend While Toets1 = 0 : Wend Waitms 500 End If Cls Loop Close #2 Close #1 End ' if display is used Sub Disp_freq(byval Freq As Long , Byval Row As Byte) Local Str_dispfreq As String * 14 Str_dispfreq = Str(freq) Str_dispfreq = Format(str_dispfreq , "000.000000") + " Mhz" If Row = 0 Then Locate 1 , 1 Elseif Row = 1 Then Locate 2 , 1 End If Lcd Str_dispfreq End Sub Sub Read_freq(byval Port As Byte) Local Str_readfreq As String * 14 Local Readcommand As Byte Local Freqread As Long Readcommand = &H03 'Read VFO command If Port = 0 Then Printbin #1 , 0 ; 0 ; 0 ; 0 ; Readcommand ; $timeout = 1000000 Inputbin #1 , Rx1(1) , 5 Elseif Port = 1 Then Printbin #2 , 0 ; 0 ; 0 ; 0 ; Readcommand ; $timeout = 1000000 Inputbin #2 , Rx1(1) , 5 End If Str_readfreq = Bcd(rx1(1)) Str_readfreq = Str_readfreq + Bcd(rx1(2)) Str_readfreq = Str_readfreq + Bcd(rx1(3)) Str_readfreq = Str_readfreq + Bcd(rx1(4)) Freqread = Val(str_readfreq) Freqread = Freqread * 10 If Port = 0 Then Readcat1 = Freqread Elseif Port = 1 Then Readcat2 = Freqread End If Freqread = 0 Str_readfreq = "" End Sub '_freq is a long and the frequency value is in Hz 'split freq into 4 bcd pairs '100/10MHZ 1MHZ/100KHz 10/1KHz 100/10Hz Sub Send_freq(byval Freq As Long , Byval Port As Byte) Local Write_command As Byte : Write_command = &H01 Local L As Long Local F As Byte Local F1 As Byte Local F2 As Byte Local F3 As Byte Local F4 As Byte L = Freq / 10000000 F = L F1 = Makebcd(f) Freq = Freq Mod 10000000 L = Freq / 100000 F = L F2 = Makebcd(f) Freq = Freq Mod 100000 L = Freq / 1000 F = L F3 = Makebcd(f) Freq = Freq Mod 1000 L = Freq / 10 F = L F4 = Makebcd(f) ' 'sent to FT-817 If Port = 0 Then Printbin #1 , F1 ; F2 ; F3 ; F4 ; Write_command ' '100/10MHZ 1MHZ/100KHz 10/1KHz 100/10Hz Command Elseif Port = 1 Then Printbin #2 , F1 ; F2 ; F3 ; F4 ; Write_command ' '100/10MHZ 1MHZ/100KHz 10/1KHz 100/10Hz Command End If End Sub [/code:1:092b55df09]

Viewing all articles
Browse latest Browse all 20599

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>