Hello all,
i need your help to convert my code from basic stamp2 sx.
I'm trying to read the frequency of an ICOM shortwave receiver.
Here is my easy working basic stamp code :
Code:
' {$STAMP BS2Sx}
' {$PBASIC 2.5}
LCDcls CON 1
I CON 254
speed CON 16624 '9600 for LCD
speedI CON 2063 '1200 for ICOM
FR VAR Byte(5)
START:
PAUSE 10
SEROUT 14,speedI,[$FE,$FE,$80,$E0,$03,$FD] 'STATUS UPDATE FREQUENCY
SERIN 14,speedI,[SKIP 5,STR FR\5] ' YES !!! the same port works for RX too !!! of course works with any other port
SEROUT 15,speed,[i,128,"F : ",HEX2 FR(1),HEX2 FR(2),HEX2 FR(3),HEX2 FR(4),HEX2 FR(5)] 'Frequency digits OK
GOTO START
And here is my NOT Working code for PIC
Code:
'''''''''''''''''''''''''''''''''''''''''''''
''''''''' PIC 18F46K22
'''''''''''''''''''''''''''''''''''''''''''''
DEFINE OSC 64
'############################################
'############# INTERNAL OSC #####################
'############################################
@ CONFIG FOSC = INTIO67
OSCCON.6 = 1 '####################
OSCCON.5 = 1 '###### 16 MHz #########
OSCCON.4 = 1 '####################
OSCTUNE.6 = 1 '#### PLL X 4 ###########
'############################################
lcds con 16468
lcdcls con 1
line1 con 128
line2 con 192
lcdp var portd.1
icp1 var portd.2
icps con 813 '33581 - 813
I con 254
fr var byte(5)
start:
pause 50 'Give some time to receiver
SEROUT2 icp1,icps,[$FE,$FE,$80,$E0,$03,$FD] 'Send this to update status
SERIN2 portd.3,icps,[SKIP 5, STR FR\5] 'Skip first 5 bytes (not needed) and store next 5 bytes to FR(1) - FR(5)
serout2 lcdp,lcds,[i,line1,"F : ",hex2 fr(1),hex2 fr(2),hex2 fr(3),hex2 fr(4), hex2 fr(5)]
goto start
The above code is not working. I get only zeros. I know that there is communication from the TX line with the receiver because I can send commands (only send) to the receiver and it responds correctly. But i cannot receive anything.
I have also tried HSERIN but the same results. And I have played with the OSC frequencies in case it was too fast for my project but no luck. In any case or OSC frequency I have tried, I can send any command I want to the receiver and it responds, but I cannot read anything from it.
That's why i also tried to use a different port for RX, but i don't think this is the problem.
I beleive basic stamp treats in other way the received bytes.
To help you more, this is what i'm expecting to receive for frequency (in hex) :
$FE,$FE,$E0,$80,$03,$FR(1),$FR(2),$FR(3),$FR(4),$F R(5),$FD
I don't need the first 5 bytes and the last byte, only FR(1) to FR (5) to display the frequency and make various calculations with the frequency digits.
Any help would be much appreciated
Thanks in advance
Fanis
Bookmarks