Created
January 24, 2016 21:24
-
-
Save allisontharp/84c936274f97e39cf2e1 to your computer and use it in GitHub Desktop.
C++ script for Pic18f24k20 microcontroller that illuminates an LED on pin RA1 for approximately 30 seconds
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
//****************************************************************************** | |
//Software License Agreement | |
// | |
//The software supplied herewith by Microchip Technology | |
//Incorporated (the "Company") is intended and supplied to you, the | |
//Companyâs customer, for use solely and exclusively on Microchip | |
//products. The software is owned by the Company and/or its supplier, | |
//and is protected under applicable copyright laws. All rights are | |
//reserved. Any use in violation of the foregoing restrictions may | |
//subject the user to criminal sanctions under applicable laws, as | |
//well as to civil liability for the breach of the terms and | |
//conditions of this license. | |
// | |
//THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES, | |
//WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED | |
//TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | |
//PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, | |
//IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR | |
//CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. | |
// ******************************************************************* | |
// PIC18F45K20 PICkit 3 Debug Express Demo Board Lesson 7 - ADC | |
// | |
// This lesson uses the Analog-to-Digital-Converter on the PIC18F45K20 | |
// to convert the potentiometer voltage on pin RA0 to a value used | |
// to set the speed of the LED rotation. | |
// | |
// ******************************************************************* | |
// * See included documentation for Lesson instructions * | |
// ******************************************************************* | |
/** C O N F I G U R A T I O N B I T S ******************************/ | |
#pragma config FOSC = INTIO67 //, FCMEN = OFF, IESO = OFF // CONFIG1H | |
#pragma config BOREN = OFF //PWRT = OFF, , BORV = 30 // CONFIG2L | |
#pragma config WDTEN = OFF | |
#pragma config MCLRE = OFF, LVP = OFF//, LPT1OSC = OFF, PBADEN = ON, CCP2MX = PORTBE // CONFIG3H | |
/** I N C L U D E S **************************************************/ | |
#include "p18f24k20.h" | |
#include "delays.h" | |
/** V A R I A B L E S *************************************************/ | |
/** D E C L A R A T I O N S *******************************************/ | |
void high_isr( void ); | |
void low_isr( void ); | |
/** Declare Interrupt Vector Sections ****************************/ | |
#pragma code high_vector=0x08 | |
void interrupt_at_high_vector(void) | |
{ | |
_asm goto high_isr _endasm | |
} | |
#pragma code low_vector=0x18 | |
void interrupt_at_low_vector (void) | |
{ | |
_asm goto low_isr _endasm | |
} | |
#pragma code // declare executable instructions | |
/* | |
Purpose: | |
* Turn on 3 LEDs for approximately 30 seconds, then turn them off | |
Flow: | |
* initialize chip's pins and allow interrupts. Next, turn LED output pin | |
* (pin RA1) on for 30 seconds, then turn it off | |
Versions: | |
* 0.1 - initial release | |
*/ | |
void main (void) | |
{ | |
char i; //counter | |
// Set unused pins as output | |
TRISA = 0b10000000; // CLKI is input (RA7) | |
OSCCONbits.IRCF = 0b111; // sets oscillator to 16MHz 111 | |
RCONbits.IPEN = 1; // Allow interrupts | |
INTCONbits.GIEL = 1; // Allow low priority interrupts | |
// set RA1 as output and turn it on | |
TRISAbits.RA1 = 0; | |
PORTAbits.RA1 = 1; | |
while (1) | |
{ | |
// for LED to light up 30 seconds: 10000*4*109*109/16000000 | |
for (i = 0; i <= 109; i++) | |
{ | |
Delay10KTCYx(109); | |
} | |
// turn RA1 off | |
PORTAbits.RA1 = 0; | |
} | |
} | |
/***************************************************************** | |
* Function : void high_isr(void) | |
* Input : None (triggers from PIR1bits.RCIF | |
* Output : None (but puts values in global variable 'buf' | |
* Notes : Triggers during USART reception. Puts values from USART communication | |
into global variable 'buf'. Once reception is complete (receives ASCII 47 ('/')), | |
sets flag = 1 and ParkerCommTransmit function begins. | |
******************************************************************/ | |
#pragma interrupt high_isr // declare function as high priority isr | |
void high_isr(void) | |
{ | |
} | |
/***************************************************************** | |
* Function: void low_isr(void) | |
* Input: | |
* Output: | |
* Overview: | |
******************************************************************/ | |
#pragma interruptlow low_isr // declare function as low priority isr | |
void low_isr(void) | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment