C语言版本LED驱动实验 - 程序编写与验证

1. mian.c 

#include "main.h"

/*enable peripheral clock*/
void clock_enable(void)
{
    CCM_CCGR1 = 0xFFFFFFFF;
    CCM_CCGR2 = 0xFFFFFFFF;
    CCM_CCGR3 = 0xFFFFFFFF;
    CCM_CCGR4 = 0xFFFFFFFF;
    CCM_CCGR5 = 0xFFFFFFFF;
    CCM_CCGR6 = 0xFFFFFFFF;
}

/*initialize LED*/
void led_init(void)
{
    SW_MUX_GPIO1_IO03 = 0x5;  /*set to GPIO1_IO03*/
    SW_PAD_GPIO1_IO03 = 0x10b0; /*set  GPIO1_IO03 electrical parameters */

    /*GPIO initialize*/
    GPIO1_GDIR = 0x8;  /*set bit3 output*/
    GPIO1_DR = 0x0;    /*by default, led power on*/    
}

void main(void)
{
    clk_enable();   /*enale peripheral clk*/
    led_init();     /*initialize LED*/
    while(1);
}

2. main.h

#ifndef __MAIN.H
#define __MAIN.H

/*define all registers*/
#define CCM_CCGR0 *((volatile unsigned int *)0x020c4068)
#define CCM_CCGR1 *((volatile unsigned int *)0x020c406c)
#define CCM_CCGR2 *((volatile unsigned int 

你可能感兴趣的:(ARM)