[AVR单片机] 用ATmel Studio6.2编译出错,ATmega16的T/C0例程

[复制链接]
2696|3
 楼主| moyansen 发表于 2014-10-16 23:12 | 显示全部楼层 |阅读模式
我最近在学习AVR单片机,我参考《AVR单片机使用C语言程序设计与典型实例》书上的例程来学习,但是我使用Atmel Studio6.2编译书上的T/C0例程时,出错了,是什么原因呢?
  1. #define F_CPU 4000000UL
  2. #include <avr/io.h>
  3. //#include <iom16.h>
  4. #include <util/delay.h>
  5. #include <avr/interrupt.h>
  6. #define uchar unsigned char
  7. #define uint unsigned int
  8. const uchar LedNum[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
  9. uchar second = 0;
  10. uchar count = 0;
  11. uchar minute = 0;

  12. void LEDShow(int num)
  13. {
  14.         uchar i,tmp,curnum;
  15.         int tmpnum;
  16.         tmp=0xef;
  17.         tmpnum=num;
  18.         for (i=0;i<4;i++)
  19.         {
  20.                 curnum = tmpnum % 10;
  21.                 curnum = tmpnum / 10;
  22.                 PORTA =tmp;
  23.                 if (i==2)
  24.                 {
  25.                         PORTC=LedNum[curnum]|0x80;
  26.                 }
  27.                 else
  28.                 {
  29.                         PORTC=LedNum[curnum];
  30.                 }
  31.                 _delay_ms(1);
  32.                 tmp = (tmp<<1);
  33.         }
  34. }
  35. int main(void)
  36. {
  37.     DDRC = 0XFF;
  38.     DDRA = 0XFF;
  39.     DDRB = 0X01;
  40.     TCCR0 = 0X05;
  41.     TIMSK = 0X01;
  42.     TCNT0 = 256 - 0.01/(1024.0/F_CPU);
  43.     sei();
  44.         while(1)
  45.     {
  46.         LEDShow(minute*100+second);
  47.                 if (second>59)
  48.                 {
  49.                         second = 0;
  50.                         minute ++;
  51.                 }
  52.                 if (minute>99)
  53.                 {
  54.                         minute=0;
  55.                 }
  56.     }
  57.         return 0;
  58. }
  59. SIGNAL(SIG_OVERFLOW0)
  60. {
  61.         count++;
  62.         if (count == 99)
  63.         {
  64.                 second++;
  65.                 count=0;
  66.         }
  67.         TCNT0=256 - 0.01/(1024.0/F_CPU);
  68. }
编译错误是:Error 1   attempt to use poisoned "SIG_OVERFLOW0"
wangch_sh 发表于 2014-10-17 11:55 | 显示全部楼层
SIGNAL(SIG_OVERFLOW0)
{
        count++;
        if (count == 99)
        {
                second++;
                count=0;
        }
        TCNT0=256 - 0.01/(1024.0/F_CPU);
}
貌似这里出问题了。
 楼主| moyansen 发表于 2014-10-17 21:14 | 显示全部楼层
wangch_sh 发表于 2014-10-17 11:55
SIGNAL(SIG_OVERFLOW0)
{
        count++;

编译器提示就是这个地方出错,但是我照搬书上的,例程的,可能是因为编译器版本不一样导致的,但是我还不知道怎么改!
Mcuzone_xyz 发表于 2014-10-20 13:59 | 显示全部楼层
atmel studio6的架构跟其他的AVR编译器都不一样的,好好的去看里面的ASF和它提供的例子吧。
定义中断不是用SIGNAL
用ISR(xxx)

good luck
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

18

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部