I am using PIC18f4620 and MPLAB. instead of doing each 'built' and 'program' and downloading the code in the PIC i want to write a program containing 3 individual program (i may call it as a 'case') inside my main program. after 'programming' i just want to press 3 individual button from the keyboard to switch between them. how this can be written inside the ISR? the pc will be interfaced with PIC using a serial port connection.
Here is the code that contains 3 different TEST, but i can use once at a time. i just want to avoide multiple programming and exploite the benefit of ISR.
Here is the code that contains 3 different TEST, but i can use once at a time. i just want to avoide multiple programming and exploite the benefit of ISR.
Code:
#include "UARTIntC.h"
#include "delays.h"
#include <p18f4620.h>
/*---------------------------------*/
/* Interrupt routine
/*---------------------------------*/
void low_isr(void);
// serial interrupt taken as low priority interrupt
#pragma code uart_int_service = 0x08
void uart_int_service(void)
{
_asm goto low_isr _endasm
}
#pragma code
#pragma interruptlow low_isr save=section(".tmpdata")
void low_isr(void)
{
// call of library module function, MUST
UARTIntISR();
}
void main(void)
{
// Test data array
unsigned char cArray[10]
= { 'A','B', 'C', 'D', 'E', 'F', 'G','H','I' , 'J'};
// temporary local array
unsigned char writtenArray[10];
// local variables for all test cases and their initialisation
unsigned char chData;
unsigned char *pReadArray;
unsigned char *pWriteArray;
unsigned char j = 0;
unsigned char i = 0;
unsigned char l = 0;
unsigned char k = 0;
pReadArray = pWriteArray = writtenArray;
// call of library module , MUST
UARTIntInit();
// TEST 1
// Chunk of 30 characters can be sent from PC to micro-controller.
// Each received character at micro-controller is read and immediately
// sent back to PC.
/*
while(1)
{
while(!vUARTIntStatus.UARTIntRxBufferEmpty)
{
UARTIntGetChar(&chData);
if(!vUARTIntStatus.UARTIntTxBufferFull)
UARTIntPutChar(chData);
};
};
*/
// TEST 2
// Chunk of data is sent from PC to micro. Data received at micro is
// read in to temporary buffer. The data is immediately sent back to
// PC. Usage of pointers is displayed in below example
/*
while(1)
{
l = 0;
l = UARTIntGetRxBufferDataSize();
while(l > 0)
{
if(UARTIntGetChar(pWriteArray))
{
if(!vUARTIntStatus.UARTIntTxBufferFull)
UARTIntPutChar(*pWriteArray);
l--; pWriteArray++;
if(pWriteArray == (writtenArray + 10))
pWriteArray = writtenArray;
}
}
}
*/
// TEST 3
// Chunk of data is sent from PC to micro. Data received at micro is
// read in to temporary buffer. The data is sent back to PC. Here
// reception and transmission is done independently.
while(1)
{
l = 0;
l = UARTIntGetRxBufferDataSize();
while(l > 0)
{
if(UARTIntGetChar(pReadArray))
{
l--; pReadArray++;
if(pReadArray == (writtenArray + 10))
pReadArray = writtenArray;
}
}
if((pWriteArray < pReadArray) || ((pWriteArray - pReadArray) == 9 ))
{
if(!vUARTIntStatus.UARTIntTxBufferFull)
{
UARTIntPutChar(*pWriteArray);
i--; pWriteArray++;
if(pWriteArray == (writtenArray + 10))
pWriteArray = writtenArray;
}
}
}
}