Code:
'****************************************************************
'* Name : net-master-test.pbp *
'****************************************************************
Include "modedefs.bas"
DEFINE OSC 48
'-----------------------------------------------------------------------
' configuration USART2 (communication avec FAV)
RCSTA2 = $90 ' Enable serial port & continuous receive
TXSTA2 = $20 ' Enable transmit, BRGH = 0
SPBRG2 = 77 ' 9600 Baud @ 48MHz, 0,16%
' configuration USART1 (communication RS232 externe)
RCSTA1 = $90 ' Enable serial port & continuous receive
TXSTA1 = $20 ' Enable transmit, BRGH = 0
SPBRG1 = 77 ' 9600 Baud @ 48MHz, 0,16%
ANSELA = 0 ' analog off
ANSELB = 0 ' analog off
ANSELC = 0 ' analog off
TRISA = %00000100
TRISB = %10001000
TRISC = %10100100
PORTA = 0
PORTB = 0
PORTC = 0
led var PORTA.5
GP2 VAR BYTE ' GP variable
BytesIn2 VAR BYTE[80] ' Up to 80 bytes
ByteCnt2 VAR BYTE ' Index pointer
EOM CON 10 ' EOM = "End Of Msg" terminating character
OERR2 VAR RCSTA2.1 ' Alias USART over-run bit
CREN2 VAR RCSTA2.4 ' Alias USART continuous receive enable bit
RCIF2 VAR PIR3.5 ' Alias USART received character interrupt flag bit
RCIF1 VAR PIR1.5
GP1 VAR BYTE ' GP variable
BytesIn1 VAR BYTE[80] ' Up to 80 bytes
ByteCnt1 VAR BYTE ' Index pointer
OERR1 VAR RCSTA1.1 ' Alias USART over-run bit
CREN1 VAR RCSTA1.4 ' Alias USART continuous receive enable bit
depart:
clear
high led
portc.4 = 1 ' serial to netatt
PAUSE 1000
' ask for position
position:
portc.4 = 1
serout2 PORTC.4,32,["?0",10]
toggle led
pause 500
goto position
Code:
'****************************************************************
'* Name : netatt-test.pbp *
'****************************************************************
Include "modedefs.bas"
define OSC 48
' - Memorisation des données EEPROM à la programmation
' à partir de l'addresse 1
EEPROM 1,[24,41,36,21,29,80]
' 1, H, Y, T, E, M, _
' à partir de l'adresse 16
' 17,18,19,20
EEPROM 16,[87,65,89,88]
' 16, W ,A ,Y, X
'-----------------------------------------------------------------------
DEFINE ADC_BITS 8 ' ADCIN resolution (Bits)
DEFINE ADC_CLOCK 7 ' ADC clock source (Frc)
DEFINE ADC_SAMPLEUS 11 ' ADC sampling time (uSec)
' configuration USART2 portb.6 (communication to net-master)
RCSTA2 = $90 ' Enable serial port & continuous receive
TXSTA2 = $20 ' Enable transmit, BRGH = 0
SPBRG2 = 38 ' 19200 Baud @ 48MHz, 0,16%
' configuration USART1 (external communication with EM1206 TIBBO)
RCSTA1 = $90 ' Enable serial port & continuous receive
TXSTA1 = $20 ' Enable transmit, BRGH = 0
SPBRG1 = 77 ' 9600 Baud @ 48MHz, 0,16%
ANSELA = 0
ANSELB = 0
ANSELC = 16 'analog on portc.4
TRISA = %10001111
TRISB = %10000001
TRISC = %10010000
PORTA = 0
PORTB = 0
PORTC = 0
led var PORTA.5
x var byte
voie var byte
nv1 var byte
nv2 var byte
nv3 var byte
nv4 var byte
what var byte
way var byte
vmax var WORD
att var word
GP2 VAR BYTE ' GP variable
BytesIn2 VAR BYTE[10] ' Up to 10 bytes
ByteCnt2 VAR BYTE ' Index pointer
EOM CON 10 ' EOM = "End Of Msg" terminating character
OERR2 VAR RCSTA2.1 ' Alias USART over-run bit
CREN2 VAR RCSTA2.4 ' Alias USART continuous receive enable bit
RCIF2 VAR PIR3.5 ' Alias USART received character interrupt flag bit
RCIF1 VAR PIR1.5
GP1 VAR BYTE ' GP variable
BytesIn1 VAR BYTE[80] ' Up to 80 bytes
ByteCnt1 VAR BYTE ' Index pointer
OERR1 VAR RCSTA1.1 ' Alias USART over-run bit
CREN1 VAR RCSTA1.4 ' Alias USART continuous receive enable bit
pause 10
clear
'********************************
' What is my way ? (0-3)
'********************************
ADCIn 16,way
IF way < 30 then
way = 48 'way 0 for 470R
goto mainloop
endif
IF way < 60 then
way = 49 'way 1 for 2K2
goto mainloop
endif
IF way < 90 then
way = 50 'way 2 for 3K9
goto mainloop
endif
way = 51 'way 3 for 10K
'*******************************************
mainloop:
IF RCIF2 then 'reception from master PIC ?
gosub RX2
endif
goto mainloop
'********* reception with USART2 (from netMaster PIC) ****
RX2:
IF RCIF2 THEN ' If RCIF2=1 there's a new character in RCREG
BytesIn2[ByteCnt2]=RCREG2 ' Yes. Then store character in array
IF BytesIn2[ByteCnt2]=10 THEN OutMsg2 ' LF (0A)
ByteCnt2=ByteCnt2+1 ' Increment element index pointer
ENDIF
IF !OERR2 THEN RX2 ' If NOT over-run, then re-cycle
CREN2 = 0 ' Yes. Over-run condition is present, so clear it
CREN2 = 1 ' Re-enable & clear over-run condition
HSEROUT2 ["Over-run reset",13,10]
return
OutMsg2:
HSEROUT2 [13,10,DEC ByteCnt2," received bytes",13,10]
HSEROUT2 [STR BytesIn2\ByteCnt2,13,10] ' Show each character
hserout2 ["time:",dec x,10]
x = x + 1
IF BytesIn2[0] = 63 and Bytesin2[1] = way THEN '?way
gosub sendata
gosub reset2
goto mainloop
endif
hserout2 ["?"]
gosub reset2
goto mainloop
reset2:
FOR GP2=0 TO ByteCnt2 ' Clear array bytes 0 to ByteCnt
BytesIn2[GP2]=0
NEXT GP2
ByteCnt2=0 ' Reset index pointer back to first element
WHILE RCIF2 ' Trash any left over characters in RCREG buffer
GP2=RCREG2 ' after EOM is received
WEND
RETURN
sendata:
toggle led
read 16,nv1 'first letter
read 17,nv2 'second
read 18,nv3 '....
read 19,nv4 '....
if att < 10 then
hserout2 ["00",dec att,nv1,nv2,nv3,nv4,10]
return
endif
if att < 100 then
hserout2 ["0",dec att,nv1,nv2,nv3,nv4,10]
return
endif
hserout2 [dec att,nv1,nv2,nv3,nv4,10] 'att value + name
return
Bookmarks