Last active
September 30, 2020 06:17
-
-
Save Costava/2eec172b2e0d34653ffa372e543e854f to your computer and use it in GitHub Desktop.
Straightforward LED blinking program for PIC32 devices.
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
// pic32_blink_led.c | |
// Author: github.com/Costava | |
// License: MIT License (see end of file) | |
// The wiring is the recommended minimum connections with an additional resistor | |
// and LED. The positive lead of the LED is connected to VDD and the negative | |
// lead to RB3 through a 220 ohm resistor. | |
// Tested on: | |
// PIC32MX270F256B | |
// MPLAB X IDE v4.15 | |
// XC32 v2.05 | |
#include "xc.h" | |
#include "p32xxxx.h" | |
#pragma config FWDTEN = OFF // Turn off watchdog timer | |
#pragma config FNOSC = FRCPLL // Select 8 MHz internal Fast RC (FRC) oscillator with PLL | |
#pragma config FPLLIDIV = DIV_2 // Divide PLL input (FRC) to get into required range [4 MHz, 5 MHz] | |
#pragma config FPLLMUL = MUL_15 // PLL Multiplier | |
#pragma config FPLLODIV = DIV_1 // PLL Output Divider | |
#pragma config FPBDIV = DIV_1 // Peripheral Clock divisor | |
// Operating at 8 / 2 * 15 / 1 = 60 MHz | |
void led_on() { | |
LATBbits.LATB3 = 0; | |
} | |
void led_off() { | |
LATBbits.LATB3 = 1; | |
} | |
void delay() { | |
int i; | |
for (i = 0; i < 1400000; i += 1); | |
} | |
int main() { | |
ANSELBbits.ANSB3 = 0;// RB3 is digital | |
TRISBbits.TRISB3 = 0;// RB3 is output | |
while (1) { | |
delay(); | |
led_off(); | |
delay(); | |
led_on(); | |
} | |
return 0; | |
} | |
/* | |
Copyright (c) 2020 Costava | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
SOFTWARE. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment