Skip to content

Instantly share code, notes, and snippets.

@ha2zakura

ha2zakura/main.c

Last active Apr 8, 2018
Embed
What would you like to do?
PIC18F14K50 Blink(1)
// とりあえずLチカ
// ha2zakura
#include <xc.h> // PIC のハードウエア定義
#define _XTAL_FREQ 48000000
#pragma config FOSC = HS, PLLEN = ON, FCMEN = OFF
#pragma config IESO = OFF, USBDIV = OFF, CPUDIV = NOCLKDIV
#pragma config PWRTEN = OFF, BOREN = OFF, WDTEN = OFF
#pragma config HFOFST = OFF, MCLRE = ON
#pragma config STVREN = ON, BBSIZ = OFF, LVP = OFF
#pragma config XINST = OFF
#pragma config CP0 = OFF, CP1 = OFF, CPB = OFF
#pragma config WRT0 = OFF, WRT1 = OFF, WRTB = OFF, WRTC = OFF
#pragma config EBTR0 = OFF, EBTR1 = OFF, EBTRB = OFF
void delay(int num)
{
while(--num > 0) __delay_us(1000);
}
void main(void){
OSCCON = 0b00000000; // 外部クロックx4
OSCCON2 |= (1 << 2); // PRI_SD = 1
LATB = 0; // PortBのすべてのビットを0に
TRISB = 0b00000000; // LEDの接続されているポートを出力に設定
while(1){
LATB |= (1 << 7);
delay(1000);
LATB &= ~(1 << 7);
delay(1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment