📄 main.c
字号:
/****************************************Copyright (c)**************************************************
** Guangzou ZLG-MCU Development Co.,LTD.
** graduate school
** http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name: main.c
** Last modified Date: 2004-09-16
** Last Version: 1.0
** Descriptions: The main() function example template
**
**------------------------------------------------------------------------------------------------------
** Created by: Chenmingji
** Created date: 2004-09-16
** Version: 1.0
** Descriptions: The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by: Chenxibing
** Modified date: 2005-01-18
** Version:
** Descriptions: 定时器1捕获实验。
**
********************************************************************************************************/
#include "config.h"
const uint32 LED1 = 1 << 18; /* P1.18控制LED1,低电平点亮 */
/*
*********************************************************************************************************
** 函数名称 :delay()
** 函数功能 :短软件延时
** 入口参数 :dly 延时参数,值越大,延时越久
** 出口参数 :无
*********************************************************************************************************
*/
void delay(uint32 dly)
{
uint32 i;
for ( ; dly>0; dly--)
for (i=0; i<10; i++);
}
/*
*********************************************************************************************************
** 函数名称 :main()
** 函数功能 :使用定时器1捕获按键定时,控制LED1闪烁。
** 调试说明 :需要将跳线JP12连接LED1。
*********************************************************************************************************
*/
int main (void)
{
volatile uint32 i;
PINSEL1 = 1 << 2; // P0.17连接捕获1.2
IO1DIR = LED1; // 设置LED1控制口为输出
T1PR = 99;
T1CCR = 1 << 7; // 设置CAP1.2下降沿捕获
T1TC = 0;
T1TCR = 0x01; // 启动定时器
while (1)
{
i = T1CR2; // 读取捕获到的T1TC值,用作延时参数
IO1CLR = LED1;
delay(i);
IO1SET = LED1;
delay(i);
}
return 0;
}
/*********************************************************************************************************
** End Of File
********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -