SwingeyP
Member
Hello again.
Once again my terrible electronic skills are letting me down.
I have written a routine which works perfectly in simulation and with me talking to it via the PC Serial Port Terminal in OSHON. (PIC 16f628A)
The problem comes in the real world.
1) How do I get the timing right for 38400 Baud?
2) How can I tell the HRSERIN to only wait for a period of time?
I couldn't attach the code as I keep getting a HTML 500 error - I have pasted it below.
Regards - Paul
Once again my terrible electronic skills are letting me down.
I have written a routine which works perfectly in simulation and with me talking to it via the PC Serial Port Terminal in OSHON. (PIC 16f628A)
The problem comes in the real world.
1) How do I get the timing right for 38400 Baud?
2) How can I tell the HRSERIN to only wait for a period of time?
I couldn't attach the code as I keep getting a HTML 500 error - I have pasted it below.
Regards - Paul
Code:
Define CONF_WORD = 0x3f50 'internal xtal
Define CLOCK_FREQUENCY = 4
AllDigital
'Define the comms for the LCD display.
Define LCD_LINES = 4
Define LCD_CHARS = 20
Define LCD_BITS = 4
Define LCD_DREG = PORTB
Define LCD_DBIT = 4 'Use the high order bits'
Define LCD_RSREG = PORTA
Define LCD_RSBIT = 2
Define LCD_EREG = PORTA
Define LCD_EBIT = 0
Define LCD_RWREG = PORTA
Define LCD_RWBIT = 1
Define LCD_READ_BUSY_FLAG = 1
Define LCD_COMMANDUS = 5000 'delay after LCDCMDOUT, default value is 5000
Define LCD_DATAUS = 100 'delay after LCDOUT, default value is 100
Define LCD_INITMS = 20
Define SEROUT_DELAYUS = 5000
Lcdinit
'Define the bar graph display for the Power and S meter.
Lcddefchar 0, %00000, %00000, %00000, %00000, %00000, %00000, %00000, %11111
Lcddefchar 1, %00000, %00000, %00000, %00000, %00000, %00000, %11111, %11111
Lcddefchar 2, %00000, %00000, %00000, %00000, %00000, %11111, %11111, %11111
Lcddefchar 3, %00000, %00000, %00000, %00000, %11111, %11111, %11111, %11111
Lcddefchar 4, %00000, %00000, %00000, %11111, %11111, %11111, %11111, %11111
Lcddefchar 5, %00000, %00000, %11111, %11111, %11111, %11111, %11111, %11111
Lcddefchar 6, %00000, %11111, %11111, %11111, %11111, %11111, %11111, %11111
Lcddefchar 7, %11111, %11111, %11111, %11111, %11111, %11111, %11111, %11111
Dim counter As Byte
Dim dummy As Byte
Dim data(4) As Byte 'Array to store raw Data (Remember 0-3)
Dim char(8) As Byte 'Array to store the converted Chraracters for display (Remember 0-7)
Dim dataloop As Byte 'Loop for the data
Dim charloop As Byte 'loop for the characters
Dim command As Byte 'the command byte from the 917
Dim temp As Byte 'temporary variable used for conversion
Dim signalstrength As Byte 'converted sm
Dim outputpower As Byte
Dim s_p As Byte
Dim prev As Byte
Dim txstatus As Byte 'Tx Status
Dim rxstatus As Byte 'Rx Status
Dim overnine As Byte 'Amount of db over nine (S9 + 40db)
prev = 0
'Welcome Message
Lcdcmdout LcdClear
Lcdcmdout LcdLine2Pos(4)
Lcdout "FT-817 Display"
Lcdcmdout LcdLine4Pos(7)
Lcdout "by M0TVU"
WaitMs 600 '600
Lcdcmdout LcdClear
Hseropen 38400 'Set the baud rate to 38400
Hserout 00h
Hserout 00h
Hserout 00h
Hserout 00h
Hserout 00h
WaitMs 300 '300
Hserout 00h
Hserout 00h
Hserout 00h
Hserout 00h
Hserout 00h
WaitMs 300 '300
'Lcdcmdout LcdLine1Home
'Lcdout "Dummy?"
'Hserin dummy '817 seems to send these first two
'Hserin dummy 'bytes - no idea why? Discard this data.
freq:
Lcdcmdout LcdLine4Home
Lcdout "Send 00 00 00 00 03"
WaitMs 600 '600
counter = counter + 1
Hserout 00h 'Send 00 00 00 00 03 to the 817
Hserout 00h 'Tell the 817 to send
Hserout 00h 'the frequency and mode
Hserout 00h
Hserout 03h
WaitMs 50 '50
'Read the data back from the 817 and store the raw data in
'the data array.
Lcdcmdout LcdLine4Clear
Lcdcmdout LcdLine4Home
Lcdout "Waiting for freq"
Hserin data(0) 'Frequency Bit1 - 14
Hserin data(1) 'Frequency Bit2 - 55
Hserin data(2) 'Frequency Bit3 - 00
Hserin data(3) 'Frequency Bit4 - 00 (145.500.00)
Hserin command '- Contains the Mode
Lcdcmdout LcdLine1Clear
'Now we have the raw data in the data array we need to do a little conversion
'to get the data to display chracters. Each raw data array element effectively
'contains two characters.
'Two loops run here one for characters and one for the data. The charloop is incremented
'twice for each dataloop.
charloop = 0
dataloop = 0
loop:
char(charloop) = data(dataloop) / 10h 's is the first real data. L is 1st byte to display
temp = data(dataloop) * 10h
charloop = charloop + 1
char(charloop) = temp / 10h
dataloop = dataloop + 1
If dataloop > 3 Then Goto checkzero
charloop = charloop + 1
Goto loop
checkzero:
char(0) = char(0) + 48
If char(0) = 48 Then char(0) = 32
char(1) = char(1) + 48
If char(0) > 48 Then Goto disp
If char(1) = 48 Then char(1) = 32
disp:
WaitMs 50 '50
Lcdcmdout LcdLine2Home
If command = 8 Then Goto fmdisplay
Lcdout char(0), char(1), #char(2), ".", #char(3), #char(4), #char(5), ".", #char(6), #char(7)
'set the display To the start of line 1 And send the values For l an n To the display As ascii codes
'Then display the decimal values of the other variables produced in the routine To Break the raw
'data down.any character in “” is displayed As written.
Goto mode
fmdisplay:
Lcdcmdout LcdLine2Home
Lcdout char(0), char(1), #char(2), ".", #char(3), #char(4), #char(5)
'set the display To the start of line 1 And send the values For l an n To the display As ascii codes
'Then display the decimal values of the other variables produced in the routine To Break the raw
'data down.any character in “” is displayed As written.
mode:
Select Case command
Case 0
Lcdcmdout LcdLine2Pos(18)
Lcdout "LSB"
Case 1
Lcdcmdout LcdLine2Pos(18)
Lcdout "USB"
Case 2
Lcdcmdout LcdLine2Pos(18)
Lcdout " CW"
Case 3
Lcdcmdout LcdLine2Pos(18)
Lcdout "CWR"
Case 4
Lcdcmdout LcdLine2Pos(18)
Lcdout " AM"
Case 6
Lcdcmdout LcdLine2Pos(18)
Lcdout "WFM"
Case 8
Lcdcmdout LcdLine2Pos(18)
Lcdout " FM"
Case 10
Lcdcmdout LcdLine2Pos(18)
Lcdout "DIG"
Case 12
Lcdcmdout LcdLine2Pos(18)
Lcdout "PKT"
EndSelect
sig: 'test for tx
If counter < 1 Then Goto freq '4
Lcdcmdout LcdLine4Clear
Lcdcmdout LcdLine4Home
Lcdout "Send 00 00 00 00 07"
WaitMs 600 '600
Hserout 00h 'Send 00 00 00 00 f7 to the 817
Hserout 00h 'This tells the 817 to send the status
Hserout 00h 'of the transmitter. We need to look at
Hserout 00h 'the power output meter and the PTT
Hserout f7h
Lcdcmdout LcdLine4Clear
Lcdcmdout LcdLine4Home
Lcdout "Waiting for tx info"
WaitMs 600 '600
Hserin txstatus
'test to see if bit 7 is high = RX mode.
'Only vlaues for RX - 8x, 9x, bx)
If txstatus > 7fh Then Goto rx
'Test to see if bit 6 is high - Signifies HIGH SWR'
If txstatus.6 = 1 Then Call line1(1)
s_p = 80 'Set the letter preceeding the bargraph to P for Power.
'Convert the raw status data from the 817
temp = txstatus * 10h
outputpower = temp / 10h
counter = 0
Call graph(outputpower)
WaitMs 10
Goto freq
rx:
Call line1(0)
Lcdcmdout LcdLine4Clear
Lcdcmdout LcdLine4Home
Lcdout "Send 00 00 00 00 07"
WaitMs 600 '600
s_p = 83 'Set the letter preceeding the bargraph to S for Signal Strength..
'we know the 817 is in recieve so get the data for the S-Meter
Hserout 00h
Hserout 00h
Hserout 00h
Hserout 00h
Hserout e7h
Lcdcmdout LcdLine4Clear
Lcdcmdout LcdLine4Home
Lcdout "Waiting 4 rx info"
WaitMs 600 '600
Hserin rxstatus
rxstatus = rxstatus * 10h
signalstrength = rxstatus / 10h
WaitMs 50
counter = 0
Call graph(signalstrength)
WaitMs 10
Goto freq
End
Function line1(arg As Byte) As Byte
Select Case arg
Case 0 'Clear Line 1'
Lcdcmdout LcdLine1Clear
Case 1 'High SWR'
Lcdcmdout LcdLine1Pos(2)
Lcdout "HIGH - SWR"
EndSelect
End Function
Function graph(arg1 As Byte) As Byte
Lcdcmdout LcdLine3Home
Select Case arg1
Case 0
Lcdout s_p, " ", "0 "
Case < 2
Lcdout s_p, #arg1, " ", 0, " "
Case < 3
Lcdout s_p, #arg1, " ", 0, 1, " "
Case < 4
Lcdout s_p, #arg1, " ", 0, 1, 2, " "
Case < 5
Lcdout s_p, #arg1, " ", 0, 1, 2, 3, " "
Case < 6
Lcdout s_p, #arg1, " ", 0, 1, 2, 3, 4, " "
Case < 7
Lcdout s_p, #arg1, " ", 0, 1, 2, 3, 4, 5, " "
Case < 8
Lcdout s_p, #arg1, " ", 0, 1, 2, 3, 4, 5, 6, " "
Case <= 9
Lcdout s_p, #arg1, " ", 0, 1, 2, 3, 4, 5, 6, 7, " "
Case > 9
If arg1 = 10 Then overnine = 10
If arg1 = 11 Then overnine = 20
If arg1 = 12 Then overnine = 30
If arg1 = 13 Then overnine = 40
If arg1 = 14 Then overnine = 50
If arg1 = 15 Then overnine = 60
If arg1 > 9 Then arg1 = 9
Lcdout s_p, #arg1, " ", 0, 1, 2, 3, 4, 5, 6, 7, "+", #overnine, "db"
EndSelect
End Function
Last edited: