May 11, 2023 Brute Force Techniques I
This is a description #include <LPC17xx.H>
#define SHADOW_COPY 0x000000FF
void PWM_Init(void);
void PWM1_IRQHandler(void);
unsigned long int i;
unsigned char flag;
int main(void)
{
PWM_Init();
while (1)
;
}
void PWM_Init(void)
{
LPC_SC->PCONP = (1 << 6); // PWM1 is powered
LPC_PINCON->PINSEL7 = 0x000C0000; // PWM1.2 is selected for the pin P3.25
LPC_PWM1->PR = 0x00000000; // Count frequency : Fpclk
LPC_PWM1->PCR = 0x00000400; // select PWM2 single edge
LPC_PWM1->MCR = 0x00000003; // Reset and interrupt on PWMMR0
LPC_PWM1->MR0 = 30000; // setup match register 0 count
LPC_PWM1->MR2 = 0x00000100; // setup match register MR1
LPC_PWM1->LER = SHADOW_COPY; // enable shadow copy register
LPC_PWM1->TCR = 0x00000002; // RESET COUNTER AND PRESCALER
LPC_PWM1->TCR = 0x00000009; // enable PWM and counter
NVIC_EnableIRQ(PWM1_IRQn);
}
void PWM1_IRQHandler(void)
{
LPC_PWM1->IR = 0xFF; // clear the interrupts
if (flag == 0x00)
{
LPC_PWM1->MR2 += 100;
LPC_PWM1->LER = SHADOW_COPY;
if (LPC_PWM1->MR2 >= 27000) // Is Duty Cycle 90% ??
{
flag = 0xFF;
LPC_PWM1->LER = SHADOW_COPY;
}
}
else if (flag == 0xFF)
{
LPC_PWM1->MR2 -= 100;
LPC_PWM1->LER = SHADOW_COPY;
if (LPC_PWM1->MR2 <= 0x300) // Is Duty Cycle 1% ??
{
flag = 0x00;
LPC_PWM1->LER = SHADOW_COPY;
}
}
}