p2.0 pwm1.1
void Als_init(void) //initialization
{
LPC_SC, Pconp |= (1<<1) | ( 1<<2) | (1<<); Turn on the clock
LPC_SC-PCLKSEL0 &= ~ (3<<2); Clock 25M
LPC_SC-PCLKSEL0 &= ~ (3<<4);
p2.0
Lpc_pincon-PINSEL4 &= ~ (0x03l<<0); GPIO
Lpc_pincon-PINMODE4 &= ~ (0x03l<<0); To enable pull-up
Lpc_pincon-pinmode_od2 &= ~ (0x01<<1); Push-Pull Normal mode
P2dir(0) = 1; Output
Lpc_tim1, TCR |= (1<<1); Reset Timer
LPC_TIM1-CTCR = 0x00; Timer mode
LPC_TIM1PC = 0x00;
LPC_TIM1-PR = 1; Prescaler, Count frequency 1m
LPC_TIM1-MR0 = ; 25*100 2500 Frequency 10K
LPC_TIM1-MR1 = +;
Lpc_tim1, MCR |= ( (1<<0) | ( 1<<3) | (1<<4)); MR0 when the TC value is matched will result in a reset resulting in an interrupt MR1 match when the interrupt disappears
LPC_TIM1-IR |= 0XFF; Clear all interrupt flag bits
Lpc_tim1, TCR = (1<<0); Start timer
Nvic_enableirq(timer1_irqn);
}
void Als_set_duty(u8 Duty) //Set duty ratio
{
Lpc_tim1, TCR = 0; Pause Timer
if (duty >= )Duty = ;
if (duty = = 0)Duty = 1;
LPC_TIM1-MR0 = duty;
Lpc_tim1, TCR = (1<<0); Start timer
}
void Als_stop(void)
{
Lpc_tim1, TCR = 0; Pause Timer
P2low(0) = 1; Constant level
}
void Timer1_irqhandler(void)
{
Nvic_clearpendingirq(timer1_irqn);
if ( lpc_tim1-IR &0x01) //mr0 Interrupt
{
P2low(0) = 1;
Lpc_tim1, IR |= (1<<0); Clear Interrupt Flag
}
Else if (lpc_tim1, IR &0x02)
{
P2high(0) = 1;
Lpc_tim1, IR |= (1<<1); Clear Interrupt Flag
}
}
PWM use of the lpc1768