We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
device:LPC2103 Keil MDK 3.11 I want to control the sample speed with MAT0.3 in simulator,but I can't reach the interrupt subroutine and the ADC do not work at all! Thanks everyone read the message!
the following is my code:
******************************************************* #include <lpc2103.h>
void InitADC(void); __irq void irq_adc (void) ;
void InitTimmer(void); __irq void irq_t0 (void) ;
int main(void) {
InitADC(); InitTimmer(); while(1); return(0) ; }
// T0.3 void InitADC(void) { // SEL CKDIV PDN START
int x=0x000000ff | 100<<8 | 1<<21 |5<<24 ;
ADCR = x;
ADINTEN=0X1FF;
PINSEL0 |= 3<<20 | 3<<22 | 3<<24;
PINSEL1 |=3<<12 | 3<<14 | 3<<16 | 3<<18 | 3<<20 ;
VICVectAddr1=(long)irq_adc ;
VICVectCntl1 |= 0x20 | 18; VICIntEnable |= 1<<18;
}
void InitTimmer(void) { T0MCR = 3<<9;//On match reset the counter and generate an interrupt
T0MR3 = 1500; //Set the cycle time
T0TCR = 0x00000001;//enable timer
VICVectAddr0=(long)irq_t0 ;
VICVectCntl0 = 0x20 |4; VICIntEnable|= 1<<4;
__irq void irq_adc (void) { int adc_channal;
adc_channal=ADSTAT & 0x00ff;
switch(adc_channal)
{ case 1:break; case 2 :break; case 4 :break; case 8 :break; case 0x10 :break; case 0x20 :break; case 0x40:break; case 0x80:break; } }
__irq void irq_t0 (void) { T0IR = 1; // Clear interrupt flag
VICVectAddr = 0; // Acknowledge Interrupt
switch(T0IR) { case 1:break; case 2 :break; case 4 :break; case 8 :break; case 0x10 :break; case 0x20 :break; case 0x40:break; case 0x80:break; }
Is that how you actually write your code?
Do you find it clear and easy to read?
Most people find it helps to use indentation and whitespace to lay-out their code for easier reading; eg,
int main(void) { InitADC(); // initiate ADC InitTimmer(); // initiate timmer while(1); return(0) ; }
and:
void InitADC(void)// Initate the ADC { ADCR = 0x1 | 100<<8 | 1<<21 | 5<<24 ; ADINTEN = 0x101; // enable interrupt of ADC PINSEL0 |= 3<<20 | 3<<22 | 3<<24; // connect the pin PINSEL1 |= 3<<12 | 3<<14 | 3<<16 | 3<<18 | 3<<20 ; VICVectAddr1 = (long)irq_adc ;// set the interrupt adress VICVectCntl1 |= 0x20 | 18; // set the timmer0 interrupt VICIntEnable |= 1<<18; // enable timmer0 interrupt }