|||
#include<s3c2440.h> //包含S3C2440寄存器地址设置的头文件
#define uchar unsigned char
#define uint unsigned int
#define S_key1_in 1 //key1使用GPG0
#define S_key2_in (1<<6) //KEY2使用GPG3
#define S_key3_in (1<<10) //KEY2使用GPG5
#define S_key4_in (1<<12) //KEY2使用GPG6
#define S_key5_in (1<<14) //KEY2使用GPG7
#define S_key6_in (1<<22) //KEY2使用GPG11
#define S_key1 1 //KEY2使用GPG0
#define S_key2 (1<<3) //KEY2使用GPG3
#define S_key3 (1<<5) //KEY2使用GPG5
#define S_key4 (1<<6) //KEY2使用GPG6
#define S_key5 (1<<7) //KEY2使用GPG7
#define S_key6 (1<<11) //KEY2使用GPG11
#define S_led1_out (1<<10) //GPB5
#define S_led2_out (1<<12) //GPB6
#define S_led3_out (1<<14) //GPB7
#define S_led4_out (1<<16) //GPB7
#define L_led1_out (1<<5) //GPB5
#define L_led2_out (1<<6) //GPB6
#define L_led3_out (1<<7) //GPB7
#define L_led4_out (1<<8) //GPB7
int main(void)
{
GPGCON&=~(S_key1_in|S_key2_in|S_key3_in|S_key4_in|S_key5_in|S_key6_in); //相应的KEY的端口设置为输入口
GPBUP&=~(S_key1|S_key2|S_key3|S_key4|S_key5|S_key6); //由于KEY上没有加上拉电阻,所以设置上拉。
GPBCON|=S_led1_out|S_led2_out|S_led3_out|S_led4_out ; //对应的LED口设置为输出口
GPBDAT|=(1<<5)|(1<<6)|(1<<7)|(1<<8); //LED1-4全灭
while(1)
{
if((GPGDAT&S_key1)==0) //KEY1响应
{
GPBDAT|=L_led1_out|L_led2_out|L_led3_out|L_led4_out; //LED1-4全灭
GPBDAT&=~L_led1_out; //led1输出0点亮led1
}
if((GPGDAT&S_key2)==0) //KEY2响应
{
GPBDAT|=L_led1_out|L_led2_out|L_led3_out|L_led4_out; //LED1-4全灭
GPBDAT&=~L_led2_out; //led1输出0点亮led2
}
if((GPGDAT&S_key3)==0) //KEY3响应
{
GPBDAT|=L_led1_out|L_led2_out|L_led3_out|L_led4_out; //LED1-4全灭
GPBDAT&=~L_led3_out; //led1输出0点亮led2
}
if((GPGDAT&S_key4)==0) //KEY4响应
{
GPBDAT|=L_led1_out|L_led2_out|L_led3_out|L_led4_out; //LED1-4全灭
GPBDAT&=~L_led4_out; //led1输出0点亮led3
}
if((GPGDAT&S_key5)==0) //KEY5响应
{
GPBDAT|=L_led1_out|L_led2_out|L_led3_out|L_led4_out; //LED1-4全灭
}
if((GPGDAT&S_key6)==0) //KEY6响应
{
GPBDAT&=~(L_led1_out|L_led2_out|L_led3_out|L_led4_out); //LED1-4全亮
}
}
}