From 45068a281695a47ee0c06963005cac7783c07a91 Mon Sep 17 00:00:00 2001 From: Yorick van Pelt Date: Wed, 9 Jan 2019 01:46:48 +0100 Subject: [PATCH] breathing led --- src/blink_led.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/blink_led.c b/src/blink_led.c index 01f2f36..fa3df74 100644 --- a/src/blink_led.c +++ b/src/blink_led.c @@ -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); + } + } }