实验内容:实现16个按键的检测,并在LED1和LED2上显示现两位键值信息(01~16)
#include <stdio.h>
#include "register_variant.h"
#define LED_CS2 (*((volatile unsigned short int *)(0x10300000))) //LED1 and LED2
#define LED_CS3 (*((volatile unsigned short int *)(0x10400000))) //LED3 and LED4
#define KPDK_VALUE (*((volatile unsigned char *)(0x41500008))) //Direct Keypad
#define KPAS_VALUE (*((volatile unsigned char *)(0x41500020)))
void button_statusFetch(void)
{
char i,j = 0;
unsigned short int kbd_buff;
i = KPDK_VALUE ;
j = KPAS_VALUE ;
switch (i)
{
case 0x40: //key-press 1
kbd_buff=0x7940;
LED_CS2 = kbd_buff;
LED_CS3 = 0x8F8F;
break;
case 0x02: //key-press 2
kbd_buff=0x2440;
LED_CS2 = kbd_buff;
LED_CS3 = 0x8F8F;
break;
case 0x04: //key-press 3
kbd_buff=0x3040;
LED_CS2 = kbd_buff;
LED_CS3 = 0x8F8F;
break;
case 0x20: //key-press 4
kbd_buff=0x1940;
LED_CS2 = kbd_buff;
LED_CS3 = 0x8F8F;
break;
default: kbd_buff=0x8F8F; break;
}
switch (j)
{
case 0x00: //key-press 5
kbd_buff=0x1240;
LED_CS2 = kbd_buff;
LED_CS3 = 0x8F8F;
break;
case 0x01: //key-press 6
kbd_buff=0x0240;
LED_CS2 = kbd_buff;
LED_CS3 = 0x8F8F;
break;
case 0x02: //key-press 7
kbd_buff=0x7840;
LED_CS2 = kbd_buff;
LED_CS3 = 0x8F8F;
break;
case 0x05: //key-press 8
kbd_buff=0x0040;
LED_CS2 = kbd_buff;
LED_CS3 = 0x8F8F;
break;
case 0x10: //key-press 9
kbd_buff=0x1040;
LED_CS2 = kbd_buff;
LED_CS3 = 0x8F8F;
break;
case 0x11: //key-press 10
kbd_buff=0x4079;
LED_CS2 = kbd_buff;
LED_CS3 = 0x8F8F;
break;
case 0x12: //key-press 11
kbd_buff=0x7979;
LED_CS2 = kbd_buff;
LED_CS3 = 0x8F8F;
break;
case 0x15: //key-press 12
kbd_buff=0x2479;
LED_CS2 = kbd_buff;
LED_CS3 = 0x8F8F;
break;
case 0x20: //key-press 13
kbd_buff=0x3079;
LED_CS2 = kbd_buff;
LED_CS3 = 0x8F8F;
break;
case 0x21: //key-press 14
kbd_buff=0x1979;
LED_CS2 = kbd_buff;
LED_CS3 = 0x8F8F;
break;
case 0x22: //key-press 15
kbd_buff=0x1279;
LED_CS2 = kbd_buff;
LED_CS3 = 0x8F8F;
break;
case 0x25: //key-press 16
kbd_buff=0x0279;
LED_CS2 = kbd_buff;
LED_CS3 = 0x8F8F;
break;
default: kbd_buff=0x8F8F; break;
}
}
void dummyOs(void)
{
int led_sharp;
int temp=~0;
LED_CS2 = temp;
LED_CS3 = temp;
while(1)
{
led_sharp=ledShareInterval;
for(; led_sharp>0; led_sharp--)
{
button_statusFetch();
}
}
}