Skip to content

Instantly share code, notes, and snippets.

@mipsparc
Created April 11, 2018 15:46
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 mipsparc/e63d24f7e17eaebe3b2e58562abc5610 to your computer and use it in GitHub Desktop.
Save mipsparc/e63d24f7e17eaebe3b2e58562abc5610 to your computer and use it in GitHub Desktop.
USARTで送信するテスト PIC16F1579向け
// PIC16F1579 Configuration Bit Settings
// 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 = ON // Power-up Timer Enable (PWRT enabled)
#pragma config MCLRE = OFF // MCLR Pin Function Select (MCLR/VPP pin function is digital input)
#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config PPS1WAY = ON // PPSLOCK bit One-Way Set Enable bit (PPSLOCKED Bit Can Be Cleared & Set Once)
#pragma config PLLEN = ON // PLL Enable (4x PLL enabled)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LPBOREN = OFF // Low Power Brown-out Reset enable bit (LPBOR is disabled)
#pragma config LVP = ON // Low-Voltage Programming Enable (Low-voltage programming enabled)
#define _XTAL_FREQ 16000000
#include <xc.h>
void writeSerial(char write_char)
{
while(!(PIR1bits.TXIF && TXSTAbits.TRMT));
TXREG = write_char;
}
void main(void)
{
OSCCON = 0b01111011; // 16MHz
ANSELC = 0b00000000;
TRISC = 0b00111111; // RC0 to RC5 input
PORTC = 0b00000000;
RA0PPS = 0b1001; // RA0 UART TX
TXSTA = 0b00100000; // 8bit UART
RCSTA = 0b10010000;
SPBRG = 25; // 16MHz 9600bps
while(1) {
writeSerial('O');
writeSerial('K');
while(!TXSTAbits.TRMT);
__delay_ms(1000);
}
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment