c - 如何在 Atemga128 中使用 Timer/Counter2...?
问题描述
我在使用定时器/计数器 02 时遇到了麻烦,我使用 Atmega128 8 位处理器,它有 16MHz 晶体。我知道如何使用 Timer00,但我不能使用 Timer02
我了解到计时器 00 和 02 非常相似。
下面,有我的短代码..请看代码..我需要你的帮助..
谢谢
#include <avr/io.h>
#include <avr/interrupt.h>
#define F_CPU 16000000UL
#include <avr/delay.h>
#define FALSE 0
#define TRUE 1
/*COUNT VARIABLE, SWITCH VARIABLE*/
unsigned int cnt_LED= 0; //LED TIMER0 COUNT
unsigned int cnt_FND= 0; // FND TIMER2 COUNT
unsigned short FND_sw=0;
/********************************/
/*Function List*/
void LED();
void FND_TURN_ON();
/***************/
/**** LED TIMER2 ****/
ISR(TIMER2_OVF_vect) // 0.002*1500= 3s
{
TCNT2 = 0x82;
if(++cnt_LED ==1500) {
PORTA = 0x00;
cnt_LED = 0;
}
}
/*******************/
int main()
{
sei();
LED();
while(1)
{
}
}
void LED()
{
/*LED Register*/
DDRA = 0xff;
TCCR2 = 0x06; //B 0000 0101
TCNT2 = 0x82;
/*************/
PORTA = 0xff; //led on
TIMSK = 0x40;
}
解决方案
首先你在中断程序中切换led。我认为您的意图是切换它。
其次,计数器必须是易变的。
推荐阅读
- clang-format - clang-format:指针返回值缩进(char*)
- python - 如何在 django 查询集中的多个字段上执行连接?
- c# - 有没有办法将用于 Auth 的 JWT 令牌传递到 C# Asp.net Core 中的 Selenium WebDriver 中?
- tensorflow - 图像增强再现性
- python - Python 程序没有按我的意愿命名我的文件
- c# - 在 C# windows 窗体中获取所有打开的选项卡 URL
- javascript - 在 svg 地图上创建圆圈
- c# - Asp.Net 应用程序的本地实时服务器,用于查看实时更改
- class - 带有 IEnumerable 字段的 ASP.NET Core MVC 后模型
- c# - 在 asp.net core mvc 中通过@Html.ActionLink 传递参数