PWM Disp
This commit is contained in:
parent
0fc16cc75f
commit
5ba5925433
1 changed files with 16 additions and 29 deletions
|
|
@ -1,10 +1,7 @@
|
||||||
#include "LPC17xx.h"
|
#include "LPC17xx.h"
|
||||||
|
|
||||||
volatile unsigned long int duty_cycle = 10;
|
volatile unsigned long int duty_cycle = 300;
|
||||||
volatile unsigned long int pwm_counter = 0;
|
unsigned int last_key = 0xFF;
|
||||||
|
|
||||||
#define LED_SHIFT 4
|
|
||||||
#define LED_MASK (0xFF << LED_SHIFT)
|
|
||||||
|
|
||||||
#define COL0 (1<<0)
|
#define COL0 (1<<0)
|
||||||
#define COL1 (1<<1)
|
#define COL1 (1<<1)
|
||||||
|
|
@ -15,8 +12,6 @@ volatile unsigned long int pwm_counter = 0;
|
||||||
#define COL_MASK_P0 (COL2 | COL3)
|
#define COL_MASK_P0 (COL2 | COL3)
|
||||||
#define COL_MASK_P2 (COL0 | COL1)
|
#define COL_MASK_P2 (COL0 | COL1)
|
||||||
|
|
||||||
#define PWM_PERIOD 100
|
|
||||||
|
|
||||||
static void delay_ms(unsigned int ms) {
|
static void delay_ms(unsigned int ms) {
|
||||||
unsigned int i, j;
|
unsigned int i, j;
|
||||||
for(i = 0; i < ms; i++)
|
for(i = 0; i < ms; i++)
|
||||||
|
|
@ -45,15 +40,8 @@ void PWM1_IRQHandler(void)
|
||||||
{
|
{
|
||||||
if (LPC_PWM1->IR & (1 << 0))
|
if (LPC_PWM1->IR & (1 << 0))
|
||||||
{
|
{
|
||||||
if(pwm_counter < duty_cycle)
|
LPC_PWM1->MR4 = duty_cycle;
|
||||||
LPC_GPIO0->FIOSET = LED_MASK;
|
LPC_PWM1->LER = (1 << 4);
|
||||||
else
|
|
||||||
LPC_GPIO0->FIOCLR = LED_MASK;
|
|
||||||
|
|
||||||
pwm_counter++;
|
|
||||||
if(pwm_counter >= PWM_PERIOD)
|
|
||||||
pwm_counter = 0;
|
|
||||||
|
|
||||||
LPC_PWM1->IR = (1 << 0);
|
LPC_PWM1->IR = (1 << 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -62,33 +50,32 @@ 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;
|
||||||
|
|
||||||
LPC_SC->PCONP |= (1 << 6);
|
|
||||||
|
|
||||||
LPC_PWM1->TCR = (1 << 1);
|
LPC_PWM1->TCR = (1 << 1);
|
||||||
LPC_PWM1->CTCR = 0;
|
LPC_PWM1->CTCR = 0;
|
||||||
LPC_PWM1->PR = 9;
|
LPC_PWM1->PR = 0;
|
||||||
|
|
||||||
|
LPC_PWM1->MR0 = 3000;
|
||||||
|
LPC_PWM1->MR4 = duty_cycle;
|
||||||
|
|
||||||
LPC_PWM1->MR0 = 100;
|
|
||||||
LPC_PWM1->MCR = (1 << 1) | (1 << 0);
|
LPC_PWM1->MCR = (1 << 1) | (1 << 0);
|
||||||
LPC_PWM1->LER = (1 << 0);
|
LPC_PWM1->PCR = (1 << 12);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
@ -118,10 +105,10 @@ int main(void)
|
||||||
last_key = read_key;
|
last_key = read_key;
|
||||||
|
|
||||||
switch(read_key) {
|
switch(read_key) {
|
||||||
case 0: duty_cycle = 10; break;
|
case 0: duty_cycle = 300; break;
|
||||||
case 1: duty_cycle = 25; break;
|
case 1: duty_cycle = 750; break;
|
||||||
case 2: duty_cycle = 50; break;
|
case 2: duty_cycle = 1500; break;
|
||||||
case 3: duty_cycle = 75; break;
|
case 3: duty_cycle = 2250; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue