void print_month(int month, int year) { int ymo = year - 1, i, days=0, dow = 0, start = 0; int month_length(int n, int year); char *month_name(int n); // Find the number of days in the year before the first day of the month for (i = 1; i < month; i++){ days += month_length(i, year); } // Find the day of week which the first of the month lands on dow = (1 + days + 365*ymo + ymo/4 - ymo/100 + ymo/400) % 7; // Print the header information printf(" %s, %d\n", month_name(month), year); printf(" S M T W R F S\n"); // Print spaces until the right day of week for (i = 0; i < dow; i++) printf(" "); // Print the lines for each week, putting a new line every seven entries for (i = 0; i < month_length(month, year); i++, dow++){ if ((dow % 7) == 0 && start != 0) printf("\n"); start++; (i > 8) ? printf(" %d", i + 1) : printf(" %d", i + 1); } printf("\n"); }
void main(void) { OSCCON = 0b11110000; // 内部クロックは8MHzとする OPTION_REG = 0b00000000; // デジタルI/Oに内部プルアップ抵抗を使用する ANSELA = 0b00000000; // AN0-AN4は使用しない全てデジタルI/Oとする ANSELB = 0b00000000; // AN5-AN11は使用しない全てデジタルI/Oとする TRISA = 0b00000011; // ピン(RA)は全て出力に割当てる(RA5は入力のみとなる) TRISB = 0b00010110; // ピン(RB)はRB4(SCL1)/RB1(SDA1)のみ入力 WPUB = 0b00010010; // RB1/4は内部プルアップ抵抗を指定する PORTA = 0b00000000; // RA出力ピンの初期化(全てLOWにする) PORTB = 0b00000000; // RB出力ピンの初期化(全てLOWにする) APFCON0bits.RXDTSEL = 1; APFCON1bits.TXCKSEL = 1; T1CON = 0x21; //Fosc/4, ps:1/4 TMR1H = 0x00; TMR1L = 0x00; PIE1bits.TMR1IE = 1; I2C_init(); LCD_init(); UART_init(PIC16F1827); INTCONbits.PEIE = 1; INTCONbits.GIE = 1; uint8_t buf[70]; ringbuf_init(&tx_buf, buf, sizeof (buf)); RTC_Write(0x07, 0x00); while (1) { display(); if (sw_RA1.flag.press) { sw_RA1.flag.press=0; tx_send('2'); tx_send('0'); tx_send(((YY & 0xF0) >> 4) + '0'); tx_send((YY & 0x0F) + '0'); tx_send('/'); tx_send(((MM & 0xF0) >> 4) + '0'); tx_send((MM & 0x0F) + '0'); tx_send('/'); tx_send(((DD & 0xF0) >> 4) + '0'); tx_send((DD & 0x0F) + '0'); tx_send('('); tx_send((EE & 0x0F) + '0'); tx_send(')'); tx_send(((hh & 0xF0) >> 4) + '0'); tx_send((hh & 0x0F) + '0'); tx_send(':'); tx_send(((mm & 0xF0) >> 4) + '0'); tx_send((mm & 0x0F) + '0'); tx_send('-'); tx_send(((ss & 0xF0) >> 4) + '0'); tx_send((ss & 0x0F) + '0'); tx_send('.'); tx_send('\n'); tx_sends("Real Time Clock\n"); } if (sw_RA0.flag.long_holding_1) { sw_RA0.flag.long_holding_1 = 0; timeset(&YY, 0, 99, 0x06, 0, 0); timeset(&MM, 1, 12, 0x05, 3, 0); timeset(&DD, 1, month_length(YY, MM), 0x04, 6, 0); timeset(&hh, 0, 23, 0x02, 0, 1); timeset(&mm, 0, 59, 0x01, 3, 1); timeset(&ss, 0, 59, 0x00, 6, 1); } }