Browse Source

breathing led

master
Yorick van Pelt 1 year ago
parent
commit
45068a2816
Signed by: Yorick van Pelt <yorick@yorickvanpelt.nl> GPG Key ID: D8D3CC6D951384DE
1 changed files with 20 additions and 15 deletions
  1. 20
    15
      src/blink_led.c

+ 20
- 15
src/blink_led.c View File

@@ -22,11 +22,12 @@ __code uint16_t __at (_CONFIG1) __configword = _FOSC_INTOSC & _CLKOUTEN_OFF & _W
void delay(uint16_t iterations)
{
uint16_t i, j;
for (i = 0; i < iterations; i++) {
// Prevent this loop from being optimized away.
for (j = 0; j < 1000; j++) {
//for (j = 0; j < 12; j++) {
__asm nop __endasm;
}
//}
}
}
#define PPSO_PWM1 3
@@ -35,12 +36,12 @@ void main(void)
OSCCON = 0xf0;
TRISC = 0;
//SLRCONC = 0;
OPTION_REGbits.PSA = 1;
LED_PORT = 0;
PWM1CLKCON = 0x00; // From Fosc w/o prescaler
PWM1PRH = PWM1PRL = 0xFF;
PWM1PH = 0;
PWM1DCH = 0x80;
PWM1DCL = 0;
PWM1DCH = PWM1DCL = 0;
PWM1OF = 0;

@@ -55,15 +56,19 @@ void main(void)


while (1) {
//LED_PORT = 1; // LED On
PWM1DCH = 0x80;
PWMLD = 1;
delay(300);
//LED_PORT = 0; // LED Off
//PWM1DCH = 0xff;
PWM1DCH = 0x10;
PWMLD = 1;
delay(300);
}
while(1) {
delay(1);
while (PWM1DCL < 0xFF || PWM1DCH < 0xFE) {
if (PWM1DCL == 0xFF) PWM1DCH++;
PWM1DCL++;
PWMLD = 1;
delay(1);
}
while (PWM1DCL > 0 || PWM1DCH > 0) {
if (PWM1DCL == 0) PWM1DCH--;
PWM1DCL--;
PWMLD = 1;
delay(1);
}
}
}

Loading…
Cancel
Save