u-boot-2014.10 5th day----LED, button, and beep bare metal programs

Source: Internet
Author: User

Today wrote a simple key key to drive the LED and Beep buzzer program, the source code is as follows:

/* Copyright (C) fulinux <[email protected]> * * #define GPFCON (* (unsigned long volatile *) 0x56000050) #d Efine Gpfdat (* (unsigned long volatile *) 0x56000054) #define GPFUP (* (unsigned long volatile *) 0x56000058) #define GPBC On (* (unsigned long volatile *) 0x56000010) #define GPBDAT (* (unsigned long volatile *) 0x56000014) #define GPBUP (* (UN Signed Long volatile *) 0x56000018) #define LED0 5/*led0 use gpb5*/#define LED1 6/*led1 use gpb6*/#define LE D2 7/*led2 Use gpb7*/#define LED3 8/*led3 use gpb8*/#define BEEP 0/*buzzer US GPB0 */#define D         Elay_time 40000000static inline void delay (unsigned long loops) {__asm__ volatile ("1:\n" "Subs%0,%1, #1 \ n" "BNE 1b": "=r" (Loops): "0" (loops));}    void Key_init (void) {/* Set GPF0,GPF1,GPF2,GPF4 as GPIO input mode (XX) */Gpfcon &= ~0x33f;    /* Enable pullup resister */gpfup &= ~0x17; /* Set GPF0,GPF1,GPF2,GPF4 as High level */Gpfdat |= 0x17;} VOID Led_init (void) {/* Set Gpb5,gpb6,gpb7,gpb8 as GPIO output mode */Gpbcon = (Gpbcon & ~0x3fc00) | 0x154    00;    Gpbup &= ~0x01e0; /* Set Gpb5,gpb6,gpb7,gpb8 as high level, to turn led0,led1,led2,led3 off */Gpbdat |= 0x01e0;}               void Beep_init (void) {Gpbcon = (gpbcon|0x3) &0x1;/* Set GPB0 as GPIO output mode (0x01) */Gpbup &= to; /* Enable pullup resister */}void led_off (void) {/* Set Gpb5,gpb6,gpb7,gpb8 as high level, to turn led0,led1,    LED2,LED3 off */Gpbdat |= 0x01e0; Delay (delay_time);}    int main (void) {beep_init ();    Key_init ();    Led_init ();    Led_off ();  while (1) {Gpbdat &= ~ (1<<beep);        /* Set Beep GPIO as low level */while ((Gpfdat & 0x17) = = 0x17) {delay (delay_time);        } gpbdat ^= (0x0f<<led0);  Gpbdat &= ~ (1<<beep);        /* Set Beep GPIO as Low level */delay (delay_time);     Gpbdat |= 1<<beep; /* Set Beep GPIO as HiGH level */delay (delay_time); }}

Other files are similar to those in the previous days.


u-boot-2014.10 5th day----LED, button, and beep bare metal programs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.