//看图的时候不仔细,按键顺序乱了,不好意思
#define GPFCON (*(volatile unsigned long *) 0x56000050)
#define GPFDAT (*(volatile unsigned long *) 0x56000054)
#define GPGCON (*(volatile unsigned long *) 0x56000060)
#define GPGDAT (*(volatile unsigned long *) 0x56000064)
#define GPBCON (*(volatile unsigned long *) 0x56000010)
#define GPBDAT (*(volatile unsigned long *) 0x56000014)
/*
*LED1-4 GPF4-7
*/
#define OUT_4 (1<<(4*2))
#define OUT_5 (1<<(5*2))
#define OUT_6 (1<<(6*2))
#define OUT_7 (1<<(7*2))
/*
*KEY1: GPB6 low GPF0
*KEY2: GPB6 low GPG5
*KEY3: GPB6 low GPG3
*KEY4: GPB6 low GPG11
*KEY5: GPB7 low GPF0
*KEY6: GPB7 low GPG5
*KEY7: GPB7 low GPG3
*KEY8: GPB7 low GPG11
*/
#define IN_0 ~(3<<(0*2))
#define IN_3 ~(3<<(3*2))
#define IN_5 ~(3<<(5*2))
#define IN_11 ~(3<<(11*2))
void delay()
{
int i, j;
for(i=255; i!=0; i--) {
for(j=255; j!=0; j--) {
;
}
}
}
void k1_to_k4()
{
unsigned long dwDat;
dwDat = GPFDAT;
if (dwDat & (1<<0)) {
GPFDAT |= (1<<4);
}
else {
GPFDAT &= ~(1<<4);
}
dwDat = GPGDAT;
if (dwDat & (1<<5)) {
GPFDAT |= (1<<5);
}
else {
GPFDAT &= ~(1<<5);
}
dwDat = GPGDAT;
if (dwDat & (1<<3)) {
GPFDAT |= (1<<6);
}
else {
GPFDAT &= ~(1<<6);
}
dwDat = GPGDAT;
if (dwDat & (1<<11)) {
GPFDAT |= (1<<7);
}
else {
GPFDAT &= ~(1<<7);
}
}
void k5_to_k7()
{
unsigned long dwDat;
int i;
dwDat = GPFDAT;
if (dwDat & (1<<0)) {
GPFDAT |= (1<<4);
}
else {
for (i=10; i!=0; i--) {
GPFDAT |= (1<<4);
GPFDAT &= ~(1<<4);
delay();
}
}
dwDat = GPGDAT;
if (dwDat & (1<<5)) {
GPFDAT |= (1<<5);
}
else {
for (i=10; i!=0; i--) {
GPFDAT |= (1<<5);
GPFDAT &= ~(1<<5);
delay();
}
}
dwDat = GPGDAT;
if (dwDat & (1<<3)) {
GPFDAT |= (1<<6);
}
else {
for (i=10; i!=0; i--) {
GPFDAT |= (1<<6);
GPFDAT &= ~(1<<6);
delay();
}
}
dwDat = GPGDAT;
if (dwDat & (1<<11)) {
GPFDAT |= (1<<7);
}
else {
for (i=10; i!=0; i--) {
GPFDAT |= (1<<7);
GPFDAT &= ~(1<<7);
delay();
}
}
}
int main()
{
/*
*GPB6 GPB7 GPF4-7 设为OUT
*GPF0 GPG5 GPG3 GPG11 设为IN
*/
GPFCON = OUT_4 | OUT_5 | OUT_6 | OUT_7 & IN_0;
GPBCON = OUT_6 | OUT_7;
GPGCON = IN_3 & IN_5 & IN_11;
while(1) {
GPBDAT = ~(1<<6) & (1<<7);
k1_to_k4();
GPBDAT = (1<<6) & ~(1<<7);
k5_to_k7();
}
}
https://static.assets-stash.eet-china.com/album/old-resources/2009/2/5/39a42e2b-44c2-47d3-a417-611b695f3927.rar
yannzi 2009-2-5 19:36