2016-05-14 22:19:51 +02:00
|
|
|
|
2017-01-07 21:07:10 +01:00
|
|
|
#include "addresses.h"
|
|
|
|
#include "Sound4Calc.h"
|
|
|
|
#include "syscall.h"
|
2016-05-14 22:19:51 +02:00
|
|
|
|
2017-01-07 21:07:10 +01:00
|
|
|
#include <timer.h> // add timer's fonction
|
|
|
|
#include <display.h> // add display's fonction
|
|
|
|
#include <keyboard.h>
|
|
|
|
#include <mpu.h>
|
2016-05-14 22:19:51 +02:00
|
|
|
|
|
|
|
//#define DEBUG
|
|
|
|
|
2016-05-17 19:49:11 +02:00
|
|
|
//#define PI 3.14159265358
|
2016-05-14 22:19:51 +02:00
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
2017-01-07 21:07:10 +01:00
|
|
|
//unsigned int key=0;
|
2016-05-14 22:19:51 +02:00
|
|
|
|
2017-01-07 21:07:10 +01:00
|
|
|
int sleep = 200;
|
|
|
|
//unsigned int i=0,j=0;
|
2016-05-16 13:32:58 +02:00
|
|
|
|
2016-05-14 22:19:51 +02:00
|
|
|
setup();
|
2017-01-07 21:07:10 +01:00
|
|
|
|
2016-05-14 22:19:51 +02:00
|
|
|
while(1)
|
|
|
|
{
|
2017-01-07 21:07:10 +01:00
|
|
|
//dclear();
|
|
|
|
|
|
|
|
dprint(1, 1, "%d", sleep);
|
2016-05-14 22:19:51 +02:00
|
|
|
|
2017-01-07 21:07:10 +01:00
|
|
|
// PrintMini(1, 1, itoa(sleep, str, 10), 0);
|
|
|
|
dprint(1, 10, "%d", !isSH3());
|
2016-05-14 22:19:51 +02:00
|
|
|
|
2017-01-07 21:07:10 +01:00
|
|
|
//PrintMini(1, 10, itoa(is_SH4, str, 10), 0);
|
|
|
|
// dupdate();
|
2016-05-14 22:19:51 +02:00
|
|
|
|
2017-01-07 21:07:10 +01:00
|
|
|
switch(getkey())
|
2016-05-14 22:19:51 +02:00
|
|
|
{
|
2017-01-07 21:07:10 +01:00
|
|
|
case KEY_RIGHT : sleep+=5; break;
|
|
|
|
case KEY_LEFT : sleep-=5; break;
|
|
|
|
case KEY_EXE :
|
2016-05-14 22:19:51 +02:00
|
|
|
while(Keyboard_KeyDown())
|
|
|
|
{
|
|
|
|
|
2017-01-07 21:07:10 +01:00
|
|
|
ResetPin();
|
|
|
|
timer_start(TIMER_USER, sleep, Clock_Hz, SetPin, 1000);
|
2016-05-14 22:19:51 +02:00
|
|
|
|
|
|
|
}
|
2017-01-07 21:07:10 +01:00
|
|
|
//timer_stop(1);
|
2016-05-14 22:19:51 +02:00
|
|
|
break;
|
2017-01-07 21:07:10 +01:00
|
|
|
case KEY_EXIT :
|
2016-05-14 22:19:51 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1; // this point is never reached
|
|
|
|
}
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
|
2017-01-07 21:07:10 +01:00
|
|
|
if(isSH3())
|
|
|
|
{
|
|
|
|
// 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
|
2016-05-14 22:19:51 +02:00
|
|
|
{
|
|
|
|
// SCIF2 clock on (MSTPCR0.MSTP007)
|
2016-05-16 13:32:58 +02:00
|
|
|
*(volatile unsigned int*)SH7305_MSTPCR0 &= ~0x00000080;
|
2016-05-14 22:19:51 +02:00
|
|
|
// switch off SCSMR_2.TE and SCSMR_2.RE
|
2016-05-16 13:32:58 +02:00
|
|
|
*(volatile unsigned short*)SH7305_SCSCR &= ~0x0030;
|
2016-05-14 22:19:51 +02:00
|
|
|
// SCIF2 clock off (MSTPCR0.MSTP007)
|
2016-05-16 13:32:58 +02:00
|
|
|
*(volatile unsigned int*)SH7305_MSTPCR0 |= 0x00000080;
|
2016-05-14 22:19:51 +02:00
|
|
|
|
|
|
|
// set bit 3 of port U to output mode
|
2016-05-16 13:32:58 +02:00
|
|
|
*(volatile unsigned short*)SH7305_PUCR = ( *(volatile unsigned short*)SH7305_PUCR & ~0x00C0 ) | 0x0040;
|
2016-05-14 22:19:51 +02:00
|
|
|
// set bit 4 and 5 of port U
|
2016-05-16 13:32:58 +02:00
|
|
|
*(volatile unsigned char*)SH7305_PUDR |= 0x0C;
|
2016-05-14 22:19:51 +02:00
|
|
|
|
|
|
|
// set port J bit 2 to output mode
|
2016-05-16 13:32:58 +02:00
|
|
|
*(volatile unsigned short*)SH7305_PJCR = ( *(volatile unsigned short*)SH7305_PJCR & ~0x0030 ) | 0x0010;
|
2016-05-14 22:19:51 +02:00
|
|
|
// set port J bit 3 to output mode
|
2016-05-16 13:32:58 +02:00
|
|
|
*(volatile unsigned short*)SH7305_PJCR = ( *(volatile unsigned short*)SH7305_PJCR & ~0x00C0 ) | 0x0040;
|
2016-05-14 22:19:51 +02:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
// 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;*/
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetPin()
|
|
|
|
{
|
2017-01-07 21:07:10 +01:00
|
|
|
if(isSH3())
|
2016-05-14 22:19:51 +02:00
|
|
|
{
|
2017-01-07 21:07:10 +01:00
|
|
|
*(volatile unsigned char*)SH7337_SCPDR |= 0x01;
|
|
|
|
|
2016-05-14 22:19:51 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-07 21:07:10 +01:00
|
|
|
*(volatile unsigned char*)SH7305_PJDR |= 0x04;
|
|
|
|
//*(volatile unsigned char*)SH7305_PJDR &= ~0x08;
|
|
|
|
//set pin to 0x4B
|
2016-05-14 22:19:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResetPin()
|
|
|
|
{
|
2017-01-07 21:07:10 +01:00
|
|
|
if(isSH3())
|
2016-05-14 22:19:51 +02:00
|
|
|
{
|
2017-01-07 21:07:10 +01:00
|
|
|
*(volatile unsigned char*)SH7337_SCPDR &= ~0x01;
|
2016-05-14 22:19:51 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-07 21:07:10 +01:00
|
|
|
*(volatile unsigned char*)SH7305_PJDR &= ~0x04;
|
|
|
|
//*(volatile unsigned char*)SH7305_PJDR |= 0x08;
|
|
|
|
// set the pin to 0x47
|
2016-05-14 22:19:51 +02:00
|
|
|
}
|
2017-01-07 21:07:10 +01:00
|
|
|
}
|