//ADC using interrupts ARM 7 LPC2138#include <LPC213X.H>unsignedint result=0;//void t0_init_isr(unsigned int msec);void adc_isr_init(void);void adc_schedule()__attribute__((interrupt("FIQ")));void initLCD(void);void enable(void);void LCD_WriteChar(char c);void LCD_WriteString(char* string);void LCD_Cmd(unsignedint cmd);void delay(unsignedint msec){unsignedint i,j;for(i=0;i<1275;i++){for(j=0;j<msec;j++);}}//void t0_schedule()__attribute__((interrupt("FIQ")));//#define analog (1<<27) // AD0.0 pin on p0.27//#define switch (1<<0) //pin0.0 //#define s1 (IOPIN0 & switch)/*void t0_init_isr(unsigned int msec){ T0MCR = 0x03;//interrupt and reset on MR0 T0MR0 = 3000*msec; // T0IR = 0x01; //timer 0 MR0 interrut VICIntSelect |=(1<<4);//selecting timer 0 interrupt VICIntEnable |=(1<<4);//enalbling timer 0 interrupt T0TCR = 0x01; //reset timer control register}*/void adc_isr_init(void){
VICIntSelect|=(1<<18);//selecting AD0 from VICIntselect register
VICIntEnable|=(1<<18);//enabling AD0 from VICIntenable register
VICVectCntl1=0X20|18;//AD0 source to interrupt controller VIC
VICVectAddr1=(unsigned)adc_schedule;//passing irq address to VIC
PINSEL1|=(1<<22);// P0.27
AD0CR=0X00000001;//selecting AD0.0 on SEL pin from control register
AD0CR|=(1<<9);//setting CLKDIV in ADC control register
AD0CR|=(1<<21);//making AD0 operational //AD0STAT|=(1<<16);}void adc_schedule(){
AD0CR|=(1<<24);//to start conversionwhile(!(AD0GDR &(1<<31)));// waiting data conversion to get complete
result=((!(AD0GDR>>6)&&0X3FF));//getting data from bit 6:15 of AD0GDR
AD0INTEN|=(1<<0);//generating interrupt on completion of conversion on AD0.0 //LCD_WriteString("Completion");
VICVectAddr=0x000;//end of all ISRs}void conversion(){int val;unsignedint x,y,z;float stepsize;//stepsize
stepsize =0.0032;
val=result*stepsize*100;
x=(val%10);
y=(val%100)/10;
z=val/100;
LCD_WriteString("Voltage");
LCD_WriteString("=");
LCD_WriteChar(x+48);
LCD_WriteString(".");
LCD_WriteChar(y+48);
LCD_WriteChar(z+48);
LCD_WriteString("V");}void initLCD(void){
IODIR0 =0xFF;//P0.0 to P0.7 configured as Output - Using 8 Bit mode
IODIR1 =(1<<16)|(1<<17);//P1.16 and P1.17 configured as Output - Control Pins
IOPIN0 =0x0;//Reset Port0 to 0.
IOPIN1 =0x0;//Reset Port1 to 0 - Which also makes RS and Enable LOW.//LCD Initialization Sequence Now starts
delay(2);//Initial Delay
LCD_Cmd(0x38);//Function Set Command
delay(2);
LCD_Cmd(0x0F);//Display Switch Command : Display on , Cursor on , Blink on
delay(2);//LCD_Cmd(0x06); //Input Set : Increment Mode
LCD_Cmd(0x01);//Screen Clear Command , Cursor at Home//Not required the 1st time but needed to reposition the cursor at home after Clearing Screen //Done!}void enable(void){
delay(1);
IOPIN1 |=(1<<17);//Enable=High
delay(1);
IOPIN1 &= ~(1<<17);//Enable=Low
delay(1);}void LCD_WriteChar(char c){
IOPIN1 |=(1<<16);//Switch to Data Mode
IOPIN0 =(int) c;//Supply Character Code
enable();//Pulse Enable to process it}void LCD_WriteString(char* string){int c=0;while(string[c]!='\0'){
LCD_WriteChar(string[c]);
c++;}}void LCD_Cmd(unsignedint cmd){
IOPIN1 =0x0;//Enter Instruction Mode
IOPIN0 = cmd;//Supply Instruction/Command Code
enable();//Pulse Enable to process it}void sleep_mode(){
PCON=0X01;}int main(){
initLCD();
adc_isr_init();
conversion();while(1){
sleep_mode();}}
I have used ADC interrupts in LPC2138 where after conversion is getting complete an interrupt is generated so when the analog input a pot of 100k to the AD0.0 (PIN 0.27)connected shows different values on LCD but instead of it LCD shows some junk value.Is it the problem of ISR in the code?