Skip to content

Instantly share code, notes, and snippets.

View mipsparc's full-sized avatar

mipsparc mipsparc

View GitHub Profile
@mipsparc
mipsparc / serialtx.c
Created April 11, 2018 15:46
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)
@mipsparc
mipsparc / meter_increment.c
Created April 11, 2018 16:44
ソフトウェアPWMでちょっとずつメーターが進んでいくテスト
// 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)
@mipsparc
mipsparc / serialrx.c
Created April 13, 2018 14:53
PIC16F1579向け UARTで受信するテスト。RCREGbits.RCREGって書き方、完全に思いつかなかった
// 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)
@mipsparc
mipsparc / mascon_read.c
Last active December 2, 2018 04:13
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)
@mipsparc
mipsparc / pwm_controller.c
Created May 19, 2018 04:17
PWM制御鉄道模型コントローラの試作品の制御用PIC16F1向けプログラム。シリアルで入力されたDuty ratioで駆動する。Microchip MCCで生成されたハードウェア制御用メソッドを呼び出している
#include "mcc_generated_files/mcc.h"
#include <stdio.h>
void move(unsigned char direction)
{
if (direction == 1) {
PWM1_DutyCycleSet(639);
PWM1_LoadBufferSet();
} else {
@mipsparc
mipsparc / scroll.asm
Created May 25, 2018 16:46
0x20に入ったビットがスクロールするだけのPIC向けアセンブリ
ORG 0
RAMTOP
CLRF 0x20
INCF 0x20, 1
LOOP
RLF 0x20, 1
GOTO LOOP
@mipsparc
mipsparc / adding_up_to_16.asm
Created May 25, 2018 17:21
1から16まで足していくだけのPIC向けアセンブリ
ORG 0
RAMTOP
CLRF 0x20
CLRW
CALC
INCF 0x20
ADDWF 0x20, 0
BTFSS 0x20, 4
@mipsparc
mipsparc / adding_up_to_16_2.asm
Created June 2, 2018 09:32
1から16まで足し上げるアセンブリを、動かしやすいようにした。実機での動作確認。
#include "p16f1579.inc"
; CONFIG1
; __config 0xFFA4
__CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOREN_ON & _CLKOUTEN_OFF
; CONFIG2
; __config 0xDEFF
__CONFIG _CONFIG2, _WRT_OFF & _PPS1WAY_ON & _PLLEN_OFF & _STVREN_ON & _BORV_LO & _LPBOREN_OFF & _LVP_OFF
ORG 0
@mipsparc
mipsparc / adding_up_to_16_3.asm
Created June 2, 2018 09:48
include less ver.
__CONFIG 0x8007, 0xFFA4
ORG 0
RAMTOP
MOVLB 0x1
MOVLW b'00010010'
MOVWF 0x99
CLRF 0x8E
MOVLB 0x3
@mipsparc
mipsparc / mascon_read.py
Created June 9, 2018 14:03
https://gist.github.com/mipsparc/f2674a6abda841ef822ad3fc306dd514 から送信されたデータを受け取って表示する
#coding:utf-8
import serial
device = '/dev/ttyUSB0'
ser = serial.Serial(device, baudrate=9600)
mascon_level = -1 # init
static_mascon_level = -1 # init
buttons = -1;