Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] Serial Communication Interrupt Flag in PIC18f4520 and mikrocpro for PIC

Status
Not open for further replies.
For my education as I do not use MikroC, does the "UART1_Write()" function wait for the transmit buffer to be empty or does it just blindly pass the parameter to the TXREG?"

a test on register is done before to fill it

Code:
UART1_Write:
;__Lib_UART_c67g12.c,62 ::                 
;__Lib_UART_c67g12.c,63 ::                 
L_UART1_Write3:
0x0A72        0xB2AD              BTFSC       TXSTA, 1 
0x0A74        0xD002              BRA         L_UART1_Write4
;__Lib_UART_c67g12.c,64 ::                 
0x0A76        0x0000              NOP
0x0A78        0xD7FC              BRA         L_UART1_Write3
L_UART1_Write4:
;__Lib_UART_c67g12.c,65 ::                 
0x0A7A        0xFFAEC42E          MOVFF       FARG_UART1_Write_data_, TXREG1
;__Lib_UART_c67g12.c,66 ::                 
L_end_UART1_Write:
0x0A7E        0x0012              RETURN      0
 

Thanks Paul. If it didn't check the TRMT bit it would explain some of djc's problems but we can forget that as a cause now.

Brian.
 

Hi all,
Issue seems to be solved. It is tricky to control MAX485. MAX_CONTROL pin played a crucial role. It has to be made high at particular instance only. So as brian posted, i waited for the termination character,';' in this case. Once i got it, then a flag is set. And using that flag in main, data is transferred with some delay before making MAX_CONTROL low.Here is the code.
Code:
#include <math.h>
#define MAX_CONTROL   PORTC.B5
#define Test          PORTD.B0  //Pin 19

volatile unsigned int index=0,sdat=0,sdat_1=0,read=0,write=0,garbage=0;
volatile unsigned char input_string[12],*string;
char FND_0='1',FND_1=2,i=0;

/*********************************************************/
//void interrupt(){
void Interrupts() iv 0x0008 ics ICS_AUTO{

  if((RCIF_bit==1)) {

                      Test=~Test;

          input_string[index]=RCREG; // store the reading char

          if(input_string[index]==59) 
           { 
             write=1;
           //  index=0;
           }
           index++;
           RCIF_bit=0;
         
          
          if(index==12) index=0;


      }

}


void main() {

     TRISD = 0x00;            /*//PortD as output*/
     PORTD = 0x00;            /*//Initial value*/
     TRISC = 0b10000000;
     TRISB = 0x55;             //0 as o/p, 1 as i/p
     PORTB = 0x00;
     INTCON =0b11000000 ;           /*//0xc0;0xa0*/



    /*TXSTA  = 0b00100000;
     RCSTA = 0b10010000;

     BAUDCON.BRG16 = 0;
     TXSTA.BRGH    = 0;
     //SPBRGH:SPBRG = 129;   //for 20MHz crystal
     SPBRG = 31;   //for 20MHz crystal*/


     UART1_Init(9600);
     Delay_ms(2);
     //PIR1.RCIF=0;
     sdat=RCREG;
     PIE1 = 0b00100000;  //RCIE bit enabled
     IPR1.RCIP = 1;
     //IPR1.TXIP = 1;
     RCON.IPEN = 1;
     PIE1 = 0b00100000;  //RCIE bit enabled
     INTCON.GIE=1;
     MAX_CONTROL=0;
     index=0;
     write=0;
         while(1){
                  if(write==1){
                                  MAX_CONTROL =1;
                                  for(i=0;i<index;i++){
                                  UART1_Write(input_string[i]);
                                  Delay_us(10);
                                  }
                                  Delay_ms(1);
                                  MAX_CONTROL =0;
                      write=0;
                      index=0;
                  }
         };

}
I haven't checked any error flags here.But this code is working somehow. Now i have to implement this logic in my main program. Thank all of you guys. You helped me a lot
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top