原创 实验3 按键+LED(测试成功)

2008-10-31 11:10 3828 8 8 分类: MCU/ 嵌入式

C程序如下:init.s程序跟前两个一样


#define rGPFCON (*(volatile unsigned *)0x56000050)
#define rGPFDAT (*(volatile unsigned *)0x56000054)
#define rGPGCON (*(volatile unsigned *)0x56000060)
#define rGPGDAT (*(volatile unsigned *)0x56000064)
#define uint32 unsigned int
#define rLED1 (1<<4)
#define rLED2 (1<<5)
#define rLED3 (1<<6)
#define rLED4 (1<<7)



#define rKEY1 (1<<3)
#define rKEY2 (1<<6)
#define rKEY3 (1<<7)
#define rKEY4 (1<<11)


#define LED1ON rGPFDAT="rGPFDAT|rLED1"
#define LED2ON rGPFDAT="rGPFDAT|rLED2"
#define LED3ON rGPFDAT="rGPFDAT|rLED3"
#define LED4ON rGPFDAT="rGPFDAT|rLED4"
#define LED1CLR rGPFDAT="rGPFDAT"&(~rLED1)
#define LED2CLR rGPFDAT="rGPFDAT"&(~rLED2)
#define LED3CLR rGPFDAT="rGPFDAT"&(~rLED3)
#define LED4CLR rGPFDAT="rGPFDAT"&(~rLED4)


#define KEY1IN rGPGDAT&rKEY1
#define KEY2IN rGPGDAT&rKEY2
#define KEY3IN rGPGDAT&rKEY3
#define KEY4IN rGPGDAT&rKEY4


int main()
{rGPFCON=(rGPFCON&0x00ff)|(1<<8)|(1<<10)|(1<<12)|(1<<14);


 rGPGCON=rGPGCON&((~(3<<6)|(3<<12)|(3<<14)|(3<<22)));
 while(1)
 {
 if(KEY1IN){LED1ON;}
 else{LED1CLR;}
 
 if(KEY2IN){LED2ON;}
 else{LED2CLR;}
 
 if(KEY3IN){LED3ON;}
 else{LED3CLR;}
 
 if(KEY4IN){LED4ON;}
 else{LED4CLR;}
 
 }
}


 


GPIO口输入实验的程序跟板子上的管脚对不上,书上的程序有个按键没用


书上的程序如下


#define KEY1 (1 << 3)
#define KEY2 (1 << 7)
#define KEY3 (1 << 8)
#define KEY4 (1 << 11)


实际上应该是


#define KEY1 (1 << 3)
#define KEY2 (1 << 6)
#define KEY3 (1 << 7)
#define KEY4 (1 << 11)


对应的控制寄存器也要改


 rGPGCON = rGPGCON & (~((3 << 6) | (3 << 14) | (3 << 16) | (3 << 22)));


改成


 rGPGCON = rGPGCON & (~((3 << 6) | (3 << 12) | (3 << 14) | (3 << 22)));

文章评论0条评论)

登录后参与讨论
我要评论
0
8
关闭 站长推荐上一条 /2 下一条