PWM use of the lpc1768

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.