Arm lpc2294 basic problems related to interrupt calling

Status
Not open for further replies.

girish09

Junior Member level 2
Joined
Jul 21, 2012
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Pune
Visit site
Activity points
1,450
I am using ARM LPC 2294, i have interfaced LCD and keypad for keypad interfacing i have used interrupt method (because my schematic is like that so i have to write code like that only)....my LCD is working properly but my program is not going into interrupt function, as i have checked this using Debugging the code, what am i supposed to do, Please help me i am beginner in ARM programming, my hardware is ok......waiting for your kind help
my code is as follows



Code:
//#include "stdio.h"
#include "lpc210x_gnuarm.h"
#include "delay.h"
#include "INTERRUPT.C"
#include "string.h"
#include "lpc22xx.h"


void wait_us (unsigned long);
void GPIO_Port_Low(unsigned int);
void GPIO_Port_High(unsigned int);
void GPIO_Set_Port(unsigned int , unsigned int);
void disp_cmd(unsigned char);
void disp_write(unsigned char);
void lcd_init(void);

#define DISP_FUNC 0x28 		 // sets the display to 4-bit, 2 lines, 5x7 chars + cursor-off 
#define DISP_ENTRY 0x06
#define DISP_CNTL 0x08
#define DISP_ON 0x04
#define DISP_CURSOR 0x02
#define DISP_CLEAR 0x01
#define DISP_HOME 0x02
#define DISP_POS 0x80
#define DISP_BLINK 0x01

#define DISPDATA_MASK 0x000000F0 	 // four(!) bit data bus to the display panel connected to GPIO[12..15]
//#define DISPDATA_MASK 0x00000F00
//#define ENABLE_MASK 1<<4	 // enable connected to GPIO[4]
//#define REGSEL_MASK 1<<5	 // REGSEL connected to GPIO[5]
#define ENABLE_MASK 1<<9	 //toggal BIT for testing BY SP		
#define REGSEL_MASK 1<8	 //toggal BIT for testing BY SP	
#define LCD_CS      1<<11	 //toggal BIT for testing BY SP	

//#include "uart0.h"
#define KEY_2		0x0B
#define KEY_F1		0x04
#define KEY_0		0x08	
#define KEY_F2		0x0C
#define KEY_7		0x05
#define KEY_8		0x09
#define KEY_9		0x0D
#define KEY_4		0x06
#define KEY_5		0x0A
#define KEY_6		0x0E
#define KEY_MENU	0x13
#define KEY_UP		0x12
#define KEY_DOWN	0x11
#define KEY_ENTER	0x10
#define KEY_1		0x07
#define KEY_3		0x0F
#define KEY_ESC		0x03
#define KEY_START	0x02
#define KEY_STOP	0x01
#define KEY_F3		0x00
//#include<LPC22XX.h>
//#include<stdio.h>



//#include "stdio.h"

//
unsigned char i=0,keycode,temp2;  							//Variable Declarations

//Function Prototype
void scancode(long,long);
void initSerial(void);
void initInterrupt(void);
void key_detect(void);

void gpioInit(void)
{	
PCB_PINSEL0  = 0x00000000;
IODIR1 = (1<<25);			 //KEY_READ
IOCLR1 = 0xFFFFFFFF;		
IODIR2 = 0x000000E0; 		//changed for debugging		
IOCLR2 = 0xFFFFFFFF;
}

void initSerial(void)
{
PCB_PINSEL0=0x00050000;
UART1_LCR=0x83;
UART1_DLL=0x86;
UART1_DLM=0x01;
UART1_LCR=0x3;
}

void initInterrupt()
{
//IOSET2 = 0xffffffff;
PCB_PINSEL1 = PCB_PINSEL1 | 0x00000001; ///////////EINT0 = Pin P0.16////////
EXTMODE = 0x00000000;
EXTPOLAR = 0x00000000;
//VICVectAddr0 = (unsigned long) external ;
VICVectAddr0 = (unsigned)EXTINTVectoredIRQ;
VICVectCntl0 = 0x0000002E ;
VICIntEnable = VICIntEnable | 0x00004000;
}

void display(char arr[])
{

 int i=0;
 disp_cmd(0x80);
 wait_us(500);
 disp_cmd(0x02);
 for(i=0;arr[i]!='\0';i++)
  {
   if(arr[i])
   	{
   		disp_write(arr[i]);
   		 wait_us(500);
   	}
 else
   return;
  }
  }	
/*
disp_cmd(0xd0);
 wait_us(500);
disp_cmd(0x02);	 
 for(i=16;i<32;i++)
{
   if(arr[i])
   {
   	disp_write(arr[i]);
	 wait_us(500);
   }
 else
   return;
} */	






void key_detect()
{

//keycode=0xf8;
wait_us(100);			      //wait 20msec debounce time
  
		switch (keycode)
		{
//* ************************** (ONE) 1 KEY ************************ *
			case KEY_0  	 :display("*****KEY 0 PRESSED*****\n");
			            	 break;
			case KEY_1 		 :display("*****KEY 1 PRESSED*****\n");
			           		 break;
			case KEY_2 		:display("*****KEY 2  PRESSED*****\n");
			           		 break;
			case KEY_3 		:display("*****KEY 3 PRESSED*****\n");
			           		 break;
			case KEY_4 		:display("*****KEY 4 PRESSED*****\n");
			           		 break;
			case KEY_5 		:display("*****KEY 5 PRESSED*****\n");
			           		 break;
			case KEY_6 		:display("*****KEY 6 PRESSED*****\n");
			           		 break;
			case KEY_7 		:display("*****KEY 7 PRESSED*****\n");
			           		 break;
			case KEY_8 		:display("*****KEY 8 PRESSED*****\n");
			           		 break;
			case KEY_9 		:display("*****KEY 9 PRESSED*****\n");
			            	 break;
			case KEY_F1 	:display("*****KEY F1 PRESSED*****\n");
			            	 break;
			case KEY_F2 	:display("*****KEY F2 PRESSED*****\n");
			                 break;
			case KEY_F3     :display("*****KEY F3 PRESSED*****\n");
			                 break;
			case KEY_MENU   :display("*****KEY MENU PRESSED*****\n");
			                 break;
			case KEY_UP      :display("*****KEY UP PRESSED*****\n");
			                 break;
			case KEY_DOWN      :display("*****KEY DOWN PRESSED*****\n");
			                 break;
			case KEY_ENTER      :display("*****KEY ENTER PRESSED*****\n");
			                 break;
			case KEY_ESC      :display("*****KEY ESC PRESSED*****\n");
			                 break;
			case KEY_START      :display("*****KEY START PRESSED*****\n");
			                 break;
			case KEY_STOP      :display("*****KEY STOP PRESSED*****\n");
			                break;
						 
			}
}

/*###################################################*/

// LCD code 
//  LCD code



void wait_us (unsigned long usdelay ) 
{
usdelay = usdelay*10;
while(--usdelay);
}

void GPIO_Port_Low(unsigned int value)
{
  
   IOCLR2 = value; // clear zeros'
   wait_us(500); // slow down timing for LCD compatibility   
  
}

void GPIO_Port_High(unsigned int value){
   IOSET2 = value; // set ones'
   wait_us(500); // slow down timing for LCD compatibility
     
}

void GPIO_Set_Port(unsigned int mask, unsigned int value)
{
   IOCLR2 = LCD_CS;	
   IOSET2 = mask & value; // set ones'
   IOCLR2 = mask & (~value); // clear zeros'
   wait_us(500); // slow down timing for LCD compatibility
   IOSET2 = LCD_CS;
}


void disp_cmd(unsigned char cmd)
{
   IODIR2 = (IODIR2 | DISPDATA_MASK | REGSEL_MASK |  ENABLE_MASK | LCD_CS);     // set ports to outputs
   GPIO_Set_Port(DISPDATA_MASK, cmd & 0XF0); 	// latch the command
   GPIO_Port_Low(REGSEL_MASK); 				// select the command reg = 0
   wait_us(500);
   GPIO_Port_High(ENABLE_MASK); 			// latch the command into the LCD panel = 1 - first nibble
   wait_us(500);
   GPIO_Port_Low(ENABLE_MASK); 				// ENABLE=0;
  wait_us(500);
   GPIO_Set_Port(DISPDATA_MASK, cmd << 4); 	// latch the command
  wait_us(500);
   GPIO_Port_High(ENABLE_MASK); 			// latch the command into the LCD panel = 1 - second nibble
   wait_us(500);
   GPIO_Port_Low(ENABLE_MASK); 				// ENABLE=0;
}

void disp_write(unsigned char value) 
{
  IODIR2 = IODIR2 | DISPDATA_MASK | REGSEL_MASK  | ENABLE_MASK | LCD_CS;     // select write mode RDWR=0

   GPIO_Set_Port(DISPDATA_MASK, value & 0XF0); 	// latch the data upper nibble
   GPIO_Port_High(REGSEL_MASK); 	// select the command reg = 1 select data reg
   wait_us(500);
   GPIO_Port_High(ENABLE_MASK); // latch the command into the LCD panel = 1
  wait_us(500);
   GPIO_Port_Low(ENABLE_MASK); // ENABLE=0;
   wait_us(500);
   GPIO_Set_Port(DISPDATA_MASK, value << 4); // latch the data lower nibble
   wait_us(500);
   GPIO_Port_High(ENABLE_MASK); // latch the command into the LCD panel = 1
   wait_us(500);
   GPIO_Port_Low(ENABLE_MASK); // ENABLE=0;
}
 


void lcd_init(void) 
{
   unsigned char counter;

   IODIR2 =  IODIR2 | DISPDATA_MASK | REGSEL_MASK |ENABLE_MASK | LCD_CS;   // select port direction=output

	for (counter = 0; counter <3; counter++)
   {
      GPIO_Set_Port(DISPDATA_MASK, (0x20)); 	// latch the command 0x30
      GPIO_Port_Low(REGSEL_MASK); // select the command reg REGSEL=0
      wait_us(500);
  	  GPIO_Port_High(ENABLE_MASK); // latch the command into the LCD panel = 1
      wait_us(500);
      GPIO_Port_Low(ENABLE_MASK);  // latch the command into the LCD panel ENABLE=0
      wait_us(500);	// wait for LCD
   }
   wait_us(500);	// wait for LCD to reset itself
		disp_cmd(0x28); 
    wait_us(500);
		disp_cmd(0x0C); 
    wait_us(500);
		disp_cmd(0x01); 
    wait_us(500);
		disp_cmd(0x06); 
    wait_us(500);
		disp_cmd(0x02); 
    wait_us(500);
		disp_cmd(0x10); 
    wait_us(500);
 /*  for (counter = 0; counter <3; counter++)
   {
      GPIO_Set_Port(DISPDATA_MASK, (0x0020)); 	// latch the command 0x30
      GPIO_Port_Low(REGSEL_MASK); // select the command reg REGSEL=0
       wait_us(0XFF);
  	  GPIO_Port_High(ENABLE_MASK); // latch the command into the LCD panel = 1
       wait_us(0XFF);
      GPIO_Port_Low(ENABLE_MASK);  // latch the command into the LCD panel ENABLE=0
      wait_us(0XFF);	// wait for LCD
   }	

	//**********************ENTRY  ENTRY   ENTRY  ****************************

   wait_us(0XFF);	// wait for LCD
   disp_cmd(DISP_FUNC); // set the display for an 8
   // bit bus, 2 display lines,
   // and a 5x7 dot font
    wait_us(0XFF);	// wait for LCD
   disp_cmd(DISP_CNTL | DISP_ON ); // turn the display on, cursor off
    wait_us(0XFF);	// wait for LCD
   //*********************Added Function **************************************
   disp_cmd(0x14); 
    wait_us(0XFF);
   disp_cmd(DISP_CLEAR); // clear the display
    wait_us(0XFF);	// wait for LCD
   disp_cmd(DISP_ENTRY);	// set the character entry
						   	// mode to increment display
   							// address for each
   							// character, but not to scroll
	 wait_us(0XFF);	
  */ 	
 }
  


 void main(void)
{
//unsigned char message[] = "SUMIT EMBIN TECHNOLOGIES";
//unsigned char message[] = "TECHNOLOGY 12345";
unsigned char message[] = "ARM 32BIT BOARD Lcd 16x2 done"; 
//unsigned char m = 0x41;
//gpioInit();
//initSerial();
lcd_init();
gpioInit();										//Initialize the GPIo Pins
initSerial();									//initlaize the serial port
initInterrupt();
display(message);
//display("Hello World");
while(1)
	{
 		 
	}
}


and interrupt function is as follows



Code:
extern unsigned char keycode;  							//Variable Declarations	
extern void key_detect(void);		 
//void external(void) __irq // External Interrupt subroutine 
void EXTINTVectoredIRQ (void)  __irq
{
IOCLR1 = (1<<25);
//IOCLR2 = 0xFFFFFFFF;
 
keycode = IOPIN2;
//printf("%s",IOPIN2);					//take data
keycode = keycode & 0x1F;     // mask MSB 4 bit of port0
wait_us(200);			      //wait 20ms debounce time
IOSET1 = (1<<25);
EXTINT = 0x00000001;
VICVectAddr = 0x00000000;
key_detect();
//printf("%s",keycode);
}
 
Last edited by a moderator:

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…