[ create a new paste ] login | about

Link: http://codepad.org/t4cXuGZM    [ raw code | output | fork ]

C, pasted on Oct 5:
/*
 * File:   4modeswitch.c
 * Author: hage no ossan dame ningen
 * DEVICE = 16F88 
 * TOOLS xc8 v2.10 MPLAB X IDE 5.25 PICKIT3 win10 core i3 LGA1150 1F DeskTopPC jitaku
 * Created on 2019/09/28, 16:13(本日未使用MACアドレスPCへの新規ダウンロードなのであと60日は最適化最大?)
 */
#include <xc.h>

// CONFIG1
#pragma config FOSC = INTOSCIO  // Oscillator Selection bits (INTRC oscillator; port I/O function on both RA6/OSC2/CLKO pin and RA7/OSC1/CLKI pin)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON       // Power-up Timer Enable bit (PWRT enabled)
#pragma config MCLRE = OFF      // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is digital I/O, MCLR internally tied to VDD)
#pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF        // Low-Voltage Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF        // Data EE Memory Code Protection bit (Code protection off)
#pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off)
#pragma config CCPMX = RB3      // CCP1 Pin Selection bit (CCP1 function on RB3)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)

// CONFIG2
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
#pragma config IESO = OFF       // Internal External Switchover bit (Internal External Switchover mode disabled)

#define _XTAL_FREQ 8000000
#define konkaiJotai RA0 // ← ***追加*** RA0の代わりに単語を使用する


void main(void) {
     
    OSCCON = 0b01110000;    // 内蔵クロックの周波数を8MHzに設定
 
    PORTA = 0x00;           // PORTAを初期化
    PORTB = 0x00;           // PORTBを初期化
 
    TRISA = 0x01;           // PORTA0(第17ピン)を入力に設定
    TRISB = 0x00;           // PORTBを全ピン(第6-13ピン)出力に設定
   
    ANSEL = 0x00;           // A/D変換を無効化
    ADCON0 = 0x00;
    ADCON1 = 0x00;
 
    int i;
   for (i = 0; i < 6; i++) {
     PORTB = 0b00000001;   //以下、プログラムがちゃんと動き出したことの確認
    __delay_ms(50);        //最初の4bitは2SC1815を経てメカニカルリレーへ。
     PORTB = 0b00000010;   //後ろの4bitは抵抗510オームを経てLED直結
    __delay_ms(50);        //リレーは倍率の違うOPアンプ回路の出力を一つだけ選択する
     PORTB = 0b00000100;   //ロータリースイッチは接点がすぐだめになるので
    __delay_ms(50);
     PORTB = 0b00001000;
    __delay_ms(50); 
     PORTB = 0b00000100;
    __delay_ms(50); 
     PORTB = 0b00000010;
    __delay_ms(50); 
   }
     PORTB = 0b00000001;
    __delay_ms(50);  
     PORTB = 0b00001111;  //合計80mAほど(<200mA)
    __delay_ms(500);
    
    PORTB = 0b10001000;
    

// ===============以下修正済===============
// konkaiJotaiとzenkaiJotaiを採用してみた(#^^#)
// やっぱPICは内臓プルアッ(ry (これを言うとなぜかスレが有れる)

    struct bits {
        bool bit0 : 1;
        bool bit1 : 1;
        bool bit2 : 1;
        bool bit3 : 1;
        bool bit4 : 1;
        bool bit5 : 1;
        bool bit6 : 1;
        bool bit7 : 1;
    };

    union {
        uint8_t uint8;
        struct bits bt;
    } Mode;

    union {
        uint8_t uint8;
        struct bits bt;
    } zenkaiJotai;
    

    zenkaiJotai.bt.bit0 = 0;

    uint8_t ButtonChangeTime = 0; // int → unsigned char → uint8_t

    Mode.uint8 = 0b00000001;

    while (1) {

        __delay_ms(5); //←タイマーに置き換える if(timer){...}

        if (!zenkaiJotai.bt.bit0) {
            if (konkaiJotai) {
                if (!--ButtonChangeTime) {

                    zenkaiJotai.bt.bit0 = 1;
                    Mode.uint8 <<= 1;

                    if (Mode.bt.bit1) {
                        PORTB = 0b00000010;
                    } else if (Mode.bt.bit2) {
                        PORTB = 0b00000100;
                    } else if (Mode.bt.bit3) {
                        PORTB = 0b00001000;
                    } else if (Mode.bt.bit4) {
                        PORTB = 0b00010000;
                        Mode.uint8 = 0b00000001;
                    }
                }
            } else {
                ButtonChangeTime = 4;//ON判定を重くしてチャタリング&ノイズ対策(ノイズ問題でもスレが荒れる・・・)
            }
        } else {
            if (!konkaiJotai) {
                if (!--ButtonChangeTime) {
                    zenkaiJotai.bt.bit0 = 0;
                }
            } else {
                ButtonChangeTime = 20;//OFF判定を重くして2重押し防止
            }
        }
    }
}


Output:
Line 15: error: xc.h: No such file or directory
In function 'main':
Line 32: error: 'OSCCON' undeclared (first use in this function)
Line 32: error: (Each undeclared identifier is reported only once
Line 32: error: for each function it appears in.)
Line 13: error: invalid suffix "b01110000" on integer constant
Line 34: error: 'PORTA' undeclared (first use in this function)
Line 35: error: 'PORTB' undeclared (first use in this function)
Line 37: error: 'TRISA' undeclared (first use in this function)
Line 38: error: 'TRISB' undeclared (first use in this function)
Line 40: error: 'ANSEL' undeclared (first use in this function)
Line 41: error: 'ADCON0' undeclared (first use in this function)
Line 42: error: 'ADCON1' undeclared (first use in this function)
Line 13: error: invalid suffix "b00000001" on integer constant
Line 13: error: invalid suffix "b00000010" on integer constant
Line 13: error: invalid suffix "b00000100" on integer constant
Line 13: error: invalid suffix "b00001000" on integer constant
Line 13: error: invalid suffix "b00000100" on integer constant
Line 13: error: invalid suffix "b00000010" on integer constant
Line 13: error: invalid suffix "b00000001" on integer constant
Line 13: error: invalid suffix "b00001111" on integer constant
Line 12: error: invalid suffix "b10001000" on integer constant
Line 72: error: expected specifier-qualifier-list before 'bool'
Line 83: error: expected specifier-qualifier-list before 'uint8_t'
Line 88: error: expected specifier-qualifier-list before 'uint8_t'
Line 93: error: 'union <anonymous>' has no member named 'bt'
Line 95: error: 'uint8_t' undeclared (first use in this function)
Line 95: error: expected ';' before 'ButtonChangeTime'
Line 97: error: 'union <anonymous>' has no member named 'uint8'
Line 17: error: invalid suffix "b00000001" on integer constant
Line 103: error: 'union <anonymous>' has no member named 'bt'
Line 104: error: 'RA0' undeclared (first use in this function)
Line 105: error: 'ButtonChangeTime' undeclared (first use in this function)
Line 107: error: 'union <anonymous>' has no member named 'bt'
Line 108: error: 'union <anonymous>' has no member named 'uint8'
Line 110: error: 'union <anonymous>' has no member named 'bt'
Line 32: error: invalid suffix "b00000010" on integer constant
Line 112: error: 'union <anonymous>' has no member named 'bt'
Line 32: error: invalid suffix "b00000100" on integer constant
Line 114: error: 'union <anonymous>' has no member named 'bt'
Line 32: error: invalid suffix "b00001000" on integer constant
Line 116: error: 'union <anonymous>' has no member named 'bt'
Line 32: error: invalid suffix "b00010000" on integer constant
Line 118: error: 'union <anonymous>' has no member named 'uint8'
Line 37: error: invalid suffix "b00000001" on integer constant
Line 127: error: 'union <anonymous>' has no member named 'bt'
Line 30: warning: return type of 'main' is not 'int'


Create a new paste based on this one


Comments: