microC libraries are wrong

General discussion on mikroC.
Post Reply
Author
Message
coskunkazma
Posts: 34
Joined: 30 Aug 2011 07:03

microC libraries are wrong

#1 Post by coskunkazma » 25 Feb 2012 14:29

microC libraries are wrong because, although I have enabled registers it does still not work. Please check it out.

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

Re: microC libraries are wrong

#2 Post by p.erasmus » 25 Feb 2012 16:07

coskunkazma wrote:microC libraries are wrong because, although I have enabled registers it does still not work. Please check it out.
Are you sure !!!
Post your code!!
Last edited by p.erasmus on 25 Feb 2012 18:25, edited 1 time in total.
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

coskunkazma
Posts: 34
Joined: 30 Aug 2011 07:03

Re: microC libraries are wrong

#3 Post by coskunkazma » 25 Feb 2012 17:46

yes, as I before see

Code: Select all

sbit LCD_RS at LATB4_bit;
sbit LCD_EN at LATB5_bit;
sbit LCD_D4 at LATB0_bit;
sbit LCD_D5 at LATB1_bit;
sbit LCD_D6 at LATB2_bit;
sbit LCD_D7 at LATB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;

char atc1[] = "AT";
char atc2[] = "ATE0";

char atc3[50];
char atc4[] = "AT#GPRS=1";
char atc5[100];
char atc6[] = "AT#FTPTO=5000";
char atc7[] = "AT#FTPTYPE=0";
char atc8[50];
char atc9[] = "AT#GPRS=0";
char atc10[21] = "AT#FTPAPP=";
char atc11[] = "ATH";
char atc12[] = "AT#SHDN";
char atc13[] = "AT#WAKE=0";
char atc14[] = "AT$GPSD=2";
char atc15[] = "AT$GPSACP";
char atc16[] = "AT#SELINT=2";
char atc17[50];
char atd[] = "ATD0533527819;";
char atc18[] = "AT#SH=1";// soketi kapatır
char atc19[] = "AT#SCFG=1,1,300,90,600,50";// soket ayarı
char atc20[] = "AT#SO=1";


char read[1024];
char readGPS[200];
int ind_carrier = 0;
int ind = 0;
int indGPS = 0;
short error_counter = 0;
short flag_NO_CRRIER = 1;
short flag_for_NO_CARRIER_check = 0;
short Flag_For_EEPROM_CONFIG = 0;
int eeprom_ind = 0;
short EEPROM_DATA[1024];
int eeprom_location = 0;
int tr = 0, tr1 = 0, tr2 = 0, tr3 = 0, tr4 = 0, tr5 = 0;
int ForcomaCNT = 0;
int ForcomaCNT1 = 0, ForcomaCNT2 = 0;
int comaPOSind = 0;
int comaPOS[13];
char time[13];
char Latitude[13];
char Longitude[13];
char speed[13];
char direction[13];
char date[13];

short FlagForComa = 0;

short f1=1,f2=0,f3=0,f4=0,f5=0;
short timeCNT = 0, LatitudeCNT = 0, LongitudeCNT = 0, speedCNT = 0, directionCNT = 0, dateCNT = 0;
short cntFORok = 0;

void interrupt()
{
 if( PIR3.RC2IF )
 {
    readGPS[indGPS] = UART2_Read();
    indGPS = indGPS + 1;
    if(readGPS[0]=='$' && readGPS[indGPS-2]==13 && readGPS[indGPS-1]==10)
    {
     readGPS[indGPS-2]='\0';
     indGPS=0;
    }
    PIR3.RC2IF=0;
 }

 if( PIR1.RC1IF )
 {
    read[ind] = UART1_Read();
    ind++;
    if(read[0]!='M' && read[1]!='C' && read[2]!='O' && read[3]!='N' && read[4]!='F' && read[ind-2]==13 && read[ind-1]==10)
    {
     read[ind-2]='\0';
     ind_carrier = ind;
     ind = 0;
    }
    if(read[0]=='M' && read[1]=='C' && read[2]=='O' && read[3]=='N' && read[4]=='F' && read[ind-2]==13 && read[ind-1]==10)
    {
     PORTB.F6 = 1;
     read[ind-2] = '\0';
     ind = 0;
     Flag_For_EEPROM_CONFIG = 1;
    }
    PIR1.RC1IF=0;
 }
}

void send_atc(char *s)
{
   while(*s)
   {
      UART1_Write(*s++);
   }
   UART1_Write(0x0D);
   delay_ms(1000);
}

short OK_Response_AT(char *atc)
{
   Lcd_Cmd(_LCD_CLEAR);
   LCD_Out(1,1,atc);
   send_atc(atc);
   LCD_Out(2,1,read);
   while(1)
    {
      if(read[ind_carrier-7] == 'E' && read[ind_carrier-6] == 'R' && read[ind_carrier-5] == 'R' &&
      read[ind_carrier-4] == 'O' && read[ind_carrier-3] == 'R')
      {
        send_atc(atc);
        LCD_Out(1,1,atc);
        LCD_Out(2,1,read);
        Delay_ms(200);
        Lcd_Cmd(_LCD_CLEAR);
        LCD_Out(1,1,"ERROR!");
        error_counter = error_counter+1;
        if(error_counter == 5)
        {
           error_counter = 0;
           return 1;
        }
      }

      if(read[ind_carrier-4] == 'O' && read[ind_carrier-3] == 'K')
      {
        LCD_Out(2,1,read);
        Delay_ms(200);
        Lcd_Cmd(_LCD_CLEAR);
        LCD_Out(1,1,"done!");
        read[0] = '\0';
        return 0;
      }
      if(read[0] == 'C' && read[1] == 'O' && read[2] == 'N' && read[3] == 'N' && read[4] == 'E' &&
      read[5] == 'C' && read[6] == 'T')
      {
        LCD_Out(2,1,read);
        Delay_ms(200);
        Lcd_Cmd(_LCD_CLEAR);
        LCD_Out(1,1,"done!");
        read[0] = '\0';
        return 0;
      }
    }
}

void main()
{
  ANSELC = 0;
  ANSELD = 0;
  PORTB = 0;
  TRISB = 3;
  PORTD = 0;
  TRISD = 0;
//readGPS

//Interrupt
  RCON.IPEN = 1;
  INTCON.GIEH=1;
  INTCON.PEIE=1;
  
  IPR1.RC1IP = 1;//receive interuppt priority enabled
  IPR1.TX1IP = 0;
  
  PIE1.RC1IE=1;
  PIE1.TX1IE = 0;//transmit interrupt enable pin disabled.
  PIE3.RC2IE=1;
  Delay_ms(100);
//LCD
  Delay_ms(100);
  Lcd_Init();
  Lcd_Cmd(_LCD_CLEAR);
  Lcd_Cmd(_LCD_CURSOR_OFF);
  Delay_ms(100);
//UART
  UART1_Init(19200);
  UART2_Init(4800);

  delay_ms(2000);

 while(PORTB.F7 == 1)
 {
  if(Flag_For_EEPROM_CONFIG == 1)
  {
   while(read[eeprom_ind+5] != '\0')
    {
     EEPROM_Write(eeprom_ind, read[eeprom_ind+5]);
     eeprom_ind++;
     EEPROM_Write(eeprom_ind, '\0');
    }
  }
 }

 while(PORTB.F7 == 0)
 {
  while(EEPROM_Read(tr) != '\0')
  {
   if(EEPROM_Read(tr) != '~' && f1 == 1)  //CGDCONT
   {
    atc3[tr1] = EEPROM_Read(tr);
    atc3[tr1+1] = '\0';
    f2=0,f3=0,f4=0,f5=0;
    tr1 = tr1 + 1;
    if(EEPROM_Read(tr+1) == '~')
       f1=0,f2=1;
   }

   else if(EEPROM_Read(tr) != '~' && f2 == 1)  //FTPOPEN
   {
    atc5[tr2] = EEPROM_Read(tr);
    atc5[tr2+1] = '\0';
    f1=0,f3=0,f4=0,f5=0;
    tr2 = tr2 + 1;
    if(EEPROM_Read(tr+1) == '~')
       f2=0,f3=1;
   }

   else if(EEPROM_Read(tr) != '~' && f3 == 1) //FTPPUT
   {
    atc8[tr3] = EEPROM_Read(tr);
    atc8[tr3] = '\0';
    f1=0,f2=0,f4=0,f5=0;
    tr3 = tr3 + 1;
    if(EEPROM_Read(tr+1) == '~')
       f3=0,f4=1;
   }

   else if(EEPROM_Read(tr) != '~' && f4 == 1)  //FTPAPP
   {
    atc10[tr4] = EEPROM_Read(tr);
    atc10[tr4+1] = '\0';
    f1=0,f2=0,f3=0,f5=0;
    tr4 = tr4 + 1;
    if(EEPROM_Read(tr+1) == '~')
       f4=0,f5=1;
   }

   else if(EEPROM_Read(tr) != '~' && f5 == 1)  //SD
   {
    atc17[tr5] = EEPROM_Read(tr);
    atc17[tr5+1] = '\0';
    f1=0,f2=0,f3=0,f4=0;
    tr5 = tr5 + 1;
    if(EEPROM_Read(tr+1) == '~')
       f5=0,f1=1;
   }
   tr = tr + 1;
  }
  delay_ms(100);
  break;
 }

 DELAY_MS(1000);
 while(1)
 {
  while(flag_NO_CRRIER)
  {
   send_atc("AT#ENHRST=1,0");
   Delay_ms(5000);
   if(OK_Response_AT(atc1))
      break;
   if(OK_Response_AT(atc2))
      break;
   if(OK_Response_AT(atc11))
      break;
   if(OK_Response_AT(atc18))
      break;
   if(OK_Response_AT(atc9))
      break;
   if(OK_Response_AT(atc3))
      break;
   if(OK_Response_AT(atc4))
      break;
   if(OK_Response_AT(atc19))
      break;
   if(OK_Response_AT(atc17))
      break;
   if(OK_Response_AT(atc20))
      break;
   flag_NO_CRRIER = 0;
   flag_for_NO_CARRIER_check = 1;
  }

  while(flag_for_NO_CARRIER_check)
  {
   if(readGPS[3] == 'R' && readGPS[4] == 'M' && readGPS[5] == 'C')
   {
      send_atc(readGPS);
      Lcd_Out(2,1,read);
      delay_ms(20000);
   }
    if(read[0] == 'N' && read[1] == 'O' && read[2] == ' ' && read[3] == 'C' && read[4] == 'A' &&
    read[5] == 'R' && read[6] == 'R' && read[7] == 'I' && read[8] == 'E' && read[9] == 'R')
    {
        flag_NO_CRRIER = 1;
        flag_for_NO_CARRIER_check = 0;
    }
  }
 }
}
Last edited by coskunkazma on 02 Mar 2012 09:02, edited 1 time in total.

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

Re: microC libraries are wrong

#4 Post by p.erasmus » 26 Feb 2012 13:51

people will help you however please nobody is going to decode your code can you at least explain what problem you are having and which micro you are using
there are at least 500 different pics so how shall we now what you are working with
also use the code tags when posting code it makes it easier to read your code
Attachments
code.png
code.png (7.04 KiB) Viewed 4197 times
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

coskunkazma
Posts: 34
Joined: 30 Aug 2011 07:03

Re: microC libraries are wrong

#5 Post by coskunkazma » 27 Feb 2012 05:47

I thing your 18F46K22 libraries are wrong, because although I did
interrupt priority setups it is still not working. As you remember before
I sent many e-mails about 18F46K22 UART interrupt while I am using V5.0.
After that you raised EasyPIC V7 and new compiler (V5.30), same code that
was not working runs well.

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: microC libraries are wrong

#6 Post by janko.kaljevic » 27 Feb 2012 17:36

Hello,

Please notice code for UART Interrupt with high priority.
I have tested this code on PIC18F45K22, and it is working fine.

Code: Select all

char uart_rd;

void interrupt(){
  if (RC1IF_bit){
    uart_rd = UART1_Read();
    UART1_Write(uart_rd);
    RC1IF_bit = 0;
  }
}

void main() {
  ANSELC = 0;                     // Configure PORTC pins as digital

  UART1_Init(9600);               // Initialize UART module at 9600 bps
  Delay_ms(100);                  // Wait for UART module to stabilize
  
  IPEN_bit = 1;                // Enable Interrupt levels
  RC1IP_bit = 1;              // Set UART1 Receive Interrupt high level 

  GIEH_bit = 1;               //  Enable High Level Interrupts
  PEIE_bit = 0;                // Disable low level interrupts
  RC1IE_bit = 1;             // Enable UART Receive Interrupts

  while (1) {                     // Endless loop
  }
}
Best regards.

coskunkazma
Posts: 34
Joined: 30 Aug 2011 07:03

Re: microC libraries are wrong

#7 Post by coskunkazma » 02 Mar 2012 05:59

Dear Janko Kaljevic

the problem is still continue. It still does not enter the interrupt. Interrupt priority does not work well. I have modified code that you before sent me in order to test. however it does still not work. PIC is direct connected to away server via UART. Please test below code. while program continues to send data I have send back data to microcontroller via microc's uart terminal. First PORTB's leds turned on, but when send data to uart secondly in order to turn off leds, there is no effect. I think uart priority runs but not well. I thing it is either problem of 18F46K22's libraries or my code problem. Please use 18F46K22.

Code: Select all


char uart_rd[] = "TEST";

void interrupt(){
  if (RC1IF_bit){
    RC1IF_bit = 0;
    PORTB = ~PORTB;
  }
}

void main() {
  ANSELC = 0;                     // Configure PORTC pins as digital
  TRISB = 0;
  PORTB = 0;
  
  UART1_Init(9600);               // Initialize UART module at 9600 bps
  Delay_ms(100);                  // Wait for UART module to stabilize

  IPEN_bit = 1;                // Enable Interrupt levels
  RC1IP_bit = 1;              // Set UART1 Receive Interrupt high level

  GIEH_bit = 1;               //  Enable High Level Interrupts
  PEIE_bit = 0;                // Disable low level interrupts
  RC1IE_bit = 1;             // Enable UART Receive Interrupts

  while (1) {                     // Endless loop
    UART1_Write(uart_rd);
  }
}
Best Regards

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: microC libraries are wrong

#8 Post by janko.kaljevic » 02 Mar 2012 12:09

Hello,

Please try with this code.
You have to read value in interrupt routine, or any new received byte will be discarded and interrupt will not trigger.
Check UART Status register for details regarding this.

Code: Select all

char uart_rd[] = "TEST";
char U1read;

void interrupt(){
  if (RC1IF_bit){
    U1read = UART1_Read();
    LATB = U1read;
    RC1IF_bit = 0;
  }
}

void main() {
  ANSELC = 0;                     // Configure PORTC pins as digital
  TRISB = 0;
  PORTB = 0;

  UART1_Init(9600);               // Initialize UART module at 9600 bps
  Delay_ms(100);                  // Wait for UART module to stabilize

  IPEN_bit = 1;                // Enable Interrupt levels
  RC1IP_bit = 1;              // Set UART1 Receive Interrupt high level

  GIEH_bit = 1;               //  Enable High Level Interrupts
  PEIE_bit = 0;                // Disable low level interrupts
  RC1IE_bit = 1;             // Enable UART Receive Interrupts

  while (1) {                     // Endless loop
    UART1_Write_Text(uart_rd);
  }
}
Best regards.

coskunkazma
Posts: 34
Joined: 30 Aug 2011 07:03

Re: microC libraries are wrong

#9 Post by coskunkazma » 02 Mar 2012 12:49

Hello,

I am testing the code like this, I commented out socket connection (//if(OK_Response_AT(atc20))) line at my code and I send data via uart to PIC, it is interrupted. However, when open code that obtain socket connection and connection is succeed and I send data to PIC via uart, it is may be interrupted I do not know but not works well. This is my problem.

best regards

Post Reply

Return to “mikroC General”