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.

source code for the external interrupt in lpc2148

Status
Not open for further replies.

Gopikrissh

Newbie level 5
Joined
Jan 25, 2012
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,340
hello,
I have written a code for my project for the external interrupt in such a manner that when i trigger a particular pin high/low externally the lcd display should change but it is not working.Can you please tell me where have i gone wrong?

my code is as follows:




Code:
#include "LPC214x.H" 	                                	// LPC2148 MPU Register
#include <stdio.h>											// For Used Function printf 
#include <lcd.h> //LCD INIT.,DATA & CMD
//#include "lcd_print.h" //WEL-COME SCREEN & MAIN MENU
//#include "baudrate.h" //FOR BAUDRATE SETTING
//#include "enroll.h" //ENROLL FUNCTION
//#include "diag.h" //DIAGNOSE FUNCTION
//#include "add_user.h"
//#include "identify.h"
//#include "deletealluser.h"
							

#define  LCD_RS     0x00010000   						// P1.16(0000 0000 0000 000x 0000 0000 0000 0000)
#define  LCD_EN     0x00020000   						// P1.17(0000 0000 0000 00x0 0000 0000 0000 0000)
#define  LCD_D4     0x00040000   						// P1.18(0000 0000 0000 0x00 0000 0000 0000 0000)
#define  LCD_D5     0x00080000   						// P1.19(0000 0000 0000 x000 0000 0000 0000 0000)
#define  LCD_D6     0x00100000   						// P1.20(0000 0000 000x 0000 0000 0000 0000 0000)
#define  LCD_D7     0x00200000   						// P1.21(0000 0000 00x0 0000 0000 0000 0000 0000)
#define	 ExtIntr    0x0000C000							//p0.7 as eint3
#define	 pin_0_7	0x00000080
	
#define  LCD_DATA   (LCD_D7|LCD_D6|LCD_D5|LCD_D4)
#define  LCD_IOALL  (LCD_D7|LCD_D6|LCD_D5|LCD_D4|LCD_RS|LCD_EN)

#define  lcd_rs_set() IOSET1 = LCD_RS	 				// RS = 1 (Select Instruction)
#define  lcd_rs_clr() IOCLR1 = LCD_RS					// RS = 0 (Select Data)
#define  lcd_en_set() IOSET1 = LCD_EN					// EN = 1 (Enable)
#define  lcd_en_clr() IOCLR1 = LCD_EN					// EN = 0 (Disable)

// xxxx xxx0 0000 0000 0000 0000 0000 0000
#define  lcd_dir_write()  IODIR1 |= 0x003F0000			// LCD Data Bus = Write
//#define  lcd_dir_read()   IODIR1 &= 0xFFC3FFFF			// LCD Data Bus = Read 




#define  lcd_clear()          lcd_write_control(0x01)	// Clear Display
#define  lcd_cursor_home()    lcd_write_control(0x02)	// Set Cursor = 0
#define  lcd_display_on()     lcd_write_control(0x0E)	// LCD Display Enable
#define  lcd_display_off()    lcd_write_control(0x08)	// LCD Display Disable
#define  lcd_cursor_blink()   lcd_write_control(0x0F)	// Set Cursor = Blink
#define  lcd_cursor_on()      lcd_write_control(0x0E)	// Enable LCD Cursor
#define  lcd_cursor_off()     lcd_write_control(0x0C)	// Disable LCD Cursor
#define  lcd_cursor_left()    lcd_write_control(0x10)	// Shift Left Cursor
#define  lcd_cursor_right()   lcd_write_control(0x14)	// Shift Right Cursor
#define  lcd_display_sleft()  lcd_write_control(0x18)	// Shift Left Display
#define  lcd_display_sright() lcd_write_control(0x1C)	// Shift Right Display

/* pototype  section */
void lcd_init(void);										// Initial LCD
void lcd_out_data4(unsigned char);						// Strobe 4-Bit Data to LCD
void lcd_write_byte(unsigned char);						// Write 1 Byte Data to LCD
void lcd_write_control(unsigned char); 					// Write Instruction
void lcd_write_ascii(unsigned char); 					// Write LCD Display(ASCII)
void goto_cursor(unsigned char);						// Set Position Cursor LCD
void lcd_print(unsigned char*);							// Print Display to LCD
//char busy_lcd(void);									// Read Busy LCD Status
void enable_lcd(void);	 								// Enable Pulse
void delay(unsigned long int);							// Delay Function



/* Main Program Start Here */
int main (void) 
{
  lcd_init();
  //IODIR1=~(1<<22);
  	
 while (1) 

	 /* Loop forever */

 {                         
   			//IOSET0=pin_0_7;
       	  	IO0DIR &=~IODIR0;
			IO0DIR &=~(1<<7);
			PINSEL0 &= ~PINSEL0;  // Clear bits
			PINSEL0 |= ExtIntr;  // Set to EINT2 (11)
		   if(IO0SET==pin_0_7)                           /* P1.22 if set high */
            {
       		 lcd_write_control(0x01);  							// Clear Display  (Clear Display,Set DD RAM Address=0) 
    		 goto_cursor(0x00);									// Set Cursor Line-1
		     lcd_print(" INTERRUPTED ");
			 delay(100000);
	        }
     		else
	        {  
				delay(100000);	
  			   lcd_write_control(0x01);  							// Clear Display  (Clear Display,Set DD RAM Address=0) 
    		   goto_cursor(0x00);									// Set Cursor Line-1
    		   lcd_print(" WELCOME");
			   delay (100000);						// Display LCD Line-1  
			    if ((IOPIN0 & pin_0_7) == 1)
  				{
    				lcd_write_control(0x01);  							// Clear Display  (Clear Display,Set DD RAM Address=0) 
    		 		goto_cursor(0x00);									// Set Cursor Line-1
					lcd_print("High");
  				}
  				else
  				{
    				lcd_write_control(0x01);  							// Clear Display  (Clear Display,Set DD RAM Address=0) 
    		 		goto_cursor(0x00);									// Set Cursor Line-1
					lcd_print("Low");
  				}
   	   		}
   
  }




 }


	


/****************************/
/* Strobe 4-Bit Data to LCD */
/****************************/
void lcd_out_data4(unsigned char val)
{
IOCLR1 = (LCD_DATA);	  								// Reset 4-Bit Pin Data
  IOSET1 = (val<<18); 									// EN,0,RW,RS:DDDD:0000:0000:0000:0000:0000:0000   
 
}

/****************************/
/* Write Data 1 Byte to LCD */
/****************************/
void lcd_write_byte(unsigned char val)
{  
      
  lcd_out_data4((val>>4)&0x0F);							// Strobe 4-Bit High-Nibble to LCD
 
  enable_lcd();											// Enable Pulse
  
  lcd_out_data4(val&0x0F);				  				// Strobe 4-Bit Low-Nibble to LCD
  enable_lcd();											// Enable Pulse  
  
  delay(100000);
  //while(busy_lcd());      								// Wait LCD Execute Complete  
}

/****************************/
/* Write Instruction to LCD */
/****************************/
void lcd_write_control(unsigned char val)
{ 

  lcd_rs_clr();											// RS = 0 = Instruction Select
  lcd_write_byte(val);									// Strobe Command Byte	    
}

/****************************/
/* Write Data(ASCII) to LCD */
/****************************/
void lcd_write_ascii(unsigned char c)
{  
  lcd_rs_set();											// RS = 1 = Data Select
  lcd_write_byte(c);		   							// Strobe 1 Byte to LCD    
}

/*******************************/
/* Initial 4-Bit LCD Interface */
/*******************************/
void lcd_init()
{
  unsigned int i;										// LCD Initial Delay Count 

  PINSEL2  = 0x00000000;								// GPIO1[31..26] = I/O Function
  lcd_dir_write();										// LCD Data Bus = Write
  for (i=0;i<1000;i++);								// Power-On Delay (15 mS)

  IOCLR1 = (LCD_IOALL);									// Reset (RS,RW,EN,4-Bit Data) Pin
  IOSET1 = (LCD_D5|LCD_D4);								// DDDD:EN,RW,RS,0:0000:0000:0000:0000:0000:0000 
  enable_lcd();											// Enable Pulse
  for (i=0;i<100;i++);								// Delay 4.1mS

  IOCLR1 = (LCD_IOALL);	  								// Reset (RS,RW,EN,4-Bit Data) Pin
  IOSET1 = (LCD_D5|LCD_D4);								// DDDD:EN,RW,RS,0:0000:0000:0000:0000:0000:0000 
  enable_lcd();											// Enable Pulse
  for (i=0;i<100;i++);									// delay 100uS

  IOCLR1 = (LCD_IOALL);	  								// Reset (RS,RW,EN,4-Bit Data) Pin
  IOSET1 = (LCD_D5|LCD_D4);								// DDDD:EN,RW,RS,0:0000:0000:0000:0000:0000:0000 
  enable_lcd();											// Enable Pulse
  delay(10000);
  //while(busy_lcd());      								// Wait LCD Execute Complete
 
  IOCLR1 = (LCD_IOALL);	  								// Reset (RS,RW,EN,4-Bit Data) Pin
  IOSET1 = (LCD_D5);									// DDDD:EN,RW,RS,0:0000:0000:0000:0000:0000:0000 
  enable_lcd();											// Enable Pulse
  delay(10000);
  //while(busy_lcd());      								// Wait LCD Execute Complete

      
  lcd_write_control(0x28);  							// Function Set (DL=0 4-Bit,N=1 2 Line,F=0 5X7)
  lcd_write_control(0x0C);  							// Display on/off Control (Entry Display,Cursor off,Cursor not Blink)
  lcd_write_control(0x06);  							// Entry Mode Set (I/D=1 Increment,S=0 Cursor Shift)
  lcd_write_control(0x01);  							// Clear Display  (Clear Display,Set DD RAM Address=0) 
  for (i=0;i<100000;i++);								// Wait Command Ready

}

/***************************/
/* Set LCD Position Cursor */
/***************************/
void goto_cursor(unsigned char i)
{
  i |= 0x80;											// Set DD-RAM Address Command
  lcd_write_control(i);  
}

/************************************/
/* Print Display Data(ASCII) to LCD */
/************************************/
void lcd_print(unsigned char* str)
{
  int i;

  
  for (i=0;i<16 && str[i]!=0;i++)  						// 16 Character Print
  {
     lcd_write_ascii(str[i]);							// Print Byte to LCD
  }
 
}

/******************/
/* Wait LCD Ready */
/******************/

/*char busy_lcd(void)
{
  unsigned long busy_status;							// Busy Status Read
  unsigned int i;										// Delay Count

  lcd_dir_read();										// LCD Data Bus = Read
  lcd_rs_clr();		 									// Instruction Select
  lcd_rw_set(); 										// Read Direction
  lcd_en_set();											// Start Read Busy

  for (i=0;i<1000;i++);	  								// Delay Before Read
  busy_status = (IOPIN1 & 0x80000000);					// Read LCD Data(DDDD:EN,RW,RS,0:0000:0000:0000:0000:0000:0000) 
  if(busy_status == 0x80000000)  						// Read & Check Busy Flag
  {
    lcd_en_clr();  										// Disable Read
	lcd_rw_clr();										// Default = Write Direction
	lcd_dir_write();									// LCD Data Bus = Write
    return 1;											// LCD Busy Status
  }
  else
  {
    lcd_en_clr();  										// Disable Read
	lcd_rw_clr();										// Default = Write Direction
	lcd_dir_write();									// LCD Data Bus = Write
    return 0;											// LCD Ready Status
  }
}
  */

/***********************/
/* Enable Pulse to LCD */
/***********************/
void enable_lcd(void)	 								// Enable Pulse
{
  unsigned int i;										// Delay Count

  
  lcd_en_set();  										// Enable ON
  for (i=0;i<400000;i++);
  lcd_en_clr();  										// Enable OFF 
}

/***********************/
/* Delay Time Function */
/*    1-4294967296     */
/***********************/
void delay(unsigned long int count1)
{
  while(count1 > 0) {count1--;}							// Loop Decrease Counter	
}
/*void //tx0(unsigned char ch) //TRANSMITTING STRING TO USART0
{
	char UDR0;
	int tx_flag0;
	UDR0=ch;
	tx_flag0=0;
	while(!tx_flag0);
		tx_flag0=0;
} */
 
Last edited by a moderator:

I think you did not read the manual for your MCU thoroughly.
if(IO0SET==pin_0_7) /* P1.22 if set high */
IO0SET is not the register that holds the state of mcu's io pins. It's usage is to output data on pints that are configured as output. It's the same as IOSET0. You need to use IP0PIN or IOPIN0 register here:
>> if(IO0PIN == pin_0_7)


if ((IOPIN0 & pin_0_7) == 1)
this condition will never be true in your case. Use "if(IOPIN0 & pin_0_7){/*....code here...*/}"

And by the way why have you not configured any interrupt vector slot for you EXT2 interrupt and there's no ISR as well.
 

I think you did not read the manual for your MCU thoroughly.

IO0SET is not the register that holds the state of mcu's io pins. It's usage is to output data on pints that are configured as output. It's the same as IOSET0. You need to use IP0PIN or IOPIN0 register here:
>> if(IO0PIN == pin_0_7)


this condition will never be true in your case. Use "if(IOPIN0 & pin_0_7){/*....code here...*/}"

And by the way why have you not configured any interrupt vector slot for you EXT2 interrupt and there's no ISR as well.


Thanks a lot salmanliaquat for your reply..I am new to the coding part ..can you suggest me few books/material to learn coding and also post a interupt program for me...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top