Hi All
I have been working on the following program for some time but to no avail .The program works okay but it stops after 3 iterations thus terminating the loop .Any ideas will be greatly appreciated .Thanks in advance .
Adam
//Program int_usart.c
//Picf18f4620 @20Mhz
//MikroC v8 demo .
//MCU Usart reads 5 ascii char from a pc
//ASCII chars stored in MCU memory .Then sent back to PC via usart
//Program works but does not iterate
//Eg. Repeats 3 times then halts.
char i,j,m;
char string[8];
/**********************************************/
// RX /TX Interrupt Handler
void interrupt() {
i=0;
do{
if (PIR1.RCIF == 1){ //if RX interrupt flag is set
m=RCREG ; //Read usart RX reg
PIR1.RCIF=0 ; //Clear flag
string=m ; //Store it in string array
i++ ;
}
}while(i<5); //Get 5 ASCII chars
string='\0' ; //Null terminate the string array
PIE1.RCIE = 0 ; //stop RX ints
//Now read back the string
i=0 ;
PIE1.TXIE=1; //Enable TX ints
do{
if(TXSTA.TRMT==1) {
m=string; //Read the stored array element
TXREG=m; //put it in TX reg
i ++;
}
}while(string!='\0');//continue until null found
PIE1.RCIE = 1; //Re-enable RX ints
PIE1.TXIE=0; //Disable TX ints
} //Return from interrupts
/*************************************/
function_init() {
Usart_Init(4800);
// Set comms and Interrupt Enable bits
RCSTA.SPEN=1; //CONFIGURE SER PORT rx/tx pins
PIE1.RCIE = 1; // bit 5 USART Receive Interrupt Enable
TXSTA.SYNC=0;
RCSTA.CREN=1; //Enable ser coms
TXSTA.TXEN=1; //Enable usart transmission
//Set global Interrupt Enable bits
INTCON.GIE = 1; // global interrput enable
INTCON.PEIE = 1; // Peripheral Interrupt Enable bit...1 = Enables all unmasked peripheral interrupts
PIE1.TXIE=0; //enable transmit interrupt
Delay_ms(100);
}
void main()
{
function_init();
//loop the program
do{
}while(1);
} //end main
I have been working on the following program for some time but to no avail .The program works okay but it stops after 3 iterations thus terminating the loop .Any ideas will be greatly appreciated .Thanks in advance .
Adam
//Program int_usart.c
//Picf18f4620 @20Mhz
//MikroC v8 demo .
//MCU Usart reads 5 ascii char from a pc
//ASCII chars stored in MCU memory .Then sent back to PC via usart
//Program works but does not iterate
//Eg. Repeats 3 times then halts.
char i,j,m;
char string[8];
/**********************************************/
// RX /TX Interrupt Handler
void interrupt() {
i=0;
do{
if (PIR1.RCIF == 1){ //if RX interrupt flag is set
m=RCREG ; //Read usart RX reg
PIR1.RCIF=0 ; //Clear flag
string=m ; //Store it in string array
i++ ;
}
}while(i<5); //Get 5 ASCII chars
string='\0' ; //Null terminate the string array
PIE1.RCIE = 0 ; //stop RX ints
//Now read back the string
i=0 ;
PIE1.TXIE=1; //Enable TX ints
do{
if(TXSTA.TRMT==1) {
m=string; //Read the stored array element
TXREG=m; //put it in TX reg
i ++;
}
}while(string!='\0');//continue until null found
PIE1.RCIE = 1; //Re-enable RX ints
PIE1.TXIE=0; //Disable TX ints
} //Return from interrupts
/*************************************/
function_init() {
Usart_Init(4800);
// Set comms and Interrupt Enable bits
RCSTA.SPEN=1; //CONFIGURE SER PORT rx/tx pins
PIE1.RCIE = 1; // bit 5 USART Receive Interrupt Enable
TXSTA.SYNC=0;
RCSTA.CREN=1; //Enable ser coms
TXSTA.TXEN=1; //Enable usart transmission
//Set global Interrupt Enable bits
INTCON.GIE = 1; // global interrput enable
INTCON.PEIE = 1; // Peripheral Interrupt Enable bit...1 = Enables all unmasked peripheral interrupts
PIE1.TXIE=0; //enable transmit interrupt
Delay_ms(100);
}
void main()
{
function_init();
//loop the program
do{
}while(1);
} //end main