Edit : one question, the part of the scroll buffer, will depend on the lenght of the buffer itself ?
The size of the buffer is set by the directive #define FifoLength 32 - in this case 32 bytes long.
Mike.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Edit : one question, the part of the scroll buffer, will depend on the lenght of the buffer itself ?
you're right,Mike. I missed that part. Sorryhence the count can never exceed two
The size of the buffer is set by the directive #define FifoLength 32 - in this case 32 bytes long.
Mike.
void interrupt ISR()
{
if(RCIF)
{
buff[a] = RCREG; /* read received byte from serial buffer */
a++;
if(RCSTAbits.OERR) /* check if any overrun occur due to continuous reception */
{
CREN = 0;
NOP();
CREN=1;
}
status_flag=1; /* use for new message arrival */
}
}
#define FifoLength 32
unsigned char FifoBuffer[FifoLength];
unsigned char *FifoStart;
unsigned char *FifoEnd;
unsigned char count;
void InitFifo(void){
FifoStart=FifoBuffer;
FifoEnd=FifoBuffer;
count=0;
}
void interrupt ISR(){
if(RCIF){
*FifoEnd++=RCREG;
count++;
if(FifoEnd==FifoBuffer+FifoLength) //reached end
FifoEnd=FifoBuffer; //yes so wrap
if(FifoStart==FifoEnd){ //is head eating tail?
//fifo full so deal with it!!
}
if(RCSTAbits.OERR) /* check if any overrun occur due to continuous reception */
{
CREN = 0;
NOP();
CREN=1;
}
}
}
unsigned char GetFifo(void){
unsigned char chr;
while(FifoStart==FifoEnd); //if fifo empty then wait
chr=*FifoStart++;
count--;
if(FifoStart==FifoBuffer+FifoLength) //wrapped?
FifoStart=FifoBuffer; //yes
return(chr);
}
unsigned char FifoCount(void){
return(count);
}
char rec,found,flag;
found=0;
flag=0;
while(1){ //loop forever
if(FifoCount()>0){ //any chars available
rec=GetFifo(); //yes so fetch first
if(found==0&&rec=='O'){ //check for 'O'
found++;
}
else if(found==1&&rec=='K'){//check for 'K'
flag=1;
found=0;
}
else{
found=0;
}
}
if(flag==1){
flag=0;
//flash LEDs etc.
}
}
char rec,found;
found=0;
while(1){ //loop forever
if(FifoCount()>0){ //any chars available
rec=GetFifo(); //yes so fetch first
if(found==0&&rec=='O') //check for 'O'
found++;
else if(found==1&&rec=='K') //check for 'K'
found++;
else
found=0;
}
if(found==2){
found=0;
//flash LEDs etc.
}
}
after reading this, I wonder, wouldnt it be easier to use strstr instead of checking for each character ? in this case something likeActually, you don't need the flag variable.
Code:char rec,found; found=0; while(1){ //loop forever if(FifoCount()>0){ //any chars available rec=GetFifo(); //yes so fetch first if(found==0&&rec=='O') //check for 'O' found++; else if(found==1&&rec=='K') //check for 'K' found++; else found=0; } if(found==2){ found=0; //flash LEDs etc. } }
Mike.
strstr(rec,"OK");