This commit is contained in:
sherlock 2025-10-23 13:06:11 +05:30
parent 5ba5925433
commit 200a988cfb

View file

@ -1,7 +1,9 @@
#include "LPC17xx.h" #include "LPC17xx.h"
volatile unsigned long int duty_cycle = 300; volatile unsigned long int duty_cycle = 300;
unsigned int last_key = 0xFF; volatile unsigned long int pwm_counter = 0;
#define LED_MASK (0xFF << 4)
#define COL0 (1<<0) #define COL0 (1<<0)
#define COL1 (1<<1) #define COL1 (1<<1)
@ -40,8 +42,15 @@ void PWM1_IRQHandler(void)
{ {
if (LPC_PWM1->IR & (1 << 0)) if (LPC_PWM1->IR & (1 << 0))
{ {
LPC_PWM1->MR4 = duty_cycle; if(pwm_counter < duty_cycle)
LPC_PWM1->LER = (1 << 4); LPC_GPIO0->FIOSET = LED_MASK;
else
LPC_GPIO0->FIOCLR = LED_MASK;
pwm_counter++;
if(pwm_counter >= 3000)
pwm_counter = 0;
LPC_PWM1->IR = (1 << 0); LPC_PWM1->IR = (1 << 0);
} }
} }
@ -50,16 +59,18 @@ int main(void)
{ {
unsigned int col_idx; unsigned int col_idx;
unsigned int read_key; unsigned int read_key;
unsigned int last_key = 0xFF;
LPC_PINCON->PINSEL0 &= ~(0xFFFF << 8); LPC_PINCON->PINSEL0 &= ~(0xFFFF << 8);
LPC_PINCON->PINSEL1 &= ~(0xFFFF << 14); LPC_PINCON->PINSEL1 &= ~(0xFFFF << 14);
LPC_PINCON->PINSEL4 &= ~(0xF << 0); LPC_PINCON->PINSEL4 &= ~(0xF << 0);
LPC_PINCON->PINSEL3 |= (2 << 14);
LPC_GPIO0->FIODIR |= LED_MASK;
LPC_GPIO0->FIODIR |= COL_MASK_P0; LPC_GPIO0->FIODIR |= COL_MASK_P0;
LPC_GPIO2->FIODIR |= COL_MASK_P2; LPC_GPIO2->FIODIR |= COL_MASK_P2;
LPC_GPIO0->FIODIR &= ~ROW0; LPC_GPIO0->FIODIR &= ~ROW0;
LPC_GPIO0->FIOCLR = LED_MASK;
LPC_GPIO2->FIOSET = COL_MASK_P2; LPC_GPIO2->FIOSET = COL_MASK_P2;
LPC_GPIO0->FIOSET = COL_MASK_P0; LPC_GPIO0->FIOSET = COL_MASK_P0;
@ -68,14 +79,11 @@ int main(void)
LPC_PWM1->PR = 0; LPC_PWM1->PR = 0;
LPC_PWM1->MR0 = 3000; LPC_PWM1->MR0 = 3000;
LPC_PWM1->MR4 = duty_cycle;
LPC_PWM1->MCR = (1 << 1) | (1 << 0); LPC_PWM1->MCR = (1 << 1) | (1 << 0);
LPC_PWM1->PCR = (1 << 12); LPC_PWM1->LER = (1 << 0);
LPC_PWM1->LER = (1 << 0) | (1 << 4);
NVIC_EnableIRQ(PWM1_IRQn); NVIC_EnableIRQ(PWM1_IRQn);
NVIC_SetPriority(PWM1_IRQn, 0);
LPC_PWM1->TCR = (1 << 0) | (1 << 3); LPC_PWM1->TCR = (1 << 0) | (1 << 3);