标题: 关于AVR单片机全局变量使用-MEGA128 ICC-AVR [打印本页]

作者: life_阳子    时间: 2020-4-12 13:42
标题: 关于AVR单片机全局变量使用-MEGA128 ICC-AVR
第一次使用AVR单片机,准备做一个仿真,要求是用外部中断6去检测脉冲,然后记录脉冲一分钟有多少个,显示在数码管上,现在遇到了全局变量使用不了的问题,很懵逼,还请各位好友帮忙!
仿真电路图如下:


程序如下:
#include <iom128v.h>
#include <macros.h>
#include <stdio.h>
#include <string.h>
#define uint unsigned int
#define uchar unsigned char

uchar  table1[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar const  table[17]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82, 0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xBF};

extern uchar counter2 = 20;
void delay(uint m)
{
  uint i,j;
  for(i=90;i>0;i--)
        for(j=m;j>0;j--);
}
void init_devices(void)
{
PORTD = 0xff;//PORTC口输出0电平
DDRD  = 0xFF;//PORTD口为输出口
PORTE = 0xff;   //PORTB.0为输入带上拉
DDRE  = 0x00;   //PORTB.0为输入口
PORTF = 0xff;   //PORTB.0为输入带上拉
DDRF  = 0xFF;   //PORTB.0为输入口
}
void display(uchar counter)
{
  PORTF = 0xFE;
  PORTD = ~table[counter/10];
  delay(1);
  PORTD = 0x00;

  PORTF = 0xFD;
  PORTD = ~table[counter%10];
  delay(1);
  PORTD = 0x00;
}
/********外中断初始化********/
void INT_init(void)
{
CLI();
EICRB&=~(1<<ISC60);
EICRB|=(1<<ISC61);
EIMSK|=(1<<INT6);
SEI();
}

void main(void)
{
uchar  counter1 = 60;
init_devices();
INT_init();
while(1)
{
  display(counter2);
}
}
/********以下是外中断1函数********/
#pragma interrupt_handler Extint6:8         //外中断6
void Extint6(void)
{
//counter2++;
}



作者: life_阳子    时间: 2020-4-12 13:46
问题是,将counter定义在了外面,在主函数里就使用不了,只有定义在主函数里才能使用




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1