u-boot-2014.10移植第5天----LED、button和beep裸机程序
来源:互联网 发布:彩票平台源码 编辑:程序博客网 时间:2024/04/26 18:23
今天写了一个简单的key按键驱动LED和beep蜂鸣器的程序,源码如下:
/* * Copyright 2014(C) fulinux <fulinux@sina.com> */#define GPFCON (*(unsigned long volatile *)0x56000050)#define GPFDAT (*(unsigned long volatile *)0x56000054)#define GPFUP (*(unsigned long volatile *)0x56000058)#define GPBCON (*(unsigned long volatile *)0x56000010)#define GPBDAT (*(unsigned long volatile *)0x56000014)#define GPBUP (*(unsigned long volatile *)0x56000018)#define LED0 5 /*LED0 use GPB5*/#define LED1 6 /*LED1 use GPB6*/#define LED2 7 /*LED2 use GPB7*/#define LED3 8 /*LED3 use GPB8*/#define BEEP 0 /*Buzzer us GPB0 */#define DELAY_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(00) */ 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(01) */ GPBCON = (GPBCON & ~0x3FC00) | 0x15400; 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 &= ~1; /* 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); }}
其他文件与前几天中的内容类似。
0 0
- u-boot-2014.10移植第5天----LED、button和beep裸机程序
- u-boot-2014.10移植第3天----LED裸机程序
- u-boot-2014.10移植第4天----裸机蜂鸣器程序
- u-boot移植总结(二)LED点灯调试 和 u-boot加载地址
- u-boot-2014.10移植第13天----创建开发板
- u-boot-2014.10移植第15天----nor flash操作
- u-boot-2014.10移植第16天----Nor flash启动
- u-boot-2014.10移植第1天----熟悉u-boot(一)
- u-boot-2014.10移植第2天----熟悉u-boot(二)
- ok6410-第06篇-裸机led程序
- mini2440裸机程序测试第一部-LED
- u-boot-2014.10移植
- 第三十三天:Tiny4412驱动开发之LED驱动和u-boot移植
- LED裸机程序(IAR)
- mini2440裸机程序LED
- OK6410裸机程序 ----led
- u-boot-2014.10移植第6天----深入分析代码(一)
- u-boot-2014.10移植第7天----深入分析代码(二)
- 动态计算行高
- Leetcode: Find Minimum in Rotated Sorted Array
- 黑马程序员——java中的反射
- VC中判断定时器是否已经开启的办法
- SOJ--Zig-Zag
- u-boot-2014.10移植第5天----LED、button和beep裸机程序
- 创建站点自助服务(Self-Service Site Creation)
- JFreeChart 使用一 直方图之简单柱状图
- springmvc基本配置及相关源码解读
- 黑马程序员---C语言预处理
- boost::asio started guide 翻译1
- PAT 1007. Maximum Subsequence Sum (25)
- Leetcode: Find Minimum in Rotated Sorted Array II
- JFreeChart 使用 一 直方图之柱状图-高级特性