I'm working on a system, where I have: 3 switches, 2 led's, and a motor (set PWM single edge)Note: the motor is replaced with 2 LEDs on PWM1 and PWM3(configured on P0.0 and P0.1). When the switch on P0.6 is pressed PWM1 is activated and after a finite delay PWM1 switches off and PWM3 switches on, and keeps repeating. the other 2 switches are set with external interrupts on P0.14 and P0.15 and the 2 leds on P0.12 and P0.13, when any of these 2 switches is activated the PWM1 and PWM3 are turned OFF. while if P0.14 switch is LOW the led on P0.12 binkis at a rate of 200ms and when the switch on P0.15 is activated LOW the LED on P0.13 blinks at a rate of 100ms.
this is my code, when compiled on ARM7 LPC2119 the leds on pins P0.0 and P0.1 will be ON. any advice pls?
#include <LPC21xx.h> //global variables unsigned int SW; __irq void T0_isr (void); void EXTINTVectoredIRQ (void) __irq; void one_sec (void); void led_100ms (void); void led_200ms (void); int main () { PLLCFG = 0x00000022; PLLCON = 0x00000001; PLLFEED = 0x000000AA; // Update PLL registers with feed sequance PLLFEED = 0x00000055; while(! (PLLSTAT & 0x00000400)); // Test Lock bit PLLCON = 0x00000003; // Connect the PLL PLLFEED = 0x000000AA; // Update PLL registers PLLFEED = 0x00000055; VPBDIV = 0x00000002; // Set the VLSi peripheral bus to 30 Mhx PINSEL0 = 0xFF00300F; // port p0.1 and p0.0 is set for PWM // Enable the interrupts // set ports for maths registor MR0 and MR1 PINSEL1 = 0; //set as GPIO PINSEL2 = 0; //set as GPIO IO0DIR = 0XFFFF3FBF; //p0.6, p0.14 and p0.15 inputs //PWM initialization PWMTCR = 2; //Reset counter, disable PWM peripheral PWMPR = 3; //PWMTC runs @ 7.5MHz PWMMR0 = 9000; PWMMR1 = 50; PWMMR3 = 100; PWMMCR = 2; // PWMTC will reset on match with PWMMRO PWMPCR = 0x0A00; // enable PWM1 and PWM3 PWMLER = 0x0B; //writing ones to corresponding bits so that the values loaded //on the match regsters will become effective PWMTCR = 9; // enable PWM peripheral and start counters //external interrupts VICVectCntl0 = 0x0000002F;//select priority slot for given interrupt VICVectAddr0 = 0x0000002F & (unsigned)EXTINTVectoredIRQ; VICIntEnable = 0x00008000;//enable interrupt VICVectCntl4 = 0x0000002E; VICVectAddr4 = 0x0000002E &(unsigned)T0_isr; VICIntEnable = 0x00008000;//enable interrupt while(1) { SW = IO0PIN & 0x0000C040;//reading all switches at the same time P0.6, //P0.14 & P0.15 if (SW==0x00000040) //when p0.6 { IO0SET = 0x00000001;//P0.0 on one_sec(); IO0CLR = 0x00000001;//P0.0 off IO0SET = 0x00000002;//P0.1 on one_sec(); IO0CLR = 0x00000002;//P0.1 off } if(SW == 0x00008000) //if P0.15 is LOW { led_100ms(); } if (SW == 0x00004000) //if P0.14 is LOW { led_200ms(); } } } void EXTINTVectoredIRQ (void) __irq { IO0SET = 0x00003000; EXTINT = 0x00000001;//clear peripheral interrupts flag VICVectAddr = 0x00000000;//write to signal ed of interrupt } void T0_isr (void) __irq //ISR have to be written before the main function { while(1) { T0IR = 0x00000001; //writing 1 on match 0 interrupt flag will reset it VICVectAddr = 0x00000000; //end of interrupt - dummy write } } void led_200ms (void) { IO0CLR = 0x00002003;// LED OFF IO0SET = 0x00001000; // LED ON P0.12 //timer T1TCR = 0x00000020; T1IR = 0x00000000; T1CTCR = 0x00000000;// timer mode T1TC = 0x00000000; T1PR = 0; T1PC = 0x00000000; T1MCR = 0x00000130; T1EMR = 0xFFFF0000; T1MR0 = 6000000;/////200ms T1MR1 = 6000000; T1TCR = 0x00000010; IO0CLR = 0x00001000;// LED OFF } void led_100ms (void) { IO0CLR = 0x00001003;// LED OFF IO0SET = 0x00002000; // LED ON P0.13 //timer T1TCR = 0x00000002; T1IR = 0x00000000; T1CTCR = 0x00000000; T1TC = 0x00000000; T1PR = 0; T1PC = 0x00000000; T1MCR = 0x00000013; T1EMR = 0xFFFF0000; T1MR0 = 3000000;/////100ms T1MR1 = 3000000; T1TCR = 0x00000001; IO0CLR = 0x00002000;// LED OFF } void one_sec (void) //Local { unsigned short w; unsigned short a; unsigned short b; for(a=0; a<=10; a++)//for 10sec { for(w=0; w<20010; w++)// 1sec x 10 { for(b=0; b<5902; b++)// 1ms { //do nothing } } } }