歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

TQ2440 查詢法實現按鍵LED的功能

以下是TQ2440裸奔按鍵LED功能的程序

init.s

    AREA init, CODE, READONLY
 
start        LDR SP,=4096
            import main
            bl main
            end

def.h

#ifndef __DEF_H__

#define GPBCON (*(volatile unsigned int*) 0x56000010)
#define GPBDAT (*(volatile unsigned int*) 0x56000014)
#define GPFCON (*(volatile unsigned int*) 0x56000050)
#define WTCON (*(volatile unsigned int*) 0x53000000)
#define GPFDAT (*(volatile unsigned int*) 0x56000054)
#define KEY1  0x02
#define KEY2  0x10
#define KEY3  0x04
#define KEY4  0x01
#define LED1  0x1cf
#define LED2  0x1bf 
#define LED3  0x17f
#define LED4  0x0ff
#define LED_OFF 0x1ff
#endif

main.c

#include "def.h"
void delay(unsigned int a)
{
    while (a--);
}

void init()
{
    WTCON = 0;//使看門狗無效
    GPBCON &= ~((3<<2*5)|(3<<2*6)|(3<<2*7)|(3<<2*8));
    GPBCON |=  ((1<<2*5)|(1<<2*6)|(1<<2*7)|(1<<2*8));//5,6,7,8口輸出(01輸出)
    GPFCON &= ~((3<<2*0)|(3<<2*1)|(3<<2*2)|(3<<2*4));//0,1,2,4口輸入(00輸入)
}

main()
{
    init();
    while (1)
    {
       
        if (!(GPFDAT & KEY4))
        {
            delay(5000);
            while (!(GPFDAT & KEY4))
            {
                GPBDAT = LED4;
            }
        }
        else 
            GPBDAT = LED_OFF;
/***********按鍵4點亮LED4,松手LED4滅*****************/   


       
        if (!(GPFDAT & KEY1))
        {
            delay(5000);
            while (!(GPFDAT & KEY1))
            {
                GPBDAT = LED1;
            }
        }
        else 
            GPBDAT = LED_OFF;   
/***********按鍵1點亮LED1,松手LED1滅*****************/       


   
        if (!(GPFDAT & KEY2))
        {
            delay(5000);
            while (!(GPFDAT & KEY2))
            {
       
                GPBDAT = LED2;
            }
        }
        else 
            GPBDAT = LED_OFF;
/***********按鍵2點亮LED2,松手LED2滅*****************/   


           
        if (!(GPFDAT & KEY3))
        {
            delay(5000);
            while (!(GPFDAT & KEY3))
            {
                GPBDAT = LED3;
            }
        }
        else 
            GPBDAT = LED_OFF;   
/***********按鍵3點亮LED3,松手LED3滅*****************/       


           
    }
   
}

Copyright © Linux教程網 All Rights Reserved