O.k, there's few thing to be removed first..
Code:
mainloop:
IF RCSTA.1 = 1 THEN 'if USART overrun error flag OERR is set...
RCSTA.4 = 0 'clear and then set CREN bit to recover
RCSTA.4 = 1
in1 = RCREG 'read data to clear out RCREG
IF PIR1.5 = 1 THEN in1 = RCREG 'clear possible 2nd byte in RCREG
ENDIF
DEFINE HSER_CLROERR 1 do this for you. Remove those line.
Code:
WHILE PIR1.5 = 0 'stay here until USART receives data
'LOW portc.3 'portc.3 has diagnostic LED
WEND
'HIGH portc.3 'data in RCREG; turn on diagnostic LED
While your program do nothing usefull there, simply remove those line and replace it simply for HSERIN.
Code:
if b1=0 and b2=1 and b3=11 THEN GOSUB ONN1
.
.
.
Should be writen like..
Code:
if (b1=0) and (b2=1) and (b3=11) THEN GOSUB ONN1
Code:
ONN1:
HIGH PORTB.7
goto mainloop
You jump to ONN1 with a gosub, it must be terminated with a RETURN to avoid stack overflow. Replace GOTO MAINLOOP by a simple RETURN.
Multiple PORTA.0=0, PORTA.1=0, ... can be replace with a single line. In your example you set all PORTA bit to zero. It's working sure, but you can still use PORTA=0. Same for all PORTx to 1. Can be replace with PORTx=%11111111, PORTx=$FF or PORTx=255.
Personnaly i would change it to something different..., let's try something.
Code:
TRISA = %00000000
TRISB = %00000000
TRISC = %10000000
ADCON1 = 7
PORTx var byte
PORTbit var byte
BitState var byte
PORTA = 0
PORTB = 0
PORTC = 0
mainloop:
hserin 500,mainloop,[PORTx,DEC1 portbit, DEC1 bitstate]
select case portx
case "A"
PORTA.0(PORTBIT)=BITSTATE
CASE "B"
PORTB.0(PORTBIT)=BITSTATE
CASE "C"
PORTC.0(PORTBIT)=BITSTATE
END SELECT
GOTO MAINLOOP
With few chunk around it may be something to play with
EDIT: also, there's no PORTD on the F870.. no warning or error using PM? I don't know how it's handle by PM but for sure, this will return you an error message when using MPASM...
@Darrel,
Yet another reason
Bookmarks