Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

I need help in using external interrupt0 on pic18f4550 and LCD

Status
Not open for further replies.

TOCHI

New Member
Please, somebody should help me on how to display data as a result of processing ISR on the lcd of this picf4550. My interrupts handling seems to respond without lcd but fails whenver the LCD initialization codes and commands are added. The code was written using MikroC for PIC. Please help me....the code is shown below:
C:
/*
* Project name:
     Lcd_Test (Simple demonstration of the LCD Library functions)
* Copyright:
    .
* Description:
     This is a simple demonstration of LCD library functions and interrupts handling. LCD is first
     initialized, then some text is written at the first row.
* Test configuration:
     MCU:             P18F4550
  
     Oscillator:      HS, 08.0000 MHz
     Ext. Modules:    LCD 2x16

* NOTES:
     None.
*/

char *text = "ASPIRE DIG. TECH.";
char *text2 = "Interupted";
int  num=0;

void main() {

    TRISD=0;                      // Configure PortD as output port
    INTCON=0x10;                  // Enable INT0
    INTCON2=0;                    // Set Falling Edge Trigger for INT0
    TRISC=0;
    INTCON.GIE=1;    // Enable The Global Interrupt

      //interrupts  settings

      //portD=0;


      while(1)
    {



  //ADCON1 = 0x0F;            // Set AN pins to Digital I/O
  Lcd_Init(&PORTD);         // Lcd_Init_EP4, see Autocomplete

  LCD_Cmd(LCD_CLEAR);       // Clear display
  LCD_Cmd(LCD_CURSOR_OFF);  // Turn cursor off
  LCD_Out(1,1, text);       // Print text to LCD, 1st row, 1st column
  Delay_ms(1000);
  LCD_Out(2,6,"");    // Print text to LCD, 2nd row, 6th column

   
     if (num>=1) {
  Delay_ms(1000);
  LCD_Cmd(LCD_CLEAR);       // Clear display
  LCD_Cmd(LCD_CURSOR_OFF);
  LCD_Out(2,6, "interrupted");
   Delay_ms(2000);
                 }
  else {

  LCD_Cmd(LCD_CLEAR);       // Clear display
  LCD_Cmd(LCD_CURSOR_OFF);
  LCD_Out(2,6,"Waiting");
   Delay_ms(2000);


      }

    }
          //Program to depict the working of External Interrupt0 of PIC18F4550
  }

void interrupt_low(int num)              // Interrupt ISR
{
    INTCON.INT0IF=0;          // Clear the interrupt 0 flag
   LATC=~LATC;               // Invert (Toggle) the value at PortD
 
    num=num+1;
}
// the circuit is also added below
 
I ve done that, still it doesnt work....My new code is this:

/*
* Project name:
Lcd_Test (Simple demonstration of the LCD Library functions)
* Description:
This is a simple demonstration of LCD library functions and external interrupts. LCD is first
initialized, then some text is written at the first row.
* Test configuration:
MCU: P18F4550
Oscillator: HS, 08.0000 MHz
Ext. Modules: LCD 2x16
SW: mikroC v8.0.0.0
* NOTES:
None.
*/

char *text = "ASPIRE DIG. TECH.";
char *text2 = "Interupted";
int num=0;

void main() {

TRISD=0; // Configure PortD as output port
INTCON=0x10; // Enable INT0
INTCON2=0; // Set Falling Edge Trigger for INT0
TRISC=0;
INTCON.GIE=1; // Enable The Global Interrupt

//interrupts settings

//portD=0;
Lcd_Init(&PORTD); // Lcd_Init_EP4, see Autocomplete

while(1)
{



//ADCON1 = 0x0F; // Set AN pins to Digital I/O

LCD_Cmd(LCD_CLEAR); // Clear display
LCD_Cmd(LCD_CURSOR_OFF); // Turn cursor off
LCD_Out(1,1, text); // Print text to LCD, 1st row, 1st column
Delay_ms(1000);
LCD_Out(2,6,""); // Print text to LCD, 2nd row, 6th column

//PORTD=PORTD++;
if (num>=1) {
Delay_ms(1000);
LCD_Cmd(LCD_CLEAR); // Clear display
LCD_Cmd(LCD_CURSOR_OFF);
LCD_Out(2,6, text2);
Delay_ms(2000);
}
else {

LCD_Cmd(LCD_CLEAR); // Clear display
LCD_Cmd(LCD_CURSOR_OFF);
LCD_Out(2,6,"Waiting");
Delay_ms(2000);


}

}
//Program to depict the working of External Interrupt0 of PIC18F4550
}

void interrupt_low(int num) // Interrupt ISR
{
INTCON.INT0IF=0; // Clear the interrupt 0 flag
LATC=~LATC; // Invert (Toggle) the value at PortD

num=num+1;
}
//
 
Why is ADCON = 0xF; commented out??? You also need to tell the compiler where the RS, RW and E definitions???

You need to read the mikroC documentation ( Unless you are using the default connections, I doubt it as the default is 4 bit )
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top