📄 timematch.c
字号:
#include "101c49k.h"
#include "lcd.h"
#include "TimeMatch.h"
unsigned int CurTime_10ms; /* Current 1/100sec */
unsigned int settime; /* set time */
unsigned char fTimeEnable; /* time enable flag */
unsigned char fMatchStart; /* match start flag */
unsigned char fMatchEnable; /* match enable flag */
unsigned int fTimeLCD; /* LCD : Timer flag */
void main(void)
{
asm ("\tand\t0b10111111,PSW\n"); /* Interrupt disable */
io_init(); /* initialize of CPU */
asm ("\tor\t0b01110000,PSW\n"); /* Interrupt enable, Level 3 */
lcd_init(); /* initialize of LCD */
/* LCD Startup Messages */
lcd_clear();
lcd_puts("Time Match Game", 0, 0);
fTimeEnable = 0; /* initialize of flags */
fMatchEnable = 0; /* initialize of flags */
while (1) {
disp_settime();
if( fMatchStart ){
disp_time();
while (1) {
if( fMatchEnable ){
disp_match();
wait_ms(2000); /* Finish Display Delay */
fMatchEnable = 0;
break;
}
}
fMatchStart = 0;
}
}
}
void disp_settime(void)
{
/* Get Settime */
settime = P4.IN.BYTE;
settime = (settime & 0x07) * 100;
settime += 300;
lcd_puts("TimeMatch: sec", 1, 0);
lcd_puts( Bin2Dec( settime/100 ), 1, 10);
}
void disp_time(void)
{
fMatchStart = 0;
lcd_clear();
lcd_puts("Start!", 0, 0);
lcd_puts("Now Countting...", 1, 0);
}
void disp_match(void)
{
unsigned int difftime;
fMatchEnable = 0;
lcd_clear();
lcd_puts("DiffTime : .", 0, 0);
if( settime > CurTime_10ms ){
lcd_puts("-", 0, 10);
difftime = settime - CurTime_10ms;
} else {
lcd_puts("+", 0, 10);
difftime = CurTime_10ms - settime;
}
lcd_puts( Bin2Dec( difftime/100 ), 0, 11);
lcd_puts( Bin2Dec( difftime%100 ), 0, 14);
if( difftime == 0 ){
lcd_puts(" Great !! ", 1, 0);
} else if( difftime < 10 ){
lcd_puts(" Nice !! ", 1, 0);
} else if( difftime < 30 ){
lcd_puts(" Good !! ", 1, 0);
} else if( difftime < 50 ){
lcd_puts(" Bad !! ", 1, 0);
} else if( difftime < 70 ){
lcd_puts(" Ill !! ", 1, 0);
} else {
lcd_puts(" Worst !! ", 1, 0);
}
}
void io_init(void)
{
CPUM.BYTE = 0x00; /* CPU mode = NORMAL */
CPUM.BIT.OSCSEL = 0x00; /* divide ratio = 1 */
CPUM.BIT.OSCDBL = 0x00; /* internal system clock = NORMAL */
OSCMD.BIT.SOSC2DS = 0x00; /* slow oscillator = NORMAL */
EXADV.BYTE = 0x00; /* extend address output = INHIBIT */
MEMCTR.BIT.IOW = 0x00; /* special register wait = NONE */
MEMCTR.BIT.EXMEM = 0x00; /* memory extend = NONE */
MEMCTR.BIT.EXWH = 0x01; /* wait mode = FIXED */
MEMCTR.BIT.IRWE = 0x00; /* software interrupt = Disable */
MEMCTR.BIT.EXW = 0x00; /* fixed wait value = 0 */
DLYCTR.BIT.DLYS = 0x00; /* stability period = 2^14/fs */
DLYCTR.BIT.BUZOE = 0x00; /* Buzzer output = NONE */
SBNKR.BIT.SBA = 0x00; /* source address bank selection = Bank0 */
DBNKR.BIT.DBA = 0x00; /* destination address bank selection = Bank0 */
/* SW IN */
FLOAT.BIT.P4RDWN = 0x00; /* P4 僾儖傾僢僾乛僟僂儞慖戰 = 僾儖傾僢僾 */
P4.DIR.BYTE = 0x00; /* P4 慡價僢僩 = 擖椡 */
P4.PLUD.BYTE = 0x00; /* P4 僾儖傾僢僾乛僟僂儞掞峈 = 側偟 */
/* LCD CONTROL */
P5.OUT.BYTE = 0x00; /* P5 data output */
P5.DIR.BYTE = 0xff; /* P5 all bit = OUTPUT */
P5.PLU.BYTE = 0x00; /* P5 pull up resistance = NONE */
P6.OUT.BYTE = 0x00; /* P6 data output */
P6.DIR.BYTE = 0xff; /* P6 all bit = OUTPUT */
P6.PLU.BYTE = 0x00; /* P6 pull up resistance = NONE */
/* LCD DATA */
P8.OUT.BYTE = 0x00; /* P8 data output */
P8.DIR.BYTE = 0xff; /* P8 all bit = OUTPUT */
P8.PLU.BYTE = 0x00; /* P8 pull up resistance = NONE */
/* TM1 timer for LCD (1ms/40us) */
TM1.MD.BYTE = 0x01; /* TM1 normal operation, stop, clock source = tm1psc */
TM1.CK.BYTE = 0x06; /* pre-scaler = fosc/128 */
ICR.TM1ICR.BIT.LV = 0x01; /* interrupt level = 1 */
ICR.TM1ICR.BIT.IE = 0x01; /* interrupt enable */
/* TM7 10msec Timer */
TM7.MD1.BYTE = 0x2C; /* TM7 */
TM7.MD2.BYTE = 0x28;
TM7.PR1 = 12288-1; /* compare value (pre-set1) */
ICR.TM7ICR.BIT.LV = 0x00; /* interrupt level = 0 */
ICR.TM7ICR.BIT.IE = 0x01; /* interrupt enable */
/* EXTERNAL INTERRUPT 0 */
ICR.IRQ0ICR.BIT.LV = 0x02; /* interrupt level = 2 */
ICR.IRQ0ICR.BIT.IE = 0x01; /* interrupt enable */
MEMCTR.BIT.IRWE = 0x01; /* software interrupt = Enable */
ICR.IRQ0ICR.BIT.IR = 0x00; /* interrupt request flag clear */
MEMCTR.BIT.IRWE = 0x00; /* software interrupt = Disable */
/* Etc. */
NFCTR.BYTE = 0x77; /* noise filter 0/1 = ON, sampling = fosc/2^10 */
PSCMD.BIT.PSCEN = 1; /* pre-scaler = ON */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -