单片机教程网
电脑版
提示:
原网页
已由神马搜索转码, 内容由
www.51hei.com
提供.
51单片机
24小时必答区
单片机教程
单片机DIY制作
STM32
更多导航↓
Cortex M3
模数电子
电子DIY制作
音响/功放
拆机乐园
Arduino
嵌入式OS
程序设计
论坛
嵌入式/单片机论坛
AVR单片机
AVR 单片机初值计算
查看:
4639
|
回复:
3
AVR 单片机初值计算
[复制链接]
来自 4#
ID:690448
发表于 2020-11-19 18:52
|
只看该作者
ICC-AVR application builder 点几下鼠标就可完成
推荐大家试一试
//ICC-AVR application builder : 2020/11/19 18:50:34
// Target : M16
// Crystal: 4.0000Mhz
#include< iom16v.h>
#include< macros.h>
void port_init(void)
{
PORTA = 0x00;
DDRA = 0x00;
PORTB = 0x00;
DDRB = 0x00;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
}
//TIMER1 initialize - prescale:256
// WGM: 0) Normal, TOP=0xFFFF
// desired value: 1Sec
// actual value: 1.000Sec (0.0%)
void timer1_init(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0xC2; //setup
TCNT1L = 0xF7;
OCR1AH = 0x3D;
OCR1AL = 0x09;
OCR1BH = 0x3D;
OCR1BL = 0x09;
ICR1H = 0x3D;
ICR1L = 0x09;
TCCR1A = 0x00;
TCCR1B = 0x04; //start Timer
}
#pragma interrupt_handler timer1_ovf_isr:iv_TIM1_OVF
void timer1_ovf_isr(void)
{
//TIMER1 has overflowed
TCNT1H = 0xC2; //reload counter high value
TCNT1L = 0xF7; //reload counter low value
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
timer1_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x04; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
//
void main(void)
{
init_devices();
//insert your functional code here...
}
复制代码
评分
参与人数
1
黑币
+50
收起
理由
admin
+ 50
回帖助人的奖励!
查看全部评分
回复
沙发
ID:739227
发表于 2020-4-27 19:30
|
只看该作者
非常好!不错!非常感谢楼主
回复
板凳
ID:808608
发表于 2020-10-10 14:23
|
只看该作者
非常好!不错!非常感谢师傅
回复
返回列表
手机版
|
小黑屋
|
51黑电子论坛
|
管理员QQ:125739409;技术交流QQ群281945664
Powered by
单片机教程网