DE10/DE15に使用されるMC45A主幹制御器などからノッチを読み取るやつ(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 = OFF // PLL Disabled | |
#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) | |
#define _XTAL_FREQ 16000000 | |
#include <xc.h> | |
#include <stdio.h> | |
void putch(char write_char) | |
{ | |
while(!TXSTAbits.TRMT); | |
TXREG = write_char; | |
} | |
void main(void) | |
{ | |
OSCCON = 0b01111011; // 16MHz | |
ANSELC = 0b00000000; // All digital | |
TRISC = 0b11111111; // PORTC all input | |
PORTC = 0b00000000; // PORTC init | |
ANSELB = 0b00000000; | |
TRISB = 0b00010000; // RB4 input | |
PORTB = 0b00000000; | |
TRISA = 0b00000000; | |
RA0PPS = 0b00001001; // RA0 UART TX | |
TXSTA = 0b00100000; // 8bit UART | |
RCSTA = 0b10010000; | |
SPBRG = 25; // 16MHz 9600bps | |
INTCONbits.GIE = 1; // accept interrupt | |
PIE1bits.TXIE = 1; // accept TX interrupt | |
unsigned char mascon = 0; | |
unsigned char txbyte; | |
while (1) { | |
if (PORTCbits.RC3 == 1 && (PORTC & 0b00010111)) { // 18????ON | |
mascon = (PORTCbits.RC4 << 3) + (PORTC & 0b00000111) - 1; | |
} else { | |
mascon = 0; | |
} | |
txbyte = (PORTC & 0b11100000) + (PORTBbits.RB4 << 4) + mascon; | |
putch("%c", txbyte); | |
while(!TXSTAbits.TRMT); | |
__delay_ms(100); | |
} | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment