Code:
@ CONFIG OSC = INTIO67 'config for internal osc
@ CONFIG PBADEN = ON ' turn off port b analog inputs
@ CONFIG MCLRE = ON 'activate master clear
@ CONFIG WDT = OFF 'turn off watchdog timer
@ CONFIG STVREN = ON 'turn off reset on overflow/underflow
@ CONFIG LVP = OFF 'turn off low voltage programming
@ CONFIG CP0 = OFF
@ CONFIG CP1 = OFF
@ CONFIG CP2 = OFF
@ CONFIG CPB = OFF
@ CONFIG WRT0 = OFF
@ CONFIG WRT1 = OFF
@ CONFIG WRT2 = OFF
@ CONFIG WRT3 = OFF
@ CONFIG WRTB = OFF
@ CONFIG WRTC = OFF
Include "modedefs.bas"
OSCCON = %01100000 'set internal oscillator to 4 mhz and select it as system clock
ADCON1 = %00001111 'turn off adcs set to digital i/o
ADCON0 = %00000000
CCP1CON = %00000000
CCP2CON = %00000000
TRISA = %00000000 'set port A to all outputs
TRISB = %10100000 'set port B I/O directions
TRISC = %00000000 'set port C to all outputs
TRISD = %00000000 'set port D to all outputs
TRISE = %00000000 'set port E to all outputs
PORTA = %11111111 'set all outputs on port a to 0
PORTB = %00011111 'set outputs on port b to 0, except leds on 4&5
PORTC = %11111111
PORTD = %00000000 'set all outputs on port d to 0
PORTE = %00000000 'set all outputs on port e to 0
WDTCON = %00000000 'turn off wdt
INTCON = %00000000
INTCON2= %00000000
INTCON3= %00000000
CMCON = 7
while OSCCON.2=0
'wait for the oscillator stable bit to be set
pause 1
WEND
led_run var PORTB.0 'led indicates transmission status, blink=transmit
led_pwr VAR PORTB.3 'led indicates power on status, on=powered
i var word 'used for loop counts
Z VAR BYTE
rcx var PORTB.7 'rs-232 input on portc.7
tcx var PORTB.6 'rs-232 output
rts var PORTB.5 'read rts signal from simulation
cts var PORTB.4 'set cts signal to simulation
newdata var byte 'flag to indicate new data
t11 var byte 'tac 1 first input character
t12 var byte 'tac 1 second input character
t13 var byte 'tac 1 third input character
t14 var byte 'tac 1 fourth input character
tac1HW var word 'tac 1 high word
tac1HP var byte 'tac 1 high pointer
tac1LW var byte 'tac 1 low word (byte)
tac1LP var byte 'tac 1 low pointer
tac1tuned var bit
t21 var byte
t22 var byte
t23 var byte
t24 var byte
tac2HW var word
tac2HP var byte
tac2LW var byte
tac2LP var byte
tac2tuned var bit
a11 var byte
a12 var byte
a13 var byte
a14 var byte
adf1HW var word
adf1HP var byte
adf1LW var byte
adf1LP var byte
adf1tuned var bit
a21 var byte
a22 var byte
a23 var byte
a24 var byte
adf2HW var word
adf2HP var byte
adf2LW var byte
adf2LP var byte
adf2tuned var bit
m11 var byte
m12 var byte
m13 var byte
m14 var byte
mmr1HW var word
mmr1HP var byte
mmr1LW var byte
mmr1LP var byte
mmr1tuned var bit
m21 var byte
m22 var byte
m23 var byte
m24 var byte
mmr2HW var word
mmr2HP var byte
mmr2LW var byte
mmr2LP var byte
mmr2tuned var bit
radioout var byte[75] 'radios output array
cnt var byte 'counter
mb1 var byte 'marker beacon input character
mbout var word[50] 'marker beacon output array
mbcnt var word 'counter for marker beacon array build
tmpstr var byte 'temp var to store morse code
tmplen var byte 'temp var to hold length of morse code
passval var byte 'value passed during morse code generation
tmpword var word
tmpbyte var byte
framelen var byte
'temporary set values to test building outputs
A11=64'83 'S
A12=64'79 'O
A13=64'83 'S
A14=64'48 '0
A21=68 'D
A22=66 'B
A23=78 'N
A24=64 '@
t11=83 'S
t12=79 'O
T13=83 'S
T14=83 '64 '@
t21=75 'K
t22=87 'W
T23=82 'R
T24=66 'B
M11=75 'K
M12=65 'A
M13=84 'T
M14=76 'L
M21=75 'K
M22=76 'L
M23=65 'A
M24=88 'X
MB1=50 '2=MIDDLE
FOR I=1 TO 5
TOGGLE led_pwr 'setting pin low turns on led
PAUSE 250
led_run=0
NEXT I
framelen=75
CTS=0
newdata=0 'set flag to get new data when starting
audio_loop:
if NEWDATA=1 then 'if request to send is high then set clear to send and get data
SEROUT tcx,n2400,["In new data if statement"]
tac1tuned=1
tac2tuned=1
adf1tuned=1
adf2tuned=1
mmr1tuned=1
mmr2tuned=1
led_run=0
LED_PWR=1
if t11=64 and t12=64 and t13=64 and t14=64 then tac1tuned=0 'all @ signs
if t21=64 and t22=64 and t23=64 and t24=64 then tac2tuned=0
if a11=64 and a12=64 and a13=64 and a14=64 then adf1tuned=0
if a21=64 and a22=64 and a23=64 and a24=64 then adf2tuned=0
if m11=64 and m12=64 and m13=64 and m14=64 then mmr1tuned=0
if m21=64 and m22=64 and m23=64 and m24=64 then mmr2tuned=0
led_run=1
for i=0 to framelen-1
radioout(i)=0
next i
tac1hw=0
tac1hp=16
tac1lw=0
tac1lp=8
tac2hw=0
tac2hp=16
tac2lw=0
tac2lp=8
adf1hw=0
adf1hp=16
adf1lw=0
adf1lp=8
adf2hw=0
adf2hp=16
adf2lw=0
adf2lp=8
mmr1hw=0
mmr1hp=16
mmr1lw=0
mmr1lp=8
mmr2hw=0
mmr2hp=16
mmr2lw=0
mmr2lp=8
if mb1<>48 then 'if marker beacon is not set to zero=off
gosub buildmb
else
for i=0 to 49
mbout(i)=1
next i
endif
gosub buildr
SEROUT tcx,n2400,["Just did buildr"]
gosub buildo
SEROUT tcx,n2400,["Just did buildo"]
NEWDATA=2
SEROUT tcx,n2400,[#newdata]
endif
'start outputting
IF NEWDATA=2 THEN
PORTA=radioout(cnt)
PORTC=mbout(mbcnt)
pause 100
cnt=cnt+1
mbcnt=mbcnt+1
if mbcnt>49 then
mbcnt=0
endif
if cnt=framelen then
cnt=0
endif
ENDIF
if rts=1 then
led_run=0
cts=1
serin rcx,N2400,[t11,t12,t13,t14,t21,t22,t23,t24,a11,a12,a13,a14,a21,a22,a23,a24,m11,m12,m13,m14,m21,m22,m23,m24,mb1]
pause 250
SEROUT tcx,n2400,["Received: "]
pause 1000
serout tcx,N2400,[t11,t12,t13,t14,t21,t22,t23,t24,a11,a12,a13,a14,a21,a22,a23,a24,m11,m12,m13,m14,m21,m22,m23,m24,mb1]
newdata=1
cts=0
toggle LED_run
endif
if newdata=1 then
SEROUT tcx,n2400,["Got out of the if statement"]
endif
toggle led_run
goto audio_loop
Bookmarks