xtaens 发表于 2010-12-9 14:50:17

哪位大哥知道ICCAVR6.31a或ICC软件中有没有自带的Atmega48等单片机的看门狗程序啊?

如题,gcc软件中就有自带的看门狗程序,只需调用一下即可,不知ICC中是否也有呢??
谢谢了

Gorgon_Meducer 发表于 2010-12-10 00:08:52

貌似代码生成器就可以产生。

xtaens 发表于 2010-12-10 13:32:35

回复【1楼】Gorgon Meducer 傻孩子
-----------------------------------------------------------------------

按你的意思我生成的WDT代码,但wdt();这个函数在哪里呢??
//ICC-AVR application builder : 2010-12-10 下午 01:31:40
// Target : M48
// Crystal: 7.3728Mhz

#include <iom48v.h>
#include <macros.h>

void port_init(void)
{
PORTB = 0x00;
DDRB= 0x00;
PORTC = 0x00; //m103 output only
DDRC= 0x00;
PORTD = 0x00;
DDRD= 0x00;
}

//Watchdog initialize
// prescale: 1024K
void watchdog_init(void)
{
WDR(); //this prevents a timout on enabling
WDTCSR = 0x69; //WATCHDOG ENABLED - dont forget to issue WDRs
}

#pragma interrupt_handler wdt_isr:7
void wdt_isr(void)
{
//watchdog timeout
}

#pragma interrupt_handler int0_isr:2
void int0_isr(void)
{
//external interupt on INT0
}

#pragma interrupt_handler int1_isr:3
void int1_isr(void)
{
//external interupt on INT1
}

//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
watchdog_init();

MCUCR = 0x00;
EICRA = 0x0B; //extended ext ints
EIMSK = 0x03;

TIMSK0 = 0x00; //timer 0 interrupt sources
TIMSK1 = 0x00; //timer 1 interrupt sources
TIMSK2 = 0x00; //timer 2 interrupt sources

PCMSK0 = 0x00; //pin change mask 0
PCMSK1 = 0x00; //pin change mask 1
PCMSK2 = 0x00; //pin change mask 2
PCICR = 0x00; //pin change enable
PRR = 0x00; //power controller
SEI(); //re-enable interrupts
//all peripherals are now initialized
}

xtaens 发表于 2010-12-10 13:47:55

回复【1楼】Gorgon Meducer 傻孩子
-----------------------------------------------------------------------

还有一事不明白,请傻孩子指点:
1、下面的端口初始化函数是用代码生成器生成的,为什么赋值时先要给PORTN赋值,而后
给DDRN赋值呢?我觉得应该先给DDRN赋值,后给PORTn赋,这样数据一来,端口上就有输出。。。
先给PORTn赋,后给DDRn赋,这样的好处是什么呢

2、我给单片机发送一串数,串口中断使能,为什么串口中断为字节中断呢????(发的格式见下图)

void port_init(void)
{
PORTB = 0x00;
DDRB= 0x00;
PORTC = 0x00; //m103 output only
DDRC= 0x00;
PORTD = 0x00;
DDRD= 0x00;
}

http://cache.amobbs.com/bbs_upload782111/files_35/ourdev_603747Q3M47N.png
(原文件名:飞信截屏未命名.png)


下面是我的串口中断处理函数
/*
***************************************************************
Uart0中断处理函数
***************************************************************
*/
void Uart0_INT(uint8 UartData)
{
        static uint8 iNumber;
        static uint8 bReceiveUart;               //标示是否接收串口数据
        static uint8 UartReceiveData;           //接收数据
        if (UartData==0x5a)
        {
                //包头到达
                iNumber=0;
                    bReceiveUart=1;        //开始接收信息
        }
        if(bReceiveUart==1)
        {
                    UartReceiveData=UartData;
                    iNumber++;
        }
        if (iNumber==7)
        {
                //已经收到整包
                SD2405Time.year=UartReceiveData;
                SD2405Time.month=UartReceiveData;
                SD2405Time.day=UartReceiveData;
                SD2405Time.hour=UartReceiveData;
                SD2405Time.minute=UartReceiveData;
                SD2405Time.second=UartReceiveData;       
                SD2405_SetTime();
                Uart0_SendByte('O');
                Uart0_SendByte('K');       
        }
}

Gorgon_Meducer 发表于 2010-12-12 01:12:56

芯片刚刚复位的时候,端口处于输入状态,上拉电阻关闭,也就是所谓的高阻态。
先设置PORTx最多也就是开启或者关闭上拉电阻;如果反过来则有可能导致在设置
DDRx以后,就有引脚对外驱动了(灌或者拉)

第二个问题不明白……

xtaens 发表于 2010-12-12 22:07:45

回复【4楼】Gorgon Meducer 傻孩子
-----------------------------------------------------------------------

谢谢大哥的回答,,
页: [1]
查看完整版本: 哪位大哥知道ICCAVR6.31a或ICC软件中有没有自带的Atmega48等单片机的看门狗程序啊?