Ravindrakant Jha
Junior Member level 2
- Joined
- Nov 2, 2014
- Messages
- 24
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 3
- Location
- India
- Activity points
- 274
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 //ADC using interrupts ARM 7 LPC2138 #include <LPC213X.H> unsigned int 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(unsigned int cmd); void delay(unsigned int msec) { unsigned int 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 conversion while(!(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; unsigned int 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(unsigned int 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?
Last edited by a moderator: