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.

[SOLVED] problem in MikroC code for LCD

Status
Not open for further replies.
Re: problem in MikroC coad for LCD

MikroC compiler is not capable to set IRP bit.
IRP is bank select bit used for indirect addressing.
IRP=0 -> Bank 0,1
IRP=1 -> Bank 2,3

My question is that:
how i use the above given instructions? i.e; at the start of program i use IRP=0 and in the mid of the program i have to use IRP=1????????
 

Re: problem in MikroC coad for LCD

Can you zip and upload your .dsn file and can you clearly explain what routines you want to run? What numbers are displayed on the lcd. what is the range of numbers. what does the numbers do, etc.,??? explain??

In the datasheet http://ww1.microchip.com/downloads/en/devicedoc/39582b.pdf page 31 it is mentioned that " The INDF register is not a physical register. Addressing
the INDF register will cause indirect addressing.
Indirect addressing is possible by using the INDF register.
Any instruction using the INDF register actually
accesses the register pointed to by the File Select Register,
FSR. Reading the INDF register itself, indirectly
(FSR = 0) will read 00h. Writing to the INDF register
indirectly results in a no operation (although status bits
may be affected). An effective 9-bit address is obtained
by concatenating the 8-bit FSR register and the IRP bit"

For direct addressing to select banks RP0 and RP1 bits have to be configured. In indirect addressing to select different banks IRP bit and 8th bit of FSR register is configured.

Direct addressing mode

RP1:RP0

0 0 selects Bank 0
0 1 selects Bank 1
1 0 selects Bank 2
1 1 selects Bank 3


Indirect addressing mode


IRP bit : 8th bit of FSR register


0 0 selects Bank 0
0 1 selects Bank 1
1 0 selects Bank 2
1 1 selects Bank 3


check about status register here
http://www.microcontrollerboard.com/pic_memory_organization.html

STATUS register is a SFR which is accessible from any bank.

STATUS register is an 8 bit register. 7th bit is IRP, 6th bit is RP1, 5th bit is RP0.

So if you need to do indirect addressing then you have to set or clear the IRP bit of STATUS register.

So you can do like

Code:
 STATUS.IRP = 0;

or

Code:
 STATUS.IRP = 1;

http://www.pictutorials.com/The_Status_Register.htm
 
Last edited:

I wrote the instruction
Code:
STATUS.IRP = 1;
but the result is the same....

my source code is :
Code:
// OUTPUTS
#define GEN_CONT PORTE.f2
#define LED PORTB.f2
#define MAIN_CONT PORTC.F0
#define CHOWK PORTC.F1
#define IGNITION PORTC.F2
#define SELF PORTC.F3

// INPUTS
#define GEN PORTA.F0
#define MAIN PORTA.F1

#define ENTER PORTD.F0
#define RESET PORTD.F1
#define UP PORTD.F2
#define DOWN PORTD.F3

//CONSTANTS
#define T 100   //DELAYS
#define P 1     //FOR MAIN AND GEN INPUTS
#define A 0     //FOR MAIN AND GEN INPUTS

sbit LCD_RS at RD5_bit;
sbit LCD_EN at RD4_bit;
sbit LCD_D4 at RC4_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D7 at RC7_bit;

sbit LCD_RS_Direction at TRISD5_bit;
sbit LCD_EN_Direction at TRISD4_bit;
sbit LCD_D4_Direction at TRISC4_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D7_Direction at TRISC7_bit;

 unsigned char cnt;
void interrupt()
{
     if(TMR0IF_bit)
     {  cnt++;
        TMR0IF_bit=0;


        if(cnt>=10)
        {
           LED=~LED;
           cnt=0;
        }

       TMR0=0;
     }

}

void gen(void);
void start(void);
void main()
{
    unsigned int i=0,x=0,j=0;  //i=loops ; x=passward ; J=While lock

 //..............INITIALIZATIONS............................................
 
/*   ANSEL  = 0;                        // Configure AN pins as digital I/O
  ANSELH = 0;
  C1ON_bit = 0;                      // Disable comparators
  C2ON_bit = 0;     */
  
  // CONFIGURING SFRs:
  cnt=0;
  TMR0=0;   // loading vlaue of timer0 interrupt
  OPTION_REG=0x87;  // for timer 0; presscaller 1; 256
  ADCON1=0x06;   // adc reg initialization
  INTCON=0xA0;  // for timer0  ; interrupt reg initilization
 // STATUS.F7=0;
  //STATUS.IRP=0;
  //asm BCF STATUS,IRP
  
  // OUTPUTS:
  TRISB.f2 = 0x00;   //led out put
  TRISE.F2=0;        // gen cont output
  TRISC=0x00;        // portC output For LCD
  PORTC=0X00;        //  initilization port c
  
  // INPUTS:
  TRISD.F0=0XFF;    // ENTER
  TRISD.F1=0XFF;   // RESET
  TRISD.F2=0XFF;    // UP
  TRISD.F3=0XFF;    // DOWN
  TRISA = 0xff;     // port A as input

    // TRISD.F4=0XFF;      ALREADY DIRECTED AT LCD INITILIZATION
    //  TRISD.F5=0XFF;
 //................................................................................
 
 
  lcd_init();
  Delay_ms(500);
  
    if(MAIN==P)    // if main is Present.
    {
       start();

    }
     
  while(1)
  {
           
               /*      if(ENTER==0)
                     {
                          Lcd_Cmd(_LCD_CLEAR);                    // Clear display
                          Lcd_Cmd(_LCD_CURSOR_OFF);
                          Lcd_Out(1,1,"Enter Passward");
                             while(ENTER==0)
                             {
                               Lcd_Out(1,x,"Enter Passward");
                                Lcd_Out(1,1,j);
                             }
                          Delay_ms(1000);
                     }                        */
     
    if(MAIN==A)    // if main is absent.
    {
     Delay_ms(4000); // wait for 4 seconds to ensure power failure
    if(MAIN==P)     //check again
      continue;
      
     //Delay_ms(1000);
     Lcd_Cmd(_LCD_CLEAR);                    // Clear display
     Lcd_Cmd(_LCD_CURSOR_OFF);
     Lcd_Out(1,1,"Mains Not Avail");
     Lcd_Out(2,1,"Starting Genset");
     Delay_ms(1000);
     gen();

    }
    else           // if main is present .........
    {

      Lcd_Cmd(_LCD_CLEAR);                    // Clear display
      Lcd_Cmd(_LCD_CURSOR_OFF); 
      Lcd_Out(1,1,"Mains ok..");   // Write text in first row
      Lcd_Out(2,1,"Mains Overload");
      Delay_ms(2000);
     //  GEN_CONT=0;   //Turn off generator contactor
       //MAIN_CONT=1;   //Turn on main contactor
      Lcd_Cmd(_LCD_CLEAR);                    // Clear display
      Lcd_Out(1,3,"Shenztech");   // Write text in first row
      Lcd_Out(2,4,"Pvt Ltd");
      Delay_ms(1000);
    }
    


              for(i=0; i<96; i++)
              {
                       Lcd_Cmd(_LCD_SHIFT_RIGHT);
                       Delay_ms(T);
                       
                        if(MAIN==A)
                        {
                          i=96;
                        }
              }


   }    // while
   
}      // main
//..............................;;;;;;;.........................................

void gen()
{     
      int i;
     MAIN_CONT=0;
      IGNITION=1;
      Delay_ms(2000);
      CHOWK=1;
      Delay_ms(5000);//Chowk on for 5 seconds
      CHOWK=0;
      for(i=0; i<3; i++)
      {
      
               if(i==2)
               {
                   CHOWK=1;
                   Delay_ms(5000);//Chowk on for 5 seconds
                   CHOWK=0;
               }
               
       SELF=1;
       Delay_ms(2000);  //self on for 2 seconds
       SELF=0;
       Delay_ms(4000);  //self off for 4 seconds
       

       if(MAIN==P)     //if Main resumes
             {
                 i=3;
                 GEN_CONT=0;
                 IGNITION=0;
                 SELF=0;
                 Delay_ms(2000);  //self on for 2 seconds
                 MAIN_CONT=1;
             }

             if(GEN==P)     //if generator ON
             {
                 i=3;
             }
      }
      
      if(GEN==P && MAIN==A)     // if generator ON
      {
       Delay_ms(1000);
      Lcd_Cmd(_LCD_CLEAR);                    // Clear display
      Lcd_Cmd(_LCD_CURSOR_OFF);
      Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
      Lcd_Out(1,1,"Warming Up...");   // Write text in first row
       Delay_ms(5000);
       GEN_CONT=1;      // transfer load on genset after warmup
      
      Delay_ms(300);

      Lcd_Cmd(_LCD_CLEAR);                    // Clear display
      Lcd_Cmd(_LCD_CURSOR_OFF);
      Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
      Lcd_Out(1,1,"frequency  volts");   // Write text in first row
      Lcd_Out(2,1," . Hz     . V");
      // lcd_init();
      Delay_ms(2000);

      }
      else
      if(GEN==A && MAIN==A)    // if generator is still off; i.e; can't start
      {
      Delay_ms(1000);

      Lcd_Cmd(_LCD_CLEAR);                    // Clear display
      Lcd_Cmd(_LCD_CURSOR_OFF);
      Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
      Lcd_Out(1,2,"< ERROR >");
      Lcd_Out(2,1,"Fails to start..");   // Write text in first row

      IGNITION=0;        //Turn off the genset
      MAIN_CONT=0;
      while(MAIN==A && GEN==A); //stuck here untill reset/restart the controller board (IF main and generator both are absent)
        Lcd_Cmd(_LCD_CLEAR);                    // Clear display
      Lcd_Cmd(_LCD_CURSOR_OFF);

      }
      
      for(;MAIN==A;)   //untill main absent
      {

          if (MAIN==A)      // if main absent
            GEN_CONT=1;     // Turn on generator contactor
            MAIN_CONT=0;    // Turn off main contactor
             while(MAIN==A); // stay here until main resumes

         if (MAIN==P)       //if main presents or after main resumes
           { 
             GEN_CONT=0;
             Delay_ms(1000);
             IGNITION=0; //Turn off the genset
             Delay_ms(2000);
             MAIN_CONT=1;
             Lcd_Cmd(_LCD_CLEAR);                    // Clear display
             Lcd_Out(1,3,"Shenztech");   // Write text in first row
             Lcd_Out(2,4,"Pvt Ltd");
           }
      }
}

void start()
 {
 
 //STATUS.IRP=1;
 // asm BSF STATUS,RP1
 // asm BSF STATUS,RP0  // ACCESS BANK 2
  
  GEN_CONT=0;
      MAIN_CONT=0;
      Lcd_Cmd(_LCD_CLEAR);                    // Clear display
      Lcd_Cmd(_LCD_CURSOR_OFF);
      Lcd_Out(1,1,"Mains ok..");   // Write text in first row
      Lcd_Out(2,1,"Please Wait.....");
      Delay_ms(3000);

      MAIN_CONT=1;
      Lcd_Cmd(_LCD_CLEAR);                    // Clear display
      Lcd_Cmd(_LCD_CURSOR_OFF);
      Lcd_Out(1,1,"Mains ok..");   // Write text in first row
      Lcd_Out(2,1,"Mains Overload");
         Delay_ms(2000);

         Lcd_Cmd(_LCD_CLEAR);                    // Clear display
         Lcd_Cmd(_LCD_CURSOR_OFF);               // Cursor off
         Lcd_Out(1,3,"Shenztech");   // Write text in first row
         Lcd_Out(2,4,"Pvt Ltd");
 }

i don't know how to attach the file , therefore i am uploading the image of my project:
ATS Test.png


problem rises when i add this routine:
Code:
void start()
 {
 
 //STATUS.IRP=1;
 // asm BSF STATUS,RP1
 // asm BSF STATUS,RP0  // ACCESS BANK 2
  
  GEN_CONT=0;
      MAIN_CONT=0;
      Lcd_Cmd(_LCD_CLEAR);                    // Clear display
      Lcd_Cmd(_LCD_CURSOR_OFF);
      Lcd_Out(1,1,"Mains ok..");   // Write text in first row
      Lcd_Out(2,1,"Please Wait.....");
      Delay_ms(3000);

      MAIN_CONT=1;
      Lcd_Cmd(_LCD_CLEAR);                    // Clear display
      Lcd_Cmd(_LCD_CURSOR_OFF);
      Lcd_Out(1,1,"Mains ok..");   // Write text in first row
      Lcd_Out(2,1,"Mains Overload");
         Delay_ms(2000);

         Lcd_Cmd(_LCD_CLEAR);                    // Clear display
         Lcd_Cmd(_LCD_CURSOR_OFF);               // Cursor off
         Lcd_Out(1,3,"Shenztech");   // Write text in first row
         Lcd_Out(2,4,"Pvt Ltd");
 }

after successful compilation, the compiler show me the following messages:
IRP error.png

The numbers to be displayed are the frequency of the generator detected by RA2. can i use only button function there??
please tell me if any further explanations about the problem are required.
A lot of Thanks.
 
Last edited:

Will check your code later. Can you explain clearly what the buttons have to do? and why do you want to select banks? The warnings about IRP bit is something related to the mikroC Compiler. Have you checked wheather the code runs properly? Are you using any ATS.c file in your project. Have you included it?
 
Last edited:

Will check your code later. Can you explain clearly what the buttons have to do? and why do you want to select banks? The warnings about IRP bit is something related to the mikroC Compiler. Have you checked wheather the code runs properly? Are you using any ATS.c file in your project. Have you included it?

The function of the button is to set the self On time, self off time, generator warmup time, chowk on and off times from 000sec to 999sec.

No code doesn't run properly. problem occurs in LCD display routines it doesn't display the correct message on the LCD screen on start-up and may be on any other time but disturbance on start-up is must. i.e; when power supply is connected to the circuit it should display

Mains ok..
Please wait.....


but it displays:
< ERROR >
ch

and after that it starts displaying the correct data. other circuit i.e; input detection and output bit set and reset works fine.

NO i didn't include any ATS.c file in the project. my project name is ATS.mcppi
 
Last edited:

Can you step by step explain what the buttons have to do, so that I can code it. Also you don't have to use the IRP bit for your program.

Check the attachment. It is displaying "Starting Genset"

-------------------------update-------------------------

Now it is displaying the messages. If you give me the step by step flow of the program, I will try to code.

Code:
// OUTPUTS
#define GEN_CONT PORTE.f2
#define LED PORTB.f2
#define MAIN_CONT PORTC.F0
#define CHOWK PORTC.F1
#define IGNITION PORTC.F2
#define SELF PORTC.F3

// INPUTS
#define GEN PORTA.F0
#define MAIN PORTA.F1

#define ENTER PORTD.F0
#define RESET PORTD.F1
#define UP PORTD.F2
#define DOWN PORTD.F3

//CONSTANTS
#define T 100   //DELAYS
#define P 1     //FOR MAIN AND GEN INPUTS
#define A 0     //FOR MAIN AND GEN INPUTS

sbit LCD_RS at RD5_bit;
sbit LCD_EN at RD4_bit;
sbit LCD_D4 at RC4_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D7 at RC7_bit;

sbit LCD_RS_Direction at TRISD5_bit;
sbit LCD_EN_Direction at TRISD4_bit;
sbit LCD_D4_Direction at TRISC4_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D7_Direction at TRISC7_bit;

void gen(void);
void start(void);

unsigned char cnt;

void interrupt()
{
     if(TMR0IF_bit)
     {  cnt++;
        TMR0IF_bit=0;

        if(cnt>=10)
        {
           LED=~LED;
           cnt=0;
        }

       TMR0=0;
     }

}

void gen()
{
      int i;
      MAIN_CONT=0;
      IGNITION=1;
      Delay_ms(2000);
      CHOWK=1;
      Delay_ms(5000);                           //Chowk on for 5 seconds
      CHOWK=0;
      
      for(i=0; i<3; i++)
      {
          if(i==2)
          {
              CHOWK=1;
              Delay_ms(5000);                   //Chowk on for 5 seconds
              CHOWK=0;
          }

          SELF=1;
          Delay_ms(2000);                       //self on for 2 seconds
          SELF=0;
          Delay_ms(4000);                       //self off for 4 seconds


          if(MAIN==P)                           //if Main resumes
          {
              i=3;
              GEN_CONT=0;
              IGNITION=0;
              SELF=0;
              Delay_ms(2000);                   //self on for 2 seconds
              MAIN_CONT=1;
          }

          if(GEN==P)                            //if generator ON
          {
              i=3;
          }
      }

      if(GEN==P && MAIN==A)                     // if generator ON
      {
           Delay_ms(1000);
           Lcd_Cmd(_LCD_CLEAR);                 // Clear display
           Lcd_Cmd(_LCD_CURSOR_OFF);
           Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
           Lcd_Out(1,1,"Warming Up...");        // Write text in first row
           Delay_ms(5000);
           GEN_CONT=1;                          // transfer load on genset after warmup
           Delay_ms(300);
           Lcd_Cmd(_LCD_CLEAR);                 // Clear display
           Lcd_Cmd(_LCD_CURSOR_OFF);
           Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
           Lcd_Out(1,1,"frequency  volts");     // Write text in first row
           Lcd_Out(2,1," . Hz     . V");
           Delay_ms(2000);

      }
      else if(GEN==A && MAIN==A)                // if generator is still off; i.e; can't start
      {
           Delay_ms(1000);
           Lcd_Cmd(_LCD_CLEAR);                 // Clear display
           Lcd_Cmd(_LCD_CURSOR_OFF);
           Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
           Lcd_Out(1,2,"< ERROR >");
           Lcd_Out(2,1,"Fails to start..");     // Write text in first row

           IGNITION=0;                          //Turn off the genset
           MAIN_CONT=0;
           while(MAIN==A && GEN==A);            //stuck here untill reset/restart the controller board (IF main and generator both are absent)
           Lcd_Cmd(_LCD_CLEAR);                 // Clear display
           Lcd_Cmd(_LCD_CURSOR_OFF);

      }

      for(;MAIN==A;)                            //untill main absent
      {

          if (MAIN==A) {                           // if main absent
              GEN_CONT=1;                          // Turn on generator contactor
              MAIN_CONT=0;
          }                                        // Turn off main contactor
          
          while(MAIN==A);                          // stay here until main resumes

         if (MAIN==P)                              //if main presents or after main resumes
           {
             GEN_CONT=0;
             Delay_ms(1000);
             IGNITION=0;                           //Turn off the genset
             Delay_ms(2000);
             MAIN_CONT=1;
             Lcd_Cmd(_LCD_CLEAR);                  // Clear display
             Lcd_Out(1,3,"Shenztech");             // Write text in first row
             Lcd_Out(2,4,"Pvt Ltd");
           }
      }
}

void start()
 {

      //STATUS.IRP=1;
      // asm BSF STATUS,RP1
      // asm BSF STATUS,RP0                        // ACCESS BANK 2

      GEN_CONT=0;
      MAIN_CONT=0;
      Lcd_Cmd(_LCD_CLEAR);                         // Clear display
      Lcd_Cmd(_LCD_CURSOR_OFF);
      Lcd_Out(1,1,"Mains ok..");                   // Write text in first row
      Lcd_Out(2,1,"Please Wait.....");
      Delay_ms(3000);

      MAIN_CONT=1;
      Lcd_Cmd(_LCD_CLEAR);                         // Clear display
      //Lcd_Cmd(_LCD_CURSOR_OFF);
      Lcd_Out(1,1,"Mains ok..");                   // Write text in first row
      Lcd_Out(2,1,"Mains Overload");
      Delay_ms(2000);

      Lcd_Cmd(_LCD_CLEAR);                         // Clear display
      //Lcd_Cmd(_LCD_CURSOR_OFF);                  // Cursor off
      Lcd_Out(1,3,"Shenztech");                    // Write text in first row
      Lcd_Out(2,4,"Pvt Ltd");
}

void main() {

     unsigned int i=0,x=0,j=0;                     //i=loops ; x=passward ; J=While lock

     //..............INITIALIZATIONS............................................

     /*ANSEL  = 0;                                 // Configure AN pins as digital I/O
     ANSELH = 0;
     C1ON_bit = 0;                                 // Disable comparators
     C2ON_bit = 0;*/

     // CONFIGURING SFRs:
     cnt=0;
     TMR0=0;                                       // loading vlaue of timer0 interrupt
     OPTION_REG=0x87;                              // for timer 0; presscaller 1: 256
     ADCON1=0x06;                                  // adc reg initialization
     INTCON=0xA0;                                  // for timer0  ; interrupt reg initilization
     // STATUS.F7=0;
     //STATUS.IRP=0;
     //asm BCF STATUS,IRP

     // OUTPUTS:
     TRISB.f2 = 0;                                 //led out put
     TRISE.F2 = 0;                                 // gen cont output
     TRISC = 0x00;                                 // portC output For LCD
     PORTC = 0X00;                                 //  initilization port c

     // INPUTS:
     TRISD.F0= 1;                                  // ENTER
     TRISD.F1= 1;                                  // RESET
     TRISD.F2= 1;                                  // UP
     TRISD.F3= 1;                                  // DOWN
     TRISA = 0xFF;                                 // port A as input

     // TRISD.F4=0XFF;                             // ALREADY DIRECTED AT LCD INITILIZATION
     //  TRISD.F5=0XFF;
     //................................................................................

     Lcd_Init();
     Delay_ms(500);

     //if(MAIN==P)                                         // if main is Present.
     //{
         start();

     //}

     while(1) {

            /*if(ENTER==0)
            {
                 Lcd_Cmd(_LCD_CLEAR);                      // Clear display
                 Lcd_Cmd(_LCD_CURSOR_OFF);
                 Lcd_Out(1,1,"Enter Passward");
                 while(ENTER==0)
                 {
                  Lcd_Out(1,x,"Enter Passward");
                  Lcd_Out(1,1,j);
                 }
                 Delay_ms(1000);
            }                        */

           if(MAIN==A)                                     // if main is absent.
           {
               Delay_ms(4000);                             // wait for 4 seconds to ensure power failure
               if(MAIN==P)                                 //check again
               continue;

               //Delay_ms(1000);
               Lcd_Cmd(_LCD_CLEAR);                        // Clear display
               Lcd_Cmd(_LCD_CURSOR_OFF);
               Lcd_Out(1,1,"Mains Not Avail");
               Lcd_Out(2,1,"Starting Genset");
               Delay_ms(1000);
               gen();

           }
           else                                           // if main is present .........
           {

               Lcd_Cmd(_LCD_CLEAR);                       // Clear display
               Lcd_Cmd(_LCD_CURSOR_OFF);
               Lcd_Out(1,1,"Mains ok..");                 // Write text in first row
               Lcd_Out(2,1,"Mains Overload");
               Delay_ms(2000);
               //  GEN_CONT=0;                            //Turn off generator contactor
               //MAIN_CONT=1;                             //Turn on main contactor
               Lcd_Cmd(_LCD_CLEAR);                       // Clear display
               Lcd_Out(1,3,"Shenztech");                  // Write text in first row
               Lcd_Out(2,4,"Pvt Ltd");
               Delay_ms(1000);
           }



           for(i=0; i<96; i++)
           {
               Lcd_Cmd(_LCD_SHIFT_RIGHT);
               Delay_ms(T);

               if(MAIN==A)
               {
                    i=96;
               }
           }


   }                                                      // while
}
 

Attachments

  • ss4.jpg
    ss4.jpg
    249.6 KB · Views: 64
  • pic16f877a.rar
    16.9 KB · Views: 65
Last edited:

Can you step by step explain what the buttons have to do, so that I can code it. Also you don't have to use the IRP bit for your program.

Check the attachment. It is displaying "Starting Genset"

-------------------------update-------------------------

Now it is displaying the messages. If you give me the step by step flow of the program, I will try to code.

Code:
// OUTPUTS
#define GEN_CONT PORTE.f2
#define LED PORTB.f2
#define MAIN_CONT PORTC.F0
#define CHOWK PORTC.F1
#define IGNITION PORTC.F2
#define SELF PORTC.F3

// INPUTS
#define GEN PORTA.F0
#define MAIN PORTA.F1

#define ENTER PORTD.F0
#define RESET PORTD.F1
#define UP PORTD.F2
#define DOWN PORTD.F3

//CONSTANTS
#define T 100   //DELAYS
#define P 1     //FOR MAIN AND GEN INPUTS
#define A 0     //FOR MAIN AND GEN INPUTS

sbit LCD_RS at RD5_bit;
sbit LCD_EN at RD4_bit;
sbit LCD_D4 at RC4_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D7 at RC7_bit;

sbit LCD_RS_Direction at TRISD5_bit;
sbit LCD_EN_Direction at TRISD4_bit;
sbit LCD_D4_Direction at TRISC4_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D7_Direction at TRISC7_bit;

void gen(void);
void start(void);

unsigned char cnt;

void interrupt()
{
     if(TMR0IF_bit)
     {  cnt++;
        TMR0IF_bit=0;

        if(cnt>=10)
        {
           LED=~LED;
           cnt=0;
        }

       TMR0=0;
     }

}

void gen()
{
      int i;
      MAIN_CONT=0;
      IGNITION=1;
      Delay_ms(2000);
      CHOWK=1;
      Delay_ms(5000);                           //Chowk on for 5 seconds
      CHOWK=0;
      
      for(i=0; i<3; i++)
      {
          if(i==2)
          {
              CHOWK=1;
              Delay_ms(5000);                   //Chowk on for 5 seconds
              CHOWK=0;
          }

          SELF=1;
          Delay_ms(2000);                       //self on for 2 seconds
          SELF=0;
          Delay_ms(4000);                       //self off for 4 seconds


          if(MAIN==P)                           //if Main resumes
          {
              i=3;
              GEN_CONT=0;
              IGNITION=0;
              SELF=0;
              Delay_ms(2000);                   //self on for 2 seconds
              MAIN_CONT=1;
          }

          if(GEN==P)                            //if generator ON
          {
              i=3;
          }
      }

      if(GEN==P && MAIN==A)                     // if generator ON
      {
           Delay_ms(1000);
           Lcd_Cmd(_LCD_CLEAR);                 // Clear display
           Lcd_Cmd(_LCD_CURSOR_OFF);
           Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
           Lcd_Out(1,1,"Warming Up...");        // Write text in first row
           Delay_ms(5000);
           GEN_CONT=1;                          // transfer load on genset after warmup
           Delay_ms(300);
           Lcd_Cmd(_LCD_CLEAR);                 // Clear display
           Lcd_Cmd(_LCD_CURSOR_OFF);
           Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
           Lcd_Out(1,1,"frequency  volts");     // Write text in first row
           Lcd_Out(2,1," . Hz     . V");
           Delay_ms(2000);

      }
      else if(GEN==A && MAIN==A)                // if generator is still off; i.e; can't start
      {
           Delay_ms(1000);
           Lcd_Cmd(_LCD_CLEAR);                 // Clear display
           Lcd_Cmd(_LCD_CURSOR_OFF);
           Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
           Lcd_Out(1,2,"< ERROR >");
           Lcd_Out(2,1,"Fails to start..");     // Write text in first row

           IGNITION=0;                          //Turn off the genset
           MAIN_CONT=0;
           while(MAIN==A && GEN==A);            //stuck here untill reset/restart the controller board (IF main and generator both are absent)
           Lcd_Cmd(_LCD_CLEAR);                 // Clear display
           Lcd_Cmd(_LCD_CURSOR_OFF);

      }

      for(;MAIN==A;)                            //untill main absent
      {

          if (MAIN==A) {                           // if main absent
              GEN_CONT=1;                          // Turn on generator contactor
              MAIN_CONT=0;
          }                                        // Turn off main contactor
          
          while(MAIN==A);                          // stay here until main resumes

         if (MAIN==P)                              //if main presents or after main resumes
           {
             GEN_CONT=0;
             Delay_ms(1000);
             IGNITION=0;                           //Turn off the genset
             Delay_ms(2000);
             MAIN_CONT=1;
             Lcd_Cmd(_LCD_CLEAR);                  // Clear display
             Lcd_Out(1,3,"Shenztech");             // Write text in first row
             Lcd_Out(2,4,"Pvt Ltd");
           }
      }
}

void start()
 {

      //STATUS.IRP=1;
      // asm BSF STATUS,RP1
      // asm BSF STATUS,RP0                        // ACCESS BANK 2

      GEN_CONT=0;
      MAIN_CONT=0;
      Lcd_Cmd(_LCD_CLEAR);                         // Clear display
      Lcd_Cmd(_LCD_CURSOR_OFF);
      Lcd_Out(1,1,"Mains ok..");                   // Write text in first row
      Lcd_Out(2,1,"Please Wait.....");
      Delay_ms(3000);

      MAIN_CONT=1;
      Lcd_Cmd(_LCD_CLEAR);                         // Clear display
      //Lcd_Cmd(_LCD_CURSOR_OFF);
      Lcd_Out(1,1,"Mains ok..");                   // Write text in first row
      Lcd_Out(2,1,"Mains Overload");
      Delay_ms(2000);

      Lcd_Cmd(_LCD_CLEAR);                         // Clear display
      //Lcd_Cmd(_LCD_CURSOR_OFF);                  // Cursor off
      Lcd_Out(1,3,"Shenztech");                    // Write text in first row
      Lcd_Out(2,4,"Pvt Ltd");
}

void main() {

     unsigned int i=0,x=0,j=0;                     //i=loops ; x=passward ; J=While lock

     //..............INITIALIZATIONS............................................

     /*ANSEL  = 0;                                 // Configure AN pins as digital I/O
     ANSELH = 0;
     C1ON_bit = 0;                                 // Disable comparators
     C2ON_bit = 0;*/

     // CONFIGURING SFRs:
     cnt=0;
     TMR0=0;                                       // loading vlaue of timer0 interrupt
     OPTION_REG=0x87;                              // for timer 0; presscaller 1: 256
     ADCON1=0x06;                                  // adc reg initialization
     INTCON=0xA0;                                  // for timer0  ; interrupt reg initilization
     // STATUS.F7=0;
     //STATUS.IRP=0;
     //asm BCF STATUS,IRP

     // OUTPUTS:
     TRISB.f2 = 0;                                 //led out put
     TRISE.F2 = 0;                                 // gen cont output
     TRISC = 0x00;                                 // portC output For LCD
     PORTC = 0X00;                                 //  initilization port c

     // INPUTS:
     TRISD.F0= 1;                                  // ENTER
     TRISD.F1= 1;                                  // RESET
     TRISD.F2= 1;                                  // UP
     TRISD.F3= 1;                                  // DOWN
     TRISA = 0xFF;                                 // port A as input

     // TRISD.F4=0XFF;                             // ALREADY DIRECTED AT LCD INITILIZATION
     //  TRISD.F5=0XFF;
     //................................................................................

     Lcd_Init();
     Delay_ms(500);

     //if(MAIN==P)                                         // if main is Present.
     //{
         start();

     //}

     while(1) {

            /*if(ENTER==0)
            {
                 Lcd_Cmd(_LCD_CLEAR);                      // Clear display
                 Lcd_Cmd(_LCD_CURSOR_OFF);
                 Lcd_Out(1,1,"Enter Passward");
                 while(ENTER==0)
                 {
                  Lcd_Out(1,x,"Enter Passward");
                  Lcd_Out(1,1,j);
                 }
                 Delay_ms(1000);
            }                        */

           if(MAIN==A)                                     // if main is absent.
           {
               Delay_ms(4000);                             // wait for 4 seconds to ensure power failure
               if(MAIN==P)                                 //check again
               continue;

               //Delay_ms(1000);
               Lcd_Cmd(_LCD_CLEAR);                        // Clear display
               Lcd_Cmd(_LCD_CURSOR_OFF);
               Lcd_Out(1,1,"Mains Not Avail");
               Lcd_Out(2,1,"Starting Genset");
               Delay_ms(1000);
               gen();

           }
           else                                           // if main is present .........
           {

               Lcd_Cmd(_LCD_CLEAR);                       // Clear display
               Lcd_Cmd(_LCD_CURSOR_OFF);
               Lcd_Out(1,1,"Mains ok..");                 // Write text in first row
               Lcd_Out(2,1,"Mains Overload");
               Delay_ms(2000);
               //  GEN_CONT=0;                            //Turn off generator contactor
               //MAIN_CONT=1;                             //Turn on main contactor
               Lcd_Cmd(_LCD_CLEAR);                       // Clear display
               Lcd_Out(1,3,"Shenztech");                  // Write text in first row
               Lcd_Out(2,4,"Pvt Ltd");
               Delay_ms(1000);
           }



           for(i=0; i<96; i++)
           {
               Lcd_Cmd(_LCD_SHIFT_RIGHT);
               Delay_ms(T);

               if(MAIN==A)
               {
                    i=96;
               }
           }


   }                                                      // while
}

this code have the same method of displaying the wrong or mixed data on the LCD screen.....

have you got the warning of IRP bit setting on the compiler message window???

the problem is only with lcd display.. other functions are working fine. i have made a video of the display to show what is happening with the display...

https://www.youtube.com/watch?v=3mCuMsdS4bA&feature=youtu.be

you can see the missing or mixed data problem. e.g; it is not displaying Shenztech in first row of lcd and just displaying Pvt Ltd on screen.

and in the last when generator fails to start it displayed

warming up....
rload


instead of displaying

<ERROR>
fails to start...


i will write down step by step the function of buttons later on any may make a video to upload.
 
Last edited:

I have posted the source code. Compile it and check. In this file there is hex file. Check with it.
 

same effects of this hex file in my hardware as in my above given video. are you using the same code as you have posted above? what changes you did in the code.

secondly what crystal have you choosen in your Mikro C project settings? kindly choose 4MHz crystal.
 

Attachments

  • Quaiser Azeeme.rar
    18.2 KB · Views: 57
Last edited:

it still have the same problem... there is still IRP bit sitting problem. your shown video link also have the same problem as i have shown in my video. i also checked it in real pic simulator software and it is also showing the same problem as it is in my real hardware board. every thing is the same and need to solve.......
 

In my video it is showing Shentech Pvt Ltd. I only changed the code such that it displays the three messages. If you want me to code then you have to clearly explain me what the buttons do and when. explain all conditions, etc.,
 

Actually i want to learn so i want to code it by myself. i actually want help of experts in points where i got stuck in problems. now i want to get out of IRP bit setting problem but can't find the way to get out of it.

Actually all these buttons that i didn't code yet are used to enter the times for various generator functions; i.e; Generator warm up time. self on and self off time and chowk on and chowk off time and cooldown time.

enter button is used to enter these routines and scroll up and down buttons are use to scroll the options up and down on lcd screen to select the options we have to press the enter button again and the corresponding time is displayed in second row. now again scroll up and down buttons are used to increase and decrease the time, now here at this point enter button is again used to save the selected time. and then reset button is used to get out of routine................ reset button is also used to over all reset the display without entering these routines.

hope this explanation have cleared the use of buttons. please tell me if you still need further explanation of the function.
 

I need step by step explanation of the flow of the program. The values you increment or decrement using up and down buttons are stored somewhere. Are you storing those values in eeprom?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top