//********************************************************************** /* <CWメモリキーヤー> */ //********************************************************************** #define SW_REC PORTA.F2 #define SW_PLAY PORTA.F3 #define SW_ACCURACY PORTA.F4 #define LED_REC PORTB.F1 #define LED_PLAY PORTB.F2 #define LED_OUTPUT PORTB.F3 #define CW_INPUT PORTA.F5 #define CW_OUTPUT PORTB.F4 #define DELAY_TIME1 20 #define DELAY_TIME2 30 //********************************************************************** void Pwm_Change_DutyEx(unsigned int duty_ratio) { CCPR1L = duty_ratio >> 2; CCP1CON.F6 = duty_ratio & 0b00000001; CCP1CON.F7 = (duty_ratio & 0b00000010) >> 1; } //********************************************************************** void Delay_ex() { if (SW_ACCURACY == 1) { Delay_ms(DELAY_TIME1); } else { Delay_ms(DELAY_TIME2); } } //********************************************************************** void recProc() { static unsigned int cnt1; static unsigned short cnt2, tmp; // LED_REC = 1; for (cnt1 = 0; cnt1 < 256; cnt1++) { tmp = 0x00; for (cnt2 = 0; cnt2 < 8; cnt2++) { if (CW_INPUT == 0) { tmp |= 0x01; Pwm_Start(); LED_OUTPUT = 1; CW_OUTPUT = 1; } else { Pwm_Stop(); LED_OUTPUT = 0; CW_OUTPUT = 0; } if (cnt2 < 7) { tmp = tmp << 1; Delay_ex(); } } Eeprom_Write(cnt1, tmp); Delay_ex(); } LED_REC = 0; Pwm_Stop(); LED_OUTPUT = 0; CW_OUTPUT = 0; } //********************************************************************** void playProc() { static unsigned int cnt1; static unsigned short cnt2, tmp; // LED_PLAY = 1; for (cnt1 = 0; cnt1 < 256; cnt1++) { tmp = Eeprom_Read(cnt1); for (cnt2 = 0; cnt2 < 8; cnt2++) { if ((tmp & 0x80) != 0) { Pwm_Start(); LED_OUTPUT = 1; CW_OUTPUT = 1; } else { Pwm_Stop(); LED_OUTPUT = 0; CW_OUTPUT = 0; } tmp = tmp << 1; Delay_ex(); } } LED_PLAY = 0; Pwm_Stop(); LED_OUTPUT = 0; CW_OUTPUT = 0; } //********************************************************************** void main() { static short cnt; // //ポート関連の設定 TRISA = 0b11111111; TRISB = 0b00000000; OSCCON = 0b01100000; // クロックを4Mhzに設定する。 ANSEL = 0b00000000; // A/D変換は使用しない。 //PWMの設定(1kHz) Pwm_Init(1000); Pwm_Change_DutyEx((PR2 * 4) / 2); Pwm_Stop(); // for (cnt = 0; cnt < 5; cnt++) { LED_REC = 1; LED_PLAY = 1; LED_OUTPUT = 1; Pwm_Start(); Delay_ms(200); Pwm_Stop(); LED_REC = 0; LED_PLAY = 0; LED_OUTPUT = 0; Delay_ms(200); } // while (1) { if (SW_REC == 0) { recProc(); } if (SW_PLAY == 0) { playProc(); } } } //**********************************************************************