找回密码
 注册会员
更新自动建库工具PCB Footprint Expert 2024.04 Pro / Library Expert 破解版

大家帮我看看程序为什么软件调试的时候就是不进T0中断?

[复制链接]
admin 发表于 2012-9-2 16:25:39 | 显示全部楼层 |阅读模式

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有账号?注册会员

×
// Target : M8
// Crystal: 8.0000Mhz

#include "iom8v.h"
#include "macros.h"
#define busy PB6
#define req PB7
#define res PB0
#define DB7 PD7
#define DB6 PD6
#define DB5 PC5
#define DB4 PC4
#define DB3 PC3
#define DB2 PD2
#define DB1 PD1
#define DB0 PD0
unsigned char time1;
unsigned char time2;
unsigned char i;
#pragma interrupt_handler timer0_ovf_isr:10

/*=========我是万恶的分界线=========*/

void port_init(void)
{
PORTB = 0x00; //B口初始化
DDRB = 0x53; //PB7,PB5,PB3,PB2-IN PB6,PB4,PB1,PB0-OUT
PORTC = 0x00; //C口初始化
DDRC = 0x7F; //output only
PORTD = 0x00; //D口初始化
DDRD = 0xFF; //output only
PORTD|=(1<<3);
}

//Watchdog initialize
// prescale: 16K
void watchdog_init(void) //看门狗初始化
{
WDR(); //this prevents a timout on enabling
WDTCR = 0x18; //置位WDCE位;防止复位
WDTCR = 0x08; //看门口有效;预分频16K;时间16m - 不要忘记发出WDRs
}

//TIMER0 initialize - prescale:1024
// desired value: 20mSec
// actual value: 19.968mSec (0.2%)

void timer0_init(void)
{
TCCR0 = 0x00; //stop
TCNT0 = 0x64; //set count
TCCR0 = 0x05; //1024分频
}


void init_devices(void) //中断初始化
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
watchdog_init();
timer0_init();

MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
//-------------华丽的分割线--------------



}
void main()
{
init_devices();
time1=0;
time2=0;
SEI();
}

/*===========初始化结束=========我是传说中的分界线========*/
while(1)
{
WDR(); //清零硬狗
NOP();
time1=0;
while(1) //延时20ms*50=1s
{
if(time2<25)
continue;
else
{
PORTD^=0b00001000;
time2=0;
break;
}
}
}
}

#pragma interrupt_handler timer0_ovf_isr:10
void timer0_ovf_isr(void) //这是中断服务程序

{
TCCR0 = 0x00; //stop
TCNT0 = 0x64; //set count
NOP();
time1++;
time2++;
TCCR0 = 0x05;
}
*滑块验证:
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2024-11-28 23:25 , Processed in 0.051187 second(s), 8 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表