doc update ESD

This commit is contained in:
sherlock 2025-10-23 11:44:39 +05:30
parent 365f8df7c0
commit 0290f584b3

58
ES/Lab/Lab11/PWM.c Normal file
View file

@ -0,0 +1,58 @@
#include "LPC17xx.h"
unsigned long int duty_cycle = 0;
int direction = 1;
int step = 50;
void PWM1_IRQHandler(void)
{
if (LPC_PWM1->IR & (1 << 0))
{
if (direction == 1)
{
duty_cycle += step;
if (duty_cycle >= 3000)
{
duty_cycle = 3000;
direction = 0;
}
}
else
{
duty_cycle -= step;
if (duty_cycle <= 0)
{
duty_cycle = 0;
direction = 1;
}
}
LPC_PWM1->MR4 = duty_cycle;
LPC_PWM1->LER = (1 << 4);
LPC_PWM1->IR = (1 << 0);
}
}
int main(void)
{
LPC_PINCON->PINSEL3 |= (2 << 14);
LPC_PWM1->TCR = (1 << 1);
LPC_PWM1->CTCR = 0;
LPC_PWM1->PR = 0;
LPC_PWM1->MR0 = 3000;
LPC_PWM1->MR4 = duty_cycle;
LPC_PWM1->MCR = (1 << 1) | (1 << 0);
LPC_PWM1->PCR = (1 << 12);
LPC_PWM1->LER = (1 << 0) | (1 << 4);
NVIC_EnableIRQ(PWM1_IRQn);
LPC_PWM1->TCR = (1 << 0) | (1 << 3);
while (1)
;
}