Created
December 27, 2019 09:42
-
-
Save smalinux/3c7fa8891ad57ecb1783c69c37a70ce4 to your computer and use it in GitHub Desktop.
PIC problem 101
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Microchip Technology Inc. and its subsidiaries. You may use this software | |
* and any derivatives exclusively with Microchip products. | |
* | |
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER | |
* EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED | |
* WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A | |
* PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION | |
* WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION. | |
* | |
* IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, | |
* INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND | |
* WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS | |
* BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE | |
* FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS | |
* IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF | |
* ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. | |
* | |
* MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE | |
* TERMS. | |
*/ | |
/* | |
* File: | |
* Author: | |
* Comments: | |
* Revision history: | |
*/ | |
// This is a guard condition so that contents of this file are not included | |
// more than once. | |
#ifndef XC_HEADER_TEMPLATE_H | |
#define XC_HEADER_TEMPLATE_H | |
#include <xc.h> // include processor files - each processor file is guarded. | |
// TODO Insert appropriate #include <> | |
// TODO Insert C++ class definitions if appropriate | |
// TODO Insert declarations | |
// Comment a function and leverage automatic documentation with slash star star | |
/** | |
<p><b>Function prototype:</b></p> | |
<p><b>Summary:</b></p> | |
<p><b>Description:</b></p> | |
<p><b>Precondition:</b></p> | |
<p><b>Parameters:</b></p> | |
<p><b>Returns:</b></p> | |
<p><b>Example:</b></p> | |
<code> | |
</code> | |
<p><b>Remarks:</b></p> | |
*/ | |
// TODO Insert declarations or function prototypes (right here) to leverage | |
// live documentation | |
#ifdef __cplusplus | |
extern "C" { | |
#endif /* __cplusplus */ | |
// TODO If C++ is being used, regular C code needs function names to have C | |
// linkage so the functions can be used by the c code. | |
#ifdef __cplusplus | |
} | |
#endif /* __cplusplus */ | |
#endif /* XC_HEADER_TEMPLATE_H */ | |
// [ PIC16F877A ] Configuration Bit Settings | |
// #pragma config statements should precede project file includes. | |
// Use project enums instead of #define for ON and OFF. | |
// CONFIG | |
#pragma config FOSC = XT // Oscillator Selection bits (XT oscillator) | |
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled) | |
#pragma config PWRTE = ON // Power-up Timer Enable bit (PWRT enabled) | |
#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) | |
#include <xc.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <xc.h> | |
#include "config.h" | |
#define _XTAL_FREQ 4000000 | |
void main(void) { | |
TRISC1 = 0; | |
TRISC2 = 0; | |
RC1 = 0; | |
RC2 = 0; | |
TRISB0 = 1; | |
INTEDG = 1; | |
INTE = 1; | |
GIE = 1; | |
while (1) { | |
RC2 = 1; | |
__delay_ms(1000); | |
RC2 = 0; | |
__delay_ms(1000); | |
} | |
} | |
void __interrupt () isr(void) { | |
if(INTF) { | |
RC1 = ~RC1; | |
INTF = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment