功用: 顺次点亮板子上的八个LED,并循环显现,每循环显现一次,蜂鸣器蜂鸣一次。
原理图:
程序清单:
/****************************************Copyright (c)**************************************************
*
**————–File Info——————————————————————————-
** File name:main.c
** Last modified Date: 2011-04-27
** Last Version:1.0
** Descriptions:The main() function example template
**——————————————————————————————————
** Created by:lxliu
** Created date:2011-04-27
** Version:1.0
** Descriptions:The original version
**——————————————————————————————————
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/
#include “config.h”
void DelayNS(uint32 dly)
{
uint32 i;
for(;dly>0;dly–)
for(i=0;i<50000;i++);
}
int main (void)
{
uint32 i; //循环变量
uint32 LED = (1<<18); //P1[25:18]操控LED,初值指向LED1
uint32 BEEP = (1<<7); //P0.7操控蜂鸣器,低电平蜂鸣器蜂鸣
PINSEL2 = PINSEL2 & (~0x08); //P1[25:16]设置为GPIO功用
PINSEL0 = 0x00000000; //P0[15:0]设置为GPIO功用
IO0DIR = BEEP; //设置BEEP操控口为输出
IO0SET = BEEP; //蜂鸣器中止蜂鸣
while(1)
{
for(i=0;i<8;i++) //8个LED
{
IO1DIR = LED; //当时的LED设置为输出
IO1SET = LED; //当时的LED平息
DelayNS(100); //延时
IO1CLR = LED; //当时的LED点亮
DelayNS(100); //延时
IO1SET = LED; //当时的LED平息
LED =(LED<<1); //左移一位,
}
IO0CLR = BEEP; //8个LED点亮一遍后,蜂鸣器蜂鸣
DelayNS(100); //延时
IO0SET = BEEP; //蜂鸣器中止蜂鸣
DelayNS(500); //延时
LED = (1<<18);//为LED赋初值
}
return 0;
}
/*********************************************************************************************************
** End Of File
********************************************************************************************************/