//----------------------------------------------------------------------------- // Note // 1桁の7セグメントの点灯 // PICの周波数を32Mhzに設定 //----------------------------------------------------------------------------- #include #include #include // コンフィグレーションBIT1 設定 #pragma config FOSC = INTOSC // Oscillator Selection (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 CPD = OFF // Data Memory Code Protection (Data memory code protection is disabled) #pragma config BOREN = OFF // Brown-out Reset Enable (Brown-out Reset disabled) #pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin) #pragma config IESO = OFF // Internal/External Switchover (Internal/External Switchover mode is disabled) #pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled) // コンフィグレーションBIT2 設定 #pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off) #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 = HI // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), high trip point selected.) #pragma config LVP = OFF // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming) // 点灯IOの定義 #define SEG_LED_A RA2 #define SEG_LED_B RC0 #define SEG_LED_C RC7 #define SEG_LED_D RC6 #define SEG_LED_E RC3 #define SEG_LED_F RA1 #define SEG_LED_G RA0 #define SEG_LED_DP RB7 // 点灯位置の設定 const unsigned char seg_led[18] = { {0b00111111}, // 0 {0b00000110}, // 1 {0b01011011}, // 2 {0b01001111}, // 3 {0b01100110}, // 4 {0b01101101}, // 5 {0b01111101}, // 6 {0b00100111}, // 7 {0b01111111}, // 8 {0b01100111}, // 9 {0b00000001}, // a {0b00000010}, // b {0b00000100}, // c {0b00001000}, // d {0b00010000}, // e {0b00100000}, // f {0b01000000}, // g {0b10000000} // dp }; int main(int argc, char** argv) { long i; long wait = 1000000; short seg = 0; short num = 10; OSCCON = 0b01110000 ; // 内部クロック8MHz ANSELA = 0b00000000 ; // すべてデジタルI/Oに割当てる TRISA = 0b00001000 ; // ピンは全て出力に割当てる(RA3は入力のみとなる) PORTA = 0b00000000 ; // 出力ピンの初期化(全てLOWにする) ANSELB = 0b00000000 ; // すべてデジタルI/Oに割当てる TRISB = 0b00000000 ; // ピンは全て出力に割当てる PORTB = 0b00000000 ; // 出力ピンの初期化(全てLOWにする) ANSELC = 0b00000000 ; // すべてデジタルI/Oに割当てる TRISC = 0b00000000 ; // ピンは全て出力に割当てる PORTC = 0b00000000 ; // 出力ピンの初期化(全てLOWにする) for(;;) { seg = seg_led[num]; // a点灯 if( (seg & 0x01) != 0 ) SEG_LED_A = 0; else SEG_LED_A = 1; // b点灯 if( (seg & 0x02) != 0 ) SEG_LED_B = 0; else SEG_LED_B = 1; // c点灯 if( (seg & 0x04) != 0 ) SEG_LED_C = 0; else SEG_LED_C = 1; // d点灯 if( (seg & 0x08) != 0 ) SEG_LED_D = 0; else SEG_LED_D = 1; // e点灯 if( (seg & 0x10) != 0 ) SEG_LED_E = 0; else SEG_LED_E = 1; // f点灯 if( (seg & 0x20) != 0 ) SEG_LED_F = 0; else SEG_LED_F = 1; // g点灯 if( (seg & 0x40) != 0 ) SEG_LED_G = 0; else SEG_LED_G = 1; // DP点灯 if( (seg & 0x80) != 0 ) SEG_LED_DP = 0; else SEG_LED_DP = 1; // 待ち時間設定 if( num < 10 ) { wait = 1000000; } else { wait = 500000; } for(i=0; i= 18) num = 0; } return (EXIT_SUCCESS); }