Chinaunix首页 | 论坛 | 博客
  • 博客访问: 104680
  • 博文数量: 11
  • 博客积分: 2520
  • 博客等级: 少校
  • 技术积分: 172
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-17 09:26
文章分类
文章存档

2009年(11)

我的朋友

分类:

2009-05-25 07:51:01

上图可以看出我们要设置的GPF是4、5、6、7
由于LED原理图可以看出只要GPF相应位置0,LED便点亮。
所以将它们设置成输出。
代码如下:
 

  1 /*********************************************
  2 *name:head.S
  3 *step1 , jump to C code
  4 *booktree.zhou@gmail.com
  5 *********************************************/
  6 .section .text
  7 .global _start
  8 _start:
  9
 10 @turn off the watchdog timer.
 11 ldr r0, =0x53000000
 12 mov r1, #0x0
 13 str r1, [r0]
 14
 15 @setup stack for C code
 16 ldr sp, = 4096
 17
 18 @jump to the C code start_main
 19 bl start_main
 20
 21 @infinite loop
 22 1: b 1b

 

1 /*
  2 *booktree.zhou@gmail.com
  3 */

  4 #include "s3c2440.h"
  5
  6 #define GPF4_out (1<<(4*2))
  7 #define GPF5_out (1<<(5*2))
  8 #define GPF6_out (1<<(6*2))
  9 #define GPF7_out (1<<(7*2))
 10
 11 static inline void delay(unsigned long loops)
 12 {
 13 __asm__ __volatile__(
 14 "1:\n"
 15 "subs %0, %1, #1\n"
 16 "bne 1b"
 17 :"=r"(loops)
 18 :"0"(loops)
 19 );
 20 }
 21
 22 void start_main(void)
 23 {
 24 unsigned int i = 0;
 25 S3C2440_GPIO * const gpio = S3C2440_GetBase_GPIO();
 26
 27 /*set led corresponding gpio output*/
 28 gpio->GPFCON = GPF4_out | GPF5_out | GPF6_out | GPF7_out;
 29
 30 while(1)
 31 {
 32 delay(300000);
 33 gpio->GPFDAT = (~(i<<5));
 34 if(++i == 16)
 35 i = 0;
 36 }

 37 }

 

1 /*
  2 *name:s3c2440.h
  3 *version 0.1
  4 *based on S3C2440A's datasheet
  5 *modified from u-boot
  6 *include/s3c24x0.h
  7 *include/s3c2410.h
  8 *booktree.zhou@gmail.com
  9 */

 10 #ifndef _S3C2440_H
 11 #define _S3C2440_H
 12
 13 #define S3C2440_GPIO_BASE 0x56000000
 14
 15 typedef volatile unsigned char S3C2440_REG8;
 16 typedef volatile unsigned short S3C2440_REG16;
 17 typedef volatile unsigned int S3C2440_REG32;
 18
 19 typedef struct {
 20 S3C2440_REG32 GPACON;
 21 S3C2440_REG32 GPADAT;
 22 S3C2440_REG32 res1[2];
 23 S3C2440_REG32 GPBCON;
 24 S3C2440_REG32 GPBDAT;
 25 S3C2440_REG32 GPBUP;
 26 S3C2440_REG32 res2;
 27 S3C2440_REG32 GPCCON;
 28 S3C2440_REG32 GPCDAT;
 29 S3C2440_REG32 GPCUP;
 30 S3C2440_REG32 res3;
 31 S3C2440_REG32 GPDCON;
 32 S3C2440_REG32 GPDDAT;
 33 S3C2440_REG32 GPDUP;
 34 S3C2440_REG32 res4;
 35 S3C2440_REG32 GPECON;
 36 S3C2440_REG32 GPEDAT;
 37 S3C2440_REG32 GPEUP;
 38 S3C2440_REG32 res5;
 39 S3C2440_REG32 GPFCON;
 40 S3C2440_REG32 GPFDAT;
 41 S3C2440_REG32 GPFUP;
 42 S3C2440_REG32 res6;
 43 S3C2440_REG32 GPGCON;
 44 S3C2440_REG32 GPGDAT;
 45 S3C2440_REG32 GPGUP;
 46 S3C2440_REG32 res7;
 47 S3C2440_REG32 GPHCON;
 48 S3C2440_REG32 GPHDAT;
 49 S3C2440_REG32 GPHUP;
 50 S3C2440_REG32 res8;
 51 S3C2440_REG32 GPJCON;
 52 S3C2440_REG32 GPJDAT;
 53 S3C2440_REG32 GPJUP;
 54 S3C2440_REG32 res9;
 55 S3C2440_REG32 MISCCR;
 56 S3C2440_REG32 EXTINT0;
 57 S3C2440_REG32 EXTINT1;
 58 S3C2440_REG32 EXTINT2;
 59 S3C2440_REG32 EINTFLT0;
 60 S3C2440_REG32 EINTFLT1;
 61 S3C2440_REG32 EINTFLT2;
 62 S3C2440_REG32 EINTFLT3;
 63 S3C2440_REG32 EINTMASK;
 64 S3C2440_REG32 EINTPEND;
 65 S3C2440_REG32 GSTATUS1;
 66 S3C2440_REG32 GSTATUS2;
 67 S3C2440_REG32 GSTATUS3;
 68 S3C2440_REG32 GSTATUS4;
 69 S3C2440_REG32 res10[3];
 70 S3C2440_REG32 MSLCON;
 71 }/*__attribute__((__packed__))*/S3C2440_GPIO;
 72
 73 static inline S3C2440_GPIO * S3C2440_GetBase_GPIO(void)
 74 {
 75 return (S3C2440_GPIO *const)S3C2440_GPIO_BASE;
 76 }
 77
 78 #endif

阅读(2762) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~