#pragma code IntrruptPriorityHigh = 0x08
void IntrruptPriorityHigh(void){
_asm goto IntrruptHandleHigh _endasm
}
#pragma code
#pragma interrupt IntrruptHandleHigh
void IntrruptHandleHigh(void){
if(PIR1bits.RCIF == 1)
{
PORTAbits.RA1 = 0; //Communication LED ON
C[i] = RCREG; //ReadUSART();
i++;
if(i > 15)
{i = 0;j = 0;}
PIR1bits.RCIF = 0;
}
}
#pragma code IntrruptPriorityLow = 0x18
void IntrruptPriorityLow(void){}
void Transmit(char* pstring)
{
a = 0;
i = 0;
j = 0;
while(*pstring != '\0')
{
while(!(TXSTA & 0x02));
TXREG = *pstring;
pstring ++;
C[a] = 0;
a++;
C[a] = 0;
a++;
}
}
void initial_all(void)
{
BAUDCTL = 0x08; //Baud rate control bits
SPBRG = 0x03; //load Baud Rate Generator Registers
SPBRGH = 0x01;
TXSTA = 0xA4; //Initialize USART Async. transmitter
RCSTA = 0x90; //initialize USART Async. receiver
T1CON = 0x00; //TIMER 1 CONTROL REGISTER SET
TMR1H = 0xC5 ; //TIMER0_HIGH;
TMR1L = 0x62 ; // TIMER0_LOW;
T0CON = 0x08;
TMR0H = 0x3D; // TIMER 0 LOAD FOR 10 mS
TMR0L = 0xCD;
TRISC = 0x89;
TRISD = 0x01;
PTCON1bits.PTEN = TRUE;
}
void initial_intrrupt(void){
RCONbits.IPEN = 1;
INTCONbits.GIE = 1;
INTCONbits.PEIE = 1;
// PIE1bits.ADIE = TRUE; //ADC INTRUPT ENABLE
// IPR1bits.ADIP = 0;
PIE1bits.RCIE = TRUE; //Enable receiver intrrupt
IPR1bits.RCIP = 1;
PIE1bits.TMR1IE = TRUE; //TIMER INTRRUPT ENABLE
IPR1bits.TMR1IP = 0; //PRIORITY LOW
INTCONbits.TMR0IE = 1; //TIMER 0 INTRRUPT ENABLE
INTCON2bits.TMR0IP = 0; //PRIORITY LOW
}
char PowerOn[9] = {"[TEST]"};
unsigned char C[15];
void main()
{
initial_all();
initial_intrrupt();
initial_start();
T0CONbits.TMR0ON = TRUE; // TIMER 0 ON
Transmit(PowerOn);
while(1)
{
}
}
unsigned char index;
volatile unsigned char mydata[50]= "";
ISR(USART1_RX_vect)
{
mydata[index] = UDR1;
if(inData[0] == '0') //Like in that I would give AT Commands whose response comes with '0' as first Character
index++;
}
then I parsed the array
void getdata()
{
unsigned char *getdata ;
getdata = &mydata[0] ; //Getting 1st element and stores in the base address of Pointer
while(*getdata ! = '\0')
{
send_char_uart(*getdata);
getdata++ ;
}
}
volatile unsigned char mydata[10] = "" ; unsigned char i;
// Interrupt Functions
if(PIR1bits.RCIF == 1) //If an Interrupt Occurs then execute block
{
mydata[i] = RCREG ; // Get the data in RCREG Register
if(mydata[0] != NULL ) /*Suppose there is some data in the First element of the array */
i++ ; // Increments i variable
}
//Interrupt Code ends
void get_data()
{
unsigned char *getdata ;
getdata = &mydata[0] ; //Storing the 1st element in Base address
// NO i will print whatever be the content of Pointer
send_char(*getdata) ; // This will give me Character 'M'
//In the same way I append the remaining but not working in PIC Mcu
}
.
.
.
stop_rx = 0;
i = 0;
while (stop_rx == 0)
{
temp = wait_for_byte_with_to();
if (temp == 0x01) // if timeout
{
stop_rx ++;
continue;
}
C[i] = RCREG;
// check the stop condition, if there is any
if (C[i]== 0xff)
stop_rx++;
else
stop_rx = 0;
i ++;
}
.
.
.
/* wait for a uart byte with timeout*/
char wait_for_byte_with_to () {
int i;
for (i = 0; i < 8000; i++ ){ // set the timeout as you see fit
if (PIR1bits.RCIF == 1) // check if a new byte was received
{
return 0x00;
}
}
return 0x01;
}
#pragma code IntrruptPriorityHigh = 0x08
void IntrruptPriorityHigh(void){
_asm goto IntrruptHandleHigh _endasm
}
#pragma code
#pragma interrupt IntrruptHandleHigh
void IntrruptHandleHigh(void){
if(PIR1bits.RCIF == 1)
{
PORTAbits.RA1 = 0; //Communication LED ON
C[i] = RCREG; //ReadUSART();
i++;
if(i > 15)
{i = 0;j = 0;}
PIR1bits.RCIF = 0;
}
}
#pragma code IntrruptPriorityLow = 0x18
void IntrruptPriorityLow(void){}
void Transmit(char* pstring)
{
a = 0;
i = 0;
j = 0;
while(*pstring != '\0')
{
while(!(TXSTA & 0x02));
TXREG = *pstring;
pstring ++;
C[a] = 0;
a++;
C[a] = 0;
a++;
}
}
void initial_all(void)
{
BAUDCTL = 0x08; //Baud rate control bits
SPBRG = 0x03; //load Baud Rate Generator Registers
SPBRGH = 0x01;
TXSTA = 0xA4; //Initialize USART Async. transmitter
RCSTA = 0x90; //initialize USART Async. receiver
T1CON = 0x00; //TIMER 1 CONTROL REGISTER SET
TMR1H = 0xC5 ; //TIMER0_HIGH;
TMR1L = 0x62 ; // TIMER0_LOW;
T0CON = 0x08;
TMR0H = 0x3D; // TIMER 0 LOAD FOR 10 mS
TMR0L = 0xCD;
TRISC = 0x89;
TRISD = 0x01;
PTCON1bits.PTEN = TRUE;
}
void initial_intrrupt(void){
RCONbits.IPEN = 1;
INTCONbits.GIE = 1;
INTCONbits.PEIE = 1;
// PIE1bits.ADIE = TRUE; //ADC INTRUPT ENABLE
// IPR1bits.ADIP = 0;
PIE1bits.RCIE = TRUE; //Enable receiver intrrupt
IPR1bits.RCIP = 1;
PIE1bits.TMR1IE = TRUE; //TIMER INTRRUPT ENABLE
IPR1bits.TMR1IP = 0; //PRIORITY LOW
INTCONbits.TMR0IE = 1; //TIMER 0 INTRRUPT ENABLE
INTCON2bits.TMR0IP = 0; //PRIORITY LOW
}
char PowerOn[9] = {"[TEST]"};
unsigned char C[15],j;
void main()
{
initial_all();
initial_intrrupt();
initial_start();
T0CONbits.TMR0ON = TRUE; // TIMER 0 ON
Transmit(PowerOn);
while(1)
{
Transmit(C[j]);
}
}
C[a]=0; // raz the 1srt car pointed
a++ ;
C[a]=0; terminator of string ? so pstring point to zero and go out of while .. loop
a++
while(1)
{
Transmit(C[j]); // how can evoluate j ?
}
if(DataReady1 == 1)
{
printf(" %s",buffer);
//or Lcdwrite_texte(buffer);
DataReady1 =0; // raz the flag
buffer[0]=0; // raz buffer origine
PIE1bits.RCIE = 1;// re enabled receiving interupt
}
volatile unsigned char in_data[100] = "" , my_flag_rx;
unsigned char index ;
if(PIR1bits.RCIF==1)
{
in_data[index] = RCREG ;
if(in_data[0] == '+' ) // As '+ ' is always the first character
index++ ;
if(RCREG == 'K') { // As 'K' is always the last Character
my_flag_rx = 1 ; }
}
... and if the (index) reached till 'K' then the Flag is set which will act as signal in MAIN function
for Interrupt ocurrance and we will do further Procedure in Main Function ?
volatile unsigned char in_data[100] = "" , my_flag_rx;
volatile unsigned char index ;
if(PIR1bits.RCIF==1)
{
in_data[index] = RCREG ;
if(in_data[0] == '+' ) // As '+ ' is always the first character
index++;
if(RCREG == 'K') { // As 'K' is always the last Character
my_flag_rx = 1 ;
index=0;
}
}
//inside interrupt function
static int i1; // locale variable for storage index
if(PIR1bits.RCIF==1)
{
in_data[i1] = RCREG ;
if (in_data[i1]=='+')
{
i1=0;
Index=0;
in_data[0]='+'; // to store first car '+' or ignore it with i1=-1;
}
if(in_data[i1] == 'K') // As 'K' is always the last Character
{
my_flag_rx = 1 ;
in_data[i1+1]=0; // terminator string after last car 'K' or ignore it by doing in_data[i1]=0;
index=i1;// last index keept
i1=-1;
// optional
// if you want to treat the result without overwritting the buffer and put again RCEN=1 in the main
RCEN=0;
}
i1++;
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?