//********************************************************************** /* <CWメモリキーヤーV2> */ //********************************************************************** #define SW_REC PORTA.F2 #define SW_PLAY PORTA.F3 #define SW_CH1 PORTA.F0 #define SW_CH2 PORTA.F1 #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_TIME 5 #define ACK 1 #define NO_ACK 0 //********************************************************************** 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() { Delay_ms(DELAY_TIME); } //********************************************************************** void EEPROM_24C64_Init() { Soft_I2C_Config(&PORTB, 6, 7); //SDA=3 SCL=2 } //********************************************************************** unsigned short EEPROM_24C64_Read(unsigned int addr) { unsigned short tmp; // Soft_I2C_Start(); Soft_I2C_Write(0xA0); Soft_I2C_Write((addr >> 8) & 0xFF); Soft_I2C_Write(addr & 0xFF); Soft_I2C_Start(); Soft_I2C_Write(0xA1); tmp = Soft_I2C_Read(NO_ACK); //not acknowledge Soft_I2C_Stop(); return (tmp); } //********************************************************************** void EEPROM_24C64_Write(unsigned int addr, unsigned short dat) { unsigned short cnt; // Soft_I2C_Start(); Soft_I2C_Write(0xA0); Soft_I2C_Write((addr >> 8) & 0xFF); Soft_I2C_Write(addr & 0xFF); Soft_I2C_Write(dat); Soft_I2C_Stop(); Delay_ms(5); } //********************************************************************** void recProc() { static unsigned int cnt1, addr_offset; static unsigned short cnt2, tmp; // if ((SW_CH1 == 1) && (SW_CH2 == 1)) { addr_offset = 0; } if ((SW_CH1 == 0) && (SW_CH2 == 1)) { addr_offset = 2048; } if ((SW_CH1 == 1) && (SW_CH2 == 0)) { addr_offset = 2048 * 2; } if ((SW_CH1 == 0) && (SW_CH2 == 0)) { addr_offset = 2048 * 3; } // LED_REC = 1; for (cnt1 = 0; cnt1 < 2048; 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_24C64_Write(addr_offset + cnt1, tmp); Delay_ex(); // if (SW_REC == 0) break; } LED_REC = 0; Pwm_Stop(); LED_OUTPUT = 0; CW_OUTPUT = 0; } //********************************************************************** void playProc() { static unsigned int cnt1, addr_offset; static unsigned short cnt2, tmp; // if ((SW_CH1 == 1) && (SW_CH2 == 1)) { addr_offset = 0; } if ((SW_CH1 == 0) && (SW_CH2 == 1)) { addr_offset = 2048; } if ((SW_CH1 == 1) && (SW_CH2 == 0)) { addr_offset = 2048 * 2; } if ((SW_CH1 == 0) && (SW_CH2 == 0)) { addr_offset = 2048 * 3; } // LED_PLAY = 1; for (cnt1 = 0; cnt1 < 2048; cnt1++) { tmp = EEPROM_24C64_Read(addr_offset + 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(); } // if (SW_PLAY == 0) break; } 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変換は使用しない。 // EEPROM_24C64_Init(); //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) { while (Button(&PORTA, 2, 1, 1) == 0) ; // recProc(); // while (Button(&PORTA, 2, 1, 1) == 0) ; } if (SW_PLAY == 0) { while (Button(&PORTA, 3, 1, 1) == 0) ; // playProc(); // while (Button(&PORTA, 3, 1, 1) == 0) ; } } } //**********************************************************************