📄 训练项目五:定时器.c
字号:
/****************************************************************************
** File Name: 定时器
** Createed By: Wangchangsong
** Create Date: 07/26/2008
** Version: 1.0
** Descriptions: led display
**
**---------------------------------------------------------------------------
** Modified By:
** Modified Date:
** Version:
** Descriptions:
**
****************************************************************************/
#include <iom128v.h>
#include <macros.h>
unsigned int count = 0;
static unsigned char led_coder[] = {0xfe,0xfd,0xfc,0xfb,0xfa,0xf9,0xf8,0xf7,0xf6,0xf5,
0xf4,0xf3,0xf2,0xf1,0xf0,0xef,0xee,0xed,0xec,0xeb,0xea,0xe9,0xe8,0xe7,0xe6,0xe5,0xe4,
0xe3,0xe2,0xe1,0xe0,0xdf,0xde,0xdd,0xdc,0xdb,0xda,0xd9,0xd8,0xd7,0xd6,0xd5,0xd4,0xd3,
0xd2,0xd1,0xd0,0xcf,0xce,0xcd,0xcc,0xcb,0xca,0xc9,0xc8,0xc7,0xc6,0xc5,0xc4};
/****************************************************************************
** Function Name: init
** Descriptions: initialization
** Input Parameters: void
** Output parameters: void
** Returned Value: void
**---------------------------------------------------------------------------
****************************************************************************/
void init() /* 初始化 */
{ SREG = 0x80; /* 状态寄存器,全局中断允许 */
DDRB = 0xFF; /* PB口作为输出口 */
TCCR1A = 0; /* 16位定时器/计数器控制寄存器A,
引脚为通用I/O口 */
TCNT1H = 0xff; /* 16位定时器/计数器的寄存器 */
TCNT1L = 0xff; /* 16位定时器/计数器的寄存器 */
TIMSK = 0x04; /* 中断屏蔽寄存器,T/C1溢出中断允许 */
TCCR1B = 0x01; /* 16位定时器/计数器控制寄存器B,
CLK/8(来自预分频器) */
}
/****************************************************************************
** Function Name: main
** Descriptions:
** Input Parameters: void
** Output parameters: void
** Returned Value: void
**---------------------------------------------------------------------------
****************************************************************************/
void main(void)
{
init();
while(1) /* 死循环 */
{
;
}
}
#pragma interrupt_handler timer:15
/* 请查阅中断向量相关资料,
程序中15为中断向量号 */
/****************************************************************************
** Function Name: timer
** Descriptions:
** Input Parameters: count
** Output parameters: void
** Returned Value: void
**---------------------------------------------------------------------------
****************************************************************************/
void timer()
{
PORTB = led_coder[count];
if(count<59)
count+=1;
else count = 0;
}
/****************************************************************************
END FILE
****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -