Code:
clear
DEFINE OSC 20
pause 4000
Include "modedefs.bas"
B0 Var Byte
TRISD = %00000000
TRISC = %10000000'set TX (PORTC.6) to out, rest in
TRISB = %0111101 ' Set PORTB.0-2 (LEDs) to output, 3-6 to input
PortB = 0
PortD = %00000000
' send command to Bluetooth(IP, name)
SerOut2 PortC.6,84, [$02,$52,$27,$06,$00,$7F,$12,$13,$23,$17,$09,$00,$03]
pause 200
SerOut2 PortC.6,84, [$02,$52,$66,$00,$00,$B8,$03]
pause 200
Serout2 PortC.6,84, [$02,$52,$04,$11,$00,$67,$10,$4D,$49,$43,$52,$4F,$42,$4F,$58,$42,$54,$31,$20,$20,$20,$20,$00,$03]
RX var byte ' Receive byte
'------------------------------------------------------------------------------
'@ DEVICE HS_OSC
Define ADC_BITS 8 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
adval1 Var Byte ' Create adval to store result
adval2 Var Byte
adval3 Var Byte
TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %00000010 ' Set PORTA analog
TRISD = %00000000
led0 var PORTD.3
led1 var PORTD.4
cnt var byte
OPTION_REG = $7f ' Enable PORTB pull-ups
TRISB = %00000000 ' Set PORTB.0-2 (LEDs) to output, 3-7 to input
PortB = 0
'------------------------------------------------------------------------------
serout PortD.2,T9600,[$1B,$45]
serout PortD.2,T9600,["Loging on.."]
pause 300
Menu:
'****** [Menu setup on PC screen] *************************
serout PortD.2,T9600,[$1B,$45,"**System Ready**"]
pause 500
serout PortD.2,T9600,[$D,"GSTS week"]
Receive:
' ***** [Receive the menu selection from PC] ***************
serin PortC.7, T9600, RX 'Receive menu from PC
serout PortD.2,T9600,[$1B,$45,RX]
pause 500
RX = RX - $30 'Convert ASCII to decimal value
If RX > 3 then Error ' Test for good value
Branch RX, [zero, one, two, Three] 'redirect to menu selection code
error:
serout PortD.2,T9600,[$1B,$45,"Try again"]
serout PortD.2,T9600,[$D,"GSTS week"]
goto menu
Zero:
'***** [ Code for zero value ] *****************************
goto menu 'Return to menu, zero is not a valid selection
One:
'***** [Code for selection 1] ************************
Toggle PortB.0
pause 100
serout PortD.2,T9600,[$1B,$45,"**System Ready**"]
serout PortD.2,T9600,[$D,"Toggle L1"]
pause 500
goto menu 'Return to main menu
Two:
pause 100
Toggle PortB.1
serout PortD.2,T9600,[$1B,$45,"**System Ready**"]
serout PortD.2,T9600,[$D,"Toggle L2"]
pause 500
goto menu 'Return to main menu
Three:
pause 100
Toggle PortB.2
serout PortD.2,T9600,[$1B,$45,"**System Ready**"]
serout PortD.2,T9600,[$D,"Toggle L3"]
pause 500
goto menu 'Return to main menu
End
I'm trying to add the following codes
Code:
ADCIN 0, adval1 ' Read channel 0 to adval D1
ADCIN 1, adval2 ' Read channel 0 to adval D0
if adval1 >25 then
SerOut2 PortC.6,84, ["1"]
Serout PortD.0,T9600, [$1B,$45,"[1] ",#adval1]
Pause 100
Endif
if adval2 >25 then
SerOut2 PortC.6,84, ["2"]
Serout PortD.0,T9600, [$1B,$45,"[2] ",#adval1]
Pause 100
Endif
The above codes works in a different application, this triggers when an RF data is received on A0 and A1..and now I'm trying to combine this code in the above code. I tried merging the two codes but it seems the RF codes does not response when triggering the RF transmitter. Do you think I need to apply an interrupt? Can you anyone guide me how?
Bookmarks