I have a problem that my Flowcode 2.2. programme runs fine but that it will not β€restart’ by looping back to the start and function properly.
The programme is basically
Initialise variables
Clear arrays
Start timer 0 interrupt driven clock
RS232 input of acquisition parameters from PC
Loop to acquire data
RS232 output to PC of data
End
This works fine.
If I carry out a hardware chip reset the code will function again without any problem.
BUT
If I loop from End to the first line again the programme restarts OK (welcome message on LCD etc)
But the RS232 input will just not work (but recall that it does work from a hard reset), i.e. :
-A:
Initialise variables
Clear arrays
Start timer 0 clock
RS232 input of acquisition parameters
Loop to acquire data
RS232 output of data
Goto-A
End
The RS232 input and output routines use handshaking by exchange of characters, hardware handshaking is disabled (as you previously advised).
All is run on v3 Dev Board with RS232 E-block, but also runs the same on a self-made dedicated circuit.
So three questions please :
1) What will be different between the hard reset and loop back to start of chart?
2) How can I simulate a hard reset through software? "asm goto 0β€ ?
(if so, correct syntax please).
3) Does Flowcode keep a buffer of β€unread’ inputs in the PIC (the PC can but I have bottomed that).
The programme is now up to nearly 4k so picking through the assembler is beyond me now.
Many thanks,
Effect of loop back to start versus a harware reset
- Steve
- Matrix Staff
- Posts: 3433
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
Hello Mark,
The clue is to look at the C code that is generated. I created a simple program with a loop-back to the beginning and this is the code that was produced:
As you can see, there is some RS232 initialisation code that is inserted before the connection point "A:".
You could simply recreate this code within a C icon before your jump back to the start of the program.
Alternatively, put this into a C code icon:
As to your final point about the buffer, a PICmicro generally has a 2 or 3-byte wide buffer. See the pic's datasheet for more on this.
The clue is to look at the C code that is generated. I created a simple program with a loop-back to the beginning and this is the code that was produced:
Code: Select all
void main()
{
//Initialisation
ansel = 0;
cmcon = 0x07;
// RS232 initialiasation code
#define fc_rs232_baud 31
#define fc_rsSTATUS_LOOP 0
#define fc_rsSTATUS_TIMEOUT 1
#define fc_rsSTATUS_RXBYTE 2
txsta = 0; // 8-bit, async, low speed, off
spbrg = fc_rs232_baud; // set the baud rate
rcsta = 0; // 8-bit, disabled
set_bit(rcsta, SPEN); // turn on serial interface
//Interrupt initialisation code
option_reg = 0xC0;
//Connection Point
//Connection Point: A
FCC_Main_A:
//Call Component Macro
//Call Component Macro: RS232(0)::SendRS232Char(2)
FCD_RS2320_SendRS232Char(2);
//Output
//Output: 0 -> PORT A
trisa = 0x00;
porta = 0;
//Goto Connection Point
//Goto Connection Point: A
goto FCC_Main_A;
mainendloop: goto mainendloop;
}
You could simply recreate this code within a C icon before your jump back to the start of the program.
Alternatively, put this into a C code icon:
Code: Select all
//perform a reset
pclath = 0;
pcl = 0;