diff --git a/include/main.h b/include/main.h index 5c3fddd..e3c1cdc 100644 --- a/include/main.h +++ b/include/main.h @@ -1,6 +1,7 @@ #ifndef _MAIN #define _MAIN + void lect(); #endif diff --git a/include/sound4calc.h b/include/sound4calc.h index dee04af..41e5198 100644 --- a/include/sound4calc.h +++ b/include/sound4calc.h @@ -18,7 +18,8 @@ #define SH7337_PGDR 0xA400012C #define SH7337_SCPDR 0xA4000136 -void SwitchPinState(char level); + +void PutPinState(char level); void PlayNote(); void InitPorts(); diff --git a/src/main.c b/src/main.c index 8d1ddcd..11e6be5 100644 --- a/src/main.c +++ b/src/main.c @@ -13,7 +13,7 @@ unsigned char range = 0; void lect() { - SwitchPinState(bincod[range]=='-'); + PutPinState(bincod[range]=='-'); range++; if(!(bincod[range])) range=0; } diff --git a/src/sound4calc.c b/src/sound4calc.c index 47966a0..e15cfd1 100644 --- a/src/sound4calc.c +++ b/src/sound4calc.c @@ -2,13 +2,58 @@ #include // from Gint #include //from Gint -unsigned char* signal = {"----_____"}; +char* signal = "-_"; // simple waveform +short Seq_signal[6] = {440,500,392,500,349,500}; // sequence signal + + +void PlaySequence() +{ +static int length_end = 0; +static int note = 0; + +if(length_end<=0) + { + note+=2; + + if(!Seq_signal[note]) + { + timer_stop(TIMER_USER); + return; + } + + length_end = Seq_signal[note+1]; + + timer_start(TIMER_USER, Seq_signal[note], Clock_Hz, PlaySequence, Seq_signal[note+1]); + } + +PlayNote(); +length_end--; +} /* - SwitchPinState() - put the pin at the level + PlayNote() + allow to make different waveforms with '-' and '_' */ -void SwitchPinState(char level) +void PlayNote() +{ +static int x = 0; +PutPinState(signal[x]=='-'); +x = x + 1; +if(!(signal[x])) x = 0; +} + +/* + PutPinState() + put the pin at the level wanted + + SH4 : + state 0 : xxxx.01xx + state 1 : xxxx.10xx + SH3 : + state 0 : xxxx.xxx0 + state 1 : xxxx.xxx1 +*/ +void PutPinState(char level) { level = !!level; @@ -22,28 +67,18 @@ else } } -/* - PlayNote() - allow to make different waveforms with '-' and '_' -*/ -void PlayNote() -{ -static x = 0; -SwitchPinState(signal[x]=='-'); -x = x + 1; -if(!(signal[x])) x = 0; -} /* InitPorts(); - Init ports to output + Ports initialisation + Open all need ports to use SwitchPinState() */ void InitPorts() { if(isSH3()) { // initialisation of pin - *(volatile unsigned char*)SH7337_SCPDR |= 0x01; +// *(volatile unsigned char*)SH7337_SCPDR |= 0x01; // SCIF2 clock on (STBCR3.MSTP31) *(volatile unsigned char*)SH7337_STBCR3 &= ~0x02; @@ -61,7 +96,7 @@ if(isSH3()) else { // initialisation of pin - *(volatile unsigned char*)SH7305_PJDR |= 0x04; +// *(volatile unsigned char*)SH7305_PJDR |= 0x04; // SCIF2 clock on (MSTPCR0.MSTP007) *(volatile unsigned int*)SH7305_MSTPCR0 &= ~0x00000080; @@ -69,20 +104,20 @@ else *(volatile unsigned short*)SH7305_SCSCR &= ~0x0030; // SCIF2 clock off (MSTPCR0.MSTP007) *(volatile unsigned int*)SH7305_MSTPCR0 |= 0x00000080; - // set bit 3 of port U to output mode *(volatile unsigned short*)SH7305_PUCR = ( *(volatile unsigned short*)SH7305_PUCR & ~0x00C0 ) | 0x0040; // set bit 4 and 5 of port U *(volatile unsigned char*)SH7305_PUDR |= 0x0C; +// set port J bit 2 to output + *(unsigned short*)0xA4050110 = ( *(unsigned short*)0xA4050110 & ~0x0030 ) | 0x0010; +// set port J bit 3 to input + *(unsigned short*)0xA4050110 = ( *(unsigned short*)0xA4050110 & ~0x00C0 ) | 0x0080; +/* // set port J bit 2 to output mode *(volatile unsigned short*)SH7305_PJCR = ( *(volatile unsigned short*)SH7305_PJCR & ~0x0030 ) | 0x0010; // set port J bit 3 to output mode *(volatile unsigned short*)SH7305_PJCR = ( *(volatile unsigned short*)SH7305_PJCR & ~0x00C0 ) | 0x0040; +*/ } - /* - // set port J bit 2 to output - *(unsigned short*)0xA4050110 = ( *(unsigned short*)0xA4050110 & ~0x0030 ) | 0x0010; - // set port J bit 3 to input - *(unsigned short*)0xA4050110 = ( *(unsigned short*)0xA4050110 & ~0x00C0 ) | 0x0080;*/ }