搜索
bottom↓
回复: 5

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

[复制链接]

出0入0汤圆

发表于 2010-12-9 14:50:17 | 显示全部楼层 |阅读模式
如题,gcc软件中就有自带的看门狗程序,只需调用一下即可,不知ICC中是否也有呢??
谢谢了

出0入296汤圆

发表于 2010-12-10 00:08:52 | 显示全部楼层
貌似代码生成器就可以产生。

出0入0汤圆

 楼主| 发表于 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
}

出0入0汤圆

 楼主| 发表于 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;
}


(原文件名:飞信截屏未命名.png)


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

出0入296汤圆

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

第二个问题不明白……

出0入0汤圆

 楼主| 发表于 2010-12-12 22:07:45 | 显示全部楼层
回复【4楼】Gorgon Meducer 傻孩子
-----------------------------------------------------------------------

谢谢大哥的回答,,
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-5 01:47

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

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