Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File: Led.c
- * Author: Pedro Alves
- *
- * Created on 15 de Maio de 2018, 14:13
- * Set PORTB to all outputs
- * Set PORTB to all high
- * Wait for half a second
- * Set PORTB to all low
- * Wait for half a second
- * Do it again
- *
- */
- #include <htc.h>
- #include <stdio.h>
- #include <stdlib.h>
- #define _XTAL_FREQ 4000000 /* required for HITECH PICC delay macros */
- // BEGIN CONFIG
- #pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
- #pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT enabled)
- #pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
- #pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
- #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)
- #pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
- #pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
- #pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
- //END CONFIG
- // Global vars
- char bootDONE = 0; //BOOT FLAG - 1 WHEN BOOT DONE
- unsigned int msCounter = 0; //MILISECOND COUNTER
- unsigned int secCounter = 0; //SECOND COUNTER
- unsigned int minCounter = 0; //MINUTE COUNTER
- unsigned int hrCounter = 0; //HOUR COUNTER
- unsigned int dayCounter = 0; //DAY COUNTER
- unsigned int timer20ms = 0; //PROCESSING STATES COUNTER - RESTART EVERY 20 MILISECONDS
- unsigned int timer10s = 0; //PROCESSING SENSORS VALUES - RESTART EVERY 10 SECONDS
- /*----------------------------------------------*/
- /* Initialize this PIC */
- /*----------------------------------------------*/
- void HardwareConfiguration(void)
- {
- PORTD = 0x00 ;
- TRISD = 0x00 ;
- TRISB = 0xFF;
- TRISA = 0xFF;
- // Initialize ADC
- ADCON1 = 0x06; /* Turn off ADC */
- /* Disable all interrupt sources */
- INTCON = 0x00;
- PIE1 = 0x00;
- PIE2 = 0x00;
- CMCON = 0x07; /* turn off comparators */
- OPTION_REG = 0b11011110;/* PORTB weak pull ups disabled */
- /* Interrupt on rising edge of RB0/INT pin */
- /* T0 internal clock source */
- /* T0 clock edge high-to-low */
- /* Prescaler assigned to WDT */
- /* Prescale 1:64 for WDT */
- /* turn on the interrupt system */
- }
- void Boot(void)
- {
- // Turn ON and OFF all LEDS
- TRISB = 0b00000000; /* make all pins of PORTB output pins */
- PORTB = 0b00111100; /* set all PORTB outputs high */
- __delay_ms(2000);
- PORTB = 0b00000000; /* set all PORTB outputs low */
- __delay_ms(1000);
- }
- /*----------------------------------------------*/
- /* Main */
- /*----------------------------------------------*/
- void main (void)
- {
- HardwareConfiguration(); //HARDWARE CONFIGURATION1
- Boot();
- while(1)
- {
- PORTB = 0b00111100; /* set all PORTB outputs high */
- __delay_ms(500);
- PORTB = 0b00000000; /* set all PORTB outputs low */
- __delay_ms(500);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement