PWM ESD, and ADC
This commit is contained in:
parent
ccff363c5a
commit
d1cd6b537c
3 changed files with 109 additions and 112 deletions
57
ES/Lab/Lab11/PWM_Keyboard.c
Normal file
57
ES/Lab/Lab11/PWM_Keyboard.c
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
#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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue