daily pastebin goal
2%
SHARE
TWEET

Untitled

a guest Jun 13th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * File:   Led.c
  3.  * Author: Pedro Alves
  4.  *
  5.  * Created on 15 de Maio de 2018, 14:13
  6.  *  Set PORTB to all outputs
  7.  *  Set PORTB to all high
  8.  *  Wait for half a second
  9.  *  Set PORTB to all low
  10.  *  Wait for half a second
  11.  *  Do it again
  12.  *
  13.  */
  14. #include <htc.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17.  
  18. #define _XTAL_FREQ 4000000     /* required for HITECH PICC delay macros */
  19.  
  20. // BEGIN CONFIG
  21. #pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator)
  22. #pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT enabled)
  23. #pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
  24. #pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)
  25. #pragma config LVP = OFF        // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
  26. #pragma config CPD = OFF        // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
  27. #pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
  28. #pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)
  29. //END CONFIG
  30.  
  31.  
  32. // Global vars
  33.  
  34. char bootDONE = 0;          //BOOT FLAG - 1 WHEN BOOT DONE
  35. unsigned int msCounter = 0;             //MILISECOND COUNTER
  36. unsigned int secCounter = 0;            //SECOND COUNTER
  37. unsigned int minCounter = 0;            //MINUTE COUNTER
  38. unsigned int hrCounter = 0;             //HOUR COUNTER
  39. unsigned int dayCounter = 0;            //DAY COUNTER
  40.  
  41. unsigned int timer20ms = 0;             //PROCESSING STATES COUNTER - RESTART EVERY 20 MILISECONDS
  42. unsigned int timer10s = 0;               //PROCESSING SENSORS VALUES - RESTART EVERY 10 SECONDS
  43.  
  44.  
  45.  
  46. /*----------------------------------------------*/
  47. /* Initialize this PIC                          */
  48. /*----------------------------------------------*/
  49. void HardwareConfiguration(void)
  50. {
  51.     PORTD = 0x00 ;
  52.     TRISD = 0x00 ;
  53.    
  54.     TRISB = 0xFF;
  55.     TRISA = 0xFF;
  56.     // Initialize ADC
  57.     ADCON1 = 0x06;          /* Turn off ADC */
  58.     /* Disable all interrupt sources */
  59.     INTCON = 0x00;
  60.     PIE1 = 0x00;
  61.     PIE2 = 0x00;
  62.  
  63.     CMCON = 0x07;           /* turn off comparators */
  64.  
  65.  
  66.     OPTION_REG = 0b11011110;/* PORTB weak pull ups disabled */
  67.                             /* Interrupt on rising edge of RB0/INT pin */
  68.                             /* T0 internal clock source */
  69.                             /* T0 clock edge high-to-low */
  70.                             /* Prescaler assigned to WDT */
  71.                             /* Prescale 1:64 for WDT */
  72.     /* turn on the interrupt system */
  73. }
  74.  
  75. void Boot(void)
  76. {
  77. // Turn ON and OFF all LEDS
  78.    
  79.     TRISB = 0b00000000; /* make all pins of PORTB output pins */
  80.     PORTB = 0b00111100; /* set all PORTB outputs high */
  81.     __delay_ms(2000);
  82.     PORTB = 0b00000000; /* set all PORTB outputs low */
  83.     __delay_ms(1000);
  84.    
  85. }
  86.  
  87. /*----------------------------------------------*/
  88. /* Main                                         */
  89. /*----------------------------------------------*/
  90. void main (void)
  91. {
  92.     HardwareConfiguration();                //HARDWARE CONFIGURATION1
  93.     Boot();    
  94.     while(1)
  95.     {
  96.         PORTB = 0b00111100; /* set all PORTB outputs high */
  97.         __delay_ms(500);
  98.         PORTB = 0b00000000; /* set all PORTB outputs low */
  99.         __delay_ms(500);
  100.     }
  101.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top