实验内容:
【选做】 实现数码管的计时秒表功能,低2位为毫秒级,高2位为秒级。按键1启动计时,按键2暂停计时,按键3清零。
#include "register_variant.h"
#define LED_CS2 (*((volatile unsigned short *)(0x10300000)))
#define LED_CS3 (*((volatile unsigned short *)(0x10400000)))
#define KPC (*((volatile unsigned int *)(0x41500000)))
#define KPDK_VALUE (*((volatile unsigned short *)(0x41500008)))
#define KPAS_VALUE (*((volatile unsigned short *)(0x41500020)))
#define OSCR (*(volatile unsigned long *)(osTimer_OSCR))
#define ICPR (*(volatile unsigned long *)(int_ICPR))
#define OSMR0 (*(volatile unsigned long *)(0x40a00000))
#define OSMR1 (*(volatile unsigned long *)(0x40a00004))
#define OSMR2 (*(volatile unsigned long *)(0x40a00008))
#define OSMR3 (*(volatile unsigned long *)(0x40a0000c))
#define OSSR (*(volatile unsigned long *)(0x40a00014))
#define OIER (*(volatile unsigned long *)(0x40a0001c))
#define ICMR (*(volatile unsigned long *)(0x40d00004))
int m=0;
void IRQ_Function(void)
{
int g,s,b,q,i;
int pretimer;
int a[10]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};
i=m++;
g=i%10;
i/=10;
s=i%10;
i/=10;
b=i%10;
i/=10;
q=i%10;
if(q==6&&b==0)
{ LED_CS2 = 0x4040;
m=0;
}
else
LED_CS2=(a[b]<<8)+a[q];
LED_CS3=(a[g]<<8)+a[s];
OIER = 0x1; //enable timer 0
pretimer = OSCR;
OSMR0 = pretimer + 36864;
}
void dummyOs()
{
int pretimer;
LED_CS2 = 0x4040;
LED_CS3 = 0x4040;
OIER = 0x1; //enable timer 0
pretimer = OSCR;
OSMR0 = pretimer + 36864;
ICMR=0;
m=0;
while(1)
{
char i;
i = KPDK_VALUE;
switch (i)
{
case 0x40: ICMR=0x3c000000;
break;
case 0x02: ICMR=0;
break;
case 0x04: m=0;
ICMR=0;
LED_CS2 = 0x4040;
LED_CS3 = 0x4040;
break;
default : break;
}
}
}