📄 main1.c
字号:
//UART1_REC INT couldn't work when using mouse
//So I use timer1 int for every 8.3ms. During timer int, I check the UART1_REC
typedef unsigned int dword;
typedef unsigned short word;
typedef unsigned char byte;
extern byte *regb;
#define regw *(word*)®b
#define regl *(int *)®b
//#define SW_KEY *(volatile unsigned short int*)(0x0120000a) //VG2
#define SW_KEY *(volatile unsigned short int*)(0x0150000a) //AMA
unsigned int _TIMER_VAR=0;
unsigned char timer_tick=0;
short light_pen_x;
short light_pen_y;
short key_left_press =0;
short key_right_press =0;
unsigned char mouse_databuf[3];
short mouse_rec_number;
unsigned char c0,c1,c2;
int mouse_sn=0;
short x_position =100;
short y_position =100;
#define MOUSE_RATIO 1
char x_count;
char y_count;
short Mouse_change = 0;
short Key_pressed = 0;
short Key_released =0;
void ReceiveCmd(void);
/////////////////////////////////////////
void UartConfig1(void)
{
regw[0x1020]=0x111; // uclk,8bit data
regw[0x1030]=95; // 1843200/((16*(95+1)) = 1200
}
short RxFul1(void)
{
if((regw[0x1024]) & 0x0010)
return 1;
else
return 0;
}
char Rx1(void)
{
return regb[0x102c];
}
void RX1_int_enable(void)
{
regb[0x0c05]=1; //interrupt vector high 3bit
asm("set 12 ; "); //set_vectored
asm("set 13 ; "); //int enable
regl[0x0c08] |= 0x00020000; //release mask
}
#define MOUSE_X_MAX 790 /*610 790*/
#define MOUSE_Y_MAX 505 /*450 505*/
//#pragma interrupt
void TIMER1()
{
timer_tick++; //global time
if(timer_tick>=12)
{ // 8.3ms* 12 = 0.1S
_TIMER_VAR ++;
timer_tick=0;
}
if((0 == mouse_sn )&& RxFul1())
{
c0 = (regb[0x102c]) &0x7f;
if(c0 & 0x40)
{
mouse_sn = 1;
}
}
if((1 == mouse_sn )&& RxFul1())
{
c1 = (regb[0x102c]) &0x7f;
if(0 == (c1 & 0x40))
{
mouse_sn = 2;
}
else
{
mouse_sn = 1;
c0 = c1;
}
}
if((2 == mouse_sn )&& RxFul1())
{
c2 = (regb[0x102c]) &0x7f;
if(0 == (c2 & 0x40))
{
mouse_sn = 3;
}
else
{
mouse_sn = 1;
c0 = c2;
}
}
if(3 == mouse_sn)
{
//do some process
key_left_press = c0 &0x20;
key_right_press = c0 &0x10;
if(key_left_press)
{
Key_pressed = 1;
// if(Key_released)
// Key_released = 0;
}
else if(Key_pressed)
{
Key_released =1;
}
else
{
Key_released =0;
}
x_count = ( (c0 & 0x03)<<6) | ((c1 & 0x3f));
y_count = ( (c0 & 0x0c)<<4) | ((c2 & 0x3f));
x_position = x_position + ((short) x_count) * MOUSE_RATIO;
y_position = y_position + ((short) y_count) * MOUSE_RATIO;
if(x_position<0)
x_position = 0;
else if(x_position>(MOUSE_X_MAX))
x_position = (MOUSE_X_MAX);
if(y_position<0)
y_position = 0;
else if(y_position>MOUSE_Y_MAX)
y_position = MOUSE_Y_MAX;
Mouse_change = 1;
mouse_sn = 0; //reset
}
regb[0x0c04]=1;
}
/*
#pragma interrupt
void VSP()
{
timer_tick++; //global time
if(timer_tick>=12)
{ // 8.3ms* 12 = 0.1S
_TIMER_VAR ++;
timer_tick=0;
}
if((0 == mouse_sn )&& RxFul1())
{
c0 = (regb[0x102c]) &0x7f;
if(c0 & 0x40)
{
mouse_sn = 1;
}
}
if((1 == mouse_sn )&& RxFul1())
{
c1 = (regb[0x102c]) &0x7f;
if(0 == (c1 & 0x40))
{
mouse_sn = 2;
}
else
{
mouse_sn = 1;
c0 = c1;
}
}
if((2 == mouse_sn )&& RxFul1())
{
c2 = (regb[0x102c]) &0x7f;
if(0 == (c2 & 0x40))
{
mouse_sn = 3;
}
else
{
mouse_sn = 1;
c0 = c2;
}
}
if(3 == mouse_sn)
{
//do some process
key_left_press = c0 &0x20;
key_right_press = c0 &0x10;
if(key_left_press)
{
Key_pressed = 1;
// if(Key_released)
// Key_released = 0;
}
else if(Key_pressed)
{
Key_released =1;
}
else
{
Key_released =0;
}
x_count = ( (c0 & 0x03)<<6) | ((c1 & 0x3f));
y_count = ( (c0 & 0x0c)<<4) | ((c2 & 0x3f));
x_position = x_position + ((short) x_count) * MOUSE_RATIO;
y_position = y_position + ((short) y_count) * MOUSE_RATIO;
if(x_position<0)
x_position = 0;
else if(x_position>(MOUSE_X_MAX))
x_position = (MOUSE_X_MAX);
if(y_position<0)
y_position = 0;
else if(y_position>MOUSE_Y_MAX)
y_position = MOUSE_Y_MAX;
Mouse_change = 1;
mouse_sn = 0; //reset
}
regb[0x0c04]=24;
}
*/
void timer_int_enable(void) //only timer test
{
regb[0x0c05]=1; //interrupt vector high 3bit
// regw[0x0c00]= 0x0DFDF; //eirq5 low level trigger//0xffff; //eirq mode = rise edge
// regw[0x1400]=0xff03; regw[0x1404]=0x2fde; //timer0 => clk_div=0xff, periodic, run, compare=0x2fde, 1/12s@37.5Mhz
//timer1 => clk_div=0xff, periodic, run, compare=0x57d,for 8.3ms@43M, =0x65B @50M
regw[0x1408]=0xff03; regw[0x140c]=0x057D;
//regw[0x1410]=0xff03; regw[0x1414]=0x0344; //timer2 => clk_div=0xff, periodic, run, compare=0xffff
//regw[0x1418]=0xff03; regw[0x141c]=0x0488; //timer3 => clk_div=0xff, periodic, run, compare=0xffff
asm("set 12 ; "); //set_vectored
asm("set 13 ; "); //int enable
//asm("clr 14 ; ");
//regl[0x0c08]=0x01000000; //enable VSP
regl[0x0c08]=0x00000002; // T1 interrupt and EXT_int5
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -