You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.6KB

  1. // led blink example Copyright (C) 2014 Diego Herranz
  2. #define NO_BIT_DEFINES
  3. #include <pic14regs.h>
  4. #include <stdint.h>
  5. // Oscillator Selection bits (INTOSCIO oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN),
  6. // disable watchdog,
  7. // and DO NOT disable low voltage programming.
  8. // The rest of fuses are left as default.
  9. __code uint16_t __at (_CONFIG1) __configword = _FOSC_INTOSC & _CLKOUTEN_OFF & _WDTE_OFF & _BOREN_ON & _CP_OFF;
  10. #define LED_PORT PORTCbits.RC5
  11. #define LED_TRIS TRISCbits.TRISC5
  12. // board layout:
  13. // mosfets clockwise from power feed:
  14. // RA5, RA4, RC2, RC3
  15. // 'input' pin: RC5
  16. // Uncalibrated delay, just waits a number of for-loop iterations
  17. void delay(uint16_t iterations)
  18. {
  19. uint16_t i;
  20. for (i = 0; i < iterations; i++) {
  21. // Prevent this loop from being optimized away.
  22. __asm nop __endasm;
  23. }
  24. }
  25. #define PPSO_PWM1 3
  26. void main(void)
  27. {
  28. //OSCCON = 0xf0;
  29. TRISC = 0;
  30. //SLRCONC = 0;
  31. LED_PORT = 0;
  32. PWM1CLKCON = 0x00; // From Fosc w/o prescaler
  33. PWM1PRH = PWM1PRL = 0xFF;
  34. PWM1PH = 0;
  35. PWM1DCH = 0xFF;
  36. PWM1OF = 0;
  37. PWMLD = 0x07;
  38. PWM1INTE = 0x00; // no interrupts enabled
  39. PWM1INTF = 0x00; // clear interrupt flag
  40. PWM1LDCON = 0x80; // load armed
  41. PWM1OFCON = 0x00; // independent run mode
  42. PWM1CON = 0x40; // enable, standard PWM mode, active high output
  43. PWMEN = 0x07;
  44. RC5PPS = PPSO_PWM1;
  45. //PWM1OUT = 1;
  46. while (1) {
  47. //LED_PORT = 1; // LED On
  48. PWM1DCH = 1;
  49. PWM1LDCON = 0x80; // load armed
  50. delay(300000);
  51. //LED_PORT = 0; // LED Off
  52. PWM1DCH = 0xff;
  53. PWM1LDCON = 0x80; // load armed
  54. delay(300000);
  55. }
  56. }