Bruce,
Can you PM or email me your last name please?
roberthedan AT hotmail DOT com
I'd like to give credit where credit is due in the comments.
And you've also made yourself a new customer at Rentron.
Robert
![]()
Bruce,
Can you PM or email me your last name please?
roberthedan AT hotmail DOT com
I'd like to give credit where credit is due in the comments.
And you've also made yourself a new customer at Rentron.
Robert
![]()
My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.
Not as dumb as yesterday, but stupider than tomorrow!
On Interrupt Goto Main
GOTO Doodle
Disable
Main:
WHILE RCIF ' If RCIF=1 there's a new character in RCREG
BytesIn[ByteCnt]=RCREG ' Yes. Then store it in array
If BytesIn[ByteCnt]=EOM then OutMsg ' Display on receipt of terminating char
ByteCnt=ByteCnt+1 ' Increment array index pointer
WEND ' Exit only when RCREG is clear
RESUME ' Return to normal operation prior to interrupt
ENABLE
---------------------------------------------------
Isn't DISABLE an unexecutable statement? Shouldn't it be the 1st statement of Main?
Then at the bottom of OutMsg, we could GOTO the WHILE statement as it is doing now; label Main1 on Disable, and Main2 on While?
Or am I missing something?
Robert
![]()
My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.
Not as dumb as yesterday, but stupider than tomorrow!
Hi Robert,
NOP, see PBP manual. Interrupt handler must be write like this. I agree that it looks weird but compiler handle it for you.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
The compiler is wrong, and I am right...
Robert
![]()
My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.
Not as dumb as yesterday, but stupider than tomorrow!
Bruce, your code works perfectly when I process a single record. But I'm trying to add a paragraph at the bottom to read multiple records and failing miserably. I'm sure I'm screwing up the INTERUPT controls. As it stands, RESUME returns into the Doodle paragraph and stays there until my hair falls out (which will be soon).
I tried to add ON INTERUPT immediately before the Doodle, followed by an INTCON=$80, but I must be messing something up doing that. I want the interupts to happen ONLY during the Doodle logic. I don't want it to fire up while I'm in the middle of extracting the bytes from BytesIn and writing them onto the EEPROM.
Also, when you 'Trash any left over characters in RCREG buffer, I will be losing characters from the next record. I have to save that in a temporary array and load it back at the start of BytesIn somehow.
Robert
![]()
My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.
Not as dumb as yesterday, but stupider than tomorrow!
Ok,
I started again from your code, and modified one thing at a time. I've removed the comments to make it easier to read here (I figure you don't need your own comments).
1. I saved the data from the 1st record by copying it into BytesGP[ByteGPN]. I need that data so I can write it to the EEPROM.
2. I was able to get just Doodle under Interupt control.
3. I was able to save the data from RCREG. There was indeed the 1st character from the next record in there. The data is stored in BytesBK[ByteBKN].
?. But I can't figure out what I'm doing wrong to get the rest of the 2nd record. I must be losing some kind of flag or something to tell USART not to hyperspace the rest of the 2nd record.
====================================
define LOADER_USED 1
ASM
LIST
INCLUDE 'M16F87X.INC' ; PM header
DEVICE PIC16F877, HS_OSC, WDT_OFF, PWRT_ON, BOD_ON, LVP_OFF, CPD_OFF, WRT_OFF, DEBUG_OFF, PROTECT_OFF
XALL
NOLIST
ENDASM
define OSC 20
define HSER_BAUD 19200
DEFINE HSER_CLROERR 1
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
GP VAR BYTE
BytesIn var byte[80]
ByteCnt var byte
BytesGP VAR BYTE[80]
ByteGPN VAR BYTE
BytesBK VAR BYTE[80]
ByteBKN VAR BYTE
X VAR BYTE
EOM CON "~"
OERR VAR RCSTA.1
CREN VAR RCSTA.4
RCIF VAR PIR1.5
ByteCnt = 0
ADCON1 = 7
INTCON = %11000000
PIE1.5 = 1
' -------------------------------------------------------------
GOTO Start
' -------------------------------------------------------------
Main:
WHILE RCIF
BytesIn[ByteCnt]=RCREG
If BytesIn[ByteCnt]=EOM then OutMsg
ByteCnt=ByteCnt+1
WEND
RESUME
' -------------------------------------------------------------
OutMsg:
HSEROUT [13,10,dec ByteCnt," Bytes Rcvd:",STR BytesIn\ByteCnt]
FOR GP=0 to ByteCnt
BytesGP[GP]=BytesIn[GP]
BytesIn[GP]=0
NEXT
ByteGPN=ByteCnt-1
ByteCnt=0
ByteBKN=0
WHILE RCIF
BytesBK[ByteBKN]=RCREG
ByteBKN=ByteBKN+1
WEND
GOTO Main
' -------------------------------------------------------------
On Interrupt Goto Main
Doodle:
FOR X = 0 TO 250 : PAUSEUS 20 : NEXT X
FOR X = 0 TO 250 : PAUSEUS 20 : NEXT X
RETURN
INTCON=$80
' -------------------------------------------------------------
Start:
ByteGPN=0
WHILE ByteGPN=0 : GOsub Doodle : Wend
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''
' BytesGP[ByteGPN] Data from BytesIn is saved here for EEPROM
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''
' Place contents trashed from RCREG back in beginning of BytesIn
ByteCnt=ByteBKN-1
For X=0 TO ByteCnt
BytesIn[X]=BytesBK[X]
NEXT X
HSEROUT [13,10,dec ByteCnt," Bytes Saved:",STR BytesIn\ByteCnt]
GOTO Start
' -------------------------------------------------------------
end
My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.
Not as dumb as yesterday, but stupider than tomorrow!
I went for a nap after my last post and not 2 minutes later, I remember this:
"If you just need to PIC to tell the PC to stop sending data, connect the PIC flow control pin to the PC CTS pin."
Robert
![]()
My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.
Not as dumb as yesterday, but stupider than tomorrow!
Why not do something useful with the data received instead of wasting time in the doodle routine or writing everything received into another array?
Once you receive the terminating character, write your data to EEPROM, then wait for the next packet.
Also, you don't need all this;
ASM
LIST
INCLUDE 'M16F87X.INC' ; PM header
DEVICE PIC16F877, HS_OSC, WDT_OFF, PWRT_ON, BOD_ON, LVP_OFF, CPD_OFF, WRT_OFF, DEBUG_OFF, PROTECT_OFF
XALL
NOLIST
ENDASM
Just drop in your fuse definitions like below, and leave the rest to PBP. It does all this for you.
@ DEVICE PIC16F877, HS_OSC, WDT_OFF, PWRT_ON, BOD_ON, LVP_OFF, CPD_OFF, WRT_OFF, DEBUG_OFF, PROTECT_OFF
This routine;
WHILE RCIF
BytesBK[ByteBKN]=RCREG
ByteBKN=ByteBKN+1
WEND
Just clears whatever characters may have arrived after the terminating character was received. You want to be sure RCREG is empty & RCIF is clear before your next data packet shows up.
At some point, you're going to need some kind of synchronization with your PC program sending your data. You can't just keep slamming data into the USART without doing something with it to clear the array, and you're going to need some time to write your data to EEPROM (without interrupts enabled).
You do not want interrupts enabled when writing data to the EEPROM, so you will definitely want to implement something to let the PC know you're busy.
Example scenario:
PIC requests data from PC.
PC sends packet with terminating character.
PIC receives & stashes data in array until terminating character is received.
PIC processes data.
PC waits for signal from PIC to send next packet.
PIC says OK, let's have it.
PC sends next data packet.
Two way communications is the key.
Strip all the useless stuff out of my example. You don't need to send everything back to the PC terminal program or waste time in the doodle sub-routine. That was just an example showing how to receive streaming data, and key on the terminating character to find the end-of-packet.
The time you spend in re-writing everything into another array, pauses, etc,, could be used for processing your inbound data, and let you setup & wait for the next packet.
Note: Watch for stuff like this;
On Interrupt Goto Main
Doodle:
FOR X = 0 TO 250 : PAUSEUS 20 : NEXT X
FOR X = 0 TO 250 : PAUSEUS 20 : NEXT X
RETURN
INTCON=$80
Program flow will never reach INTCON=$80 because it RETURNs before landing on it.
Bookmarks