Sound4Calc/src/Sound4Calc.c

130 lines
3.2 KiB
C
Executable File

#include "addresses.h"
#include "Sound4Calc.h"
#include <timer.h> // add timer's fonction
#include <display.h> // add display's fonction
#include <keyboard.h>
#include <mpu.h>
//#define PI 3.141592653584
unsigned char bincod[25] = {0};
unsigned char place = 0;
void lect()
{
static unsigned char range = 0;
if(bincod[range%place] != bincod[(range+1)%place])
{
if(isSH3())
{
*(volatile unsigned char*)SH7337_SCPDR ^= 0x01;
}
else
{
*(volatile unsigned char*)SH7305_PJDR ^= 0x04;
}
}
range++;
}
int main(void)
{
unsigned int key = 0;
static int freq = 440;
//unsigned int i=0;
setup();
while(1)
{
dclear();
dprint(1, 1, "%d", freq);
dprint(1, 10, "%s", bincod);
dprint(1, 20, "%d", place);
dtext(1, 50, "F1 _ F2 -");
dupdate();
key = getkey();
switch(key)
{
case KEY_RIGHT : freq+=1; break;
case KEY_LEFT : freq-=1; break;
case KEY_UP : freq+=10; break;
case KEY_DOWN : freq-=10; break;
case KEY_F1 : *(bincod+place++) = '_'; break;
case KEY_F2 : *(bincod+place++) = '-'; break;
case KEY_DEL : place=(place>0 ? place - 1 : 0); *(bincod+place) = 0; break;
case KEY_EXE :
timer_start(TIMER_USER, freq*place, Clock_Hz, lect, 2*freq*place);
break;
case KEY_EXIT :
timer_stop(TIMER_USER);
return 1;
}
}
return 1; // this point is never reached
}
void setup()
{
if(isSH3())
{
// initialisation of pin
*(volatile unsigned char*)SH7337_SCPDR |= 0x01;
// SCIF2 clock on (STBCR3.MSTP31)
*(volatile unsigned char*)SH7337_STBCR3 &= ~0x02;
// switch off SCSMR_2.TE and SCSMR_2.RE
*(volatile unsigned short*)SH7337_SCSCR2 &= ~0x0030;
// SCIF2 clock off (STBCR3.MSTP31)
*(volatile unsigned char*)SH7337_STBCR3 |= 0x02;
// set bit 6 of port G to output mode
*(volatile unsigned short*)SH7337_PGCR = ( *(volatile unsigned short*)SH7337_PGCR & ~0x3000 ) | 0x1000;
// set bit 5 and 6 of port G
*(volatile unsigned char*)SH7337_PGDR |= 0x60;
// set port SC bit 0 to output
*(volatile unsigned short*)SH7337_SCPCR = ( *(volatile unsigned short*)SH7337_SCPCR & ~0x0003 ) | 0x0001;
}
else
{
// initialisation of pin
*(volatile unsigned char*)SH7305_PJDR |= 0x04;
// SCIF2 clock on (MSTPCR0.MSTP007)
*(volatile unsigned int*)SH7305_MSTPCR0 &= ~0x00000080;
// switch off SCSMR_2.TE and SCSMR_2.RE
*(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 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;*/
}