Skip to content

Instantly share code, notes, and snippets.

@ElektroNeo
Last active November 16, 2019 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ElektroNeo/e9d0c0ef88b6c20695e40f543702ea19 to your computer and use it in GitHub Desktop.
Save ElektroNeo/e9d0c0ef88b6c20695e40f543702ea19 to your computer and use it in GitHub Desktop.
GPIO operations (2) for PIC16F1508 microcontroller.
// PIC16F1508 Configuration Bit Settings
// 'C' source line config statements
// CONFIG1
#pragma config FOSC = INTOSC // Oscillator Selection Bits (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is MCLR)
#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable (Brown-out Reset disabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = OFF // Internal/External Switchover Mode (Internal/External Switchover Mode is disabled)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled)
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config STVREN = OFF // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will not cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LPBOR = OFF // Low-Power Brown Out Reset (Low-Power BOR is disabled)
#pragma config LVP = OFF // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#define _XTAL_FREQ 16000000
#include <xc.h>
void main(void) {
// Internal oscillator.
OSCCONbits.SCS = 0b10;
// 16 MHz internal crystal.
OSCCONbits.IRCF = 0b1111;
// For digital i/o operations
ANSELB = 0;
// PORTB as Output
TRISB = 0;
PORTB = 0b00010000;
while(1) {
for(short i = 0; i < 3; i++) {
PORTB <<= 1;
__delay_ms(500);
}
for(short i = 0; i < 3; i++) {
PORTB >>= 1;
__delay_ms(500);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment