找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1840|回复: 1
收起左侧

关于AVR单片机全局变量使用-MEGA128 ICC-AVR

[复制链接]
ID:235332 发表于 2020-4-12 13:42 | 显示全部楼层 |阅读模式
第一次使用AVR单片机,准备做一个仿真,要求是用外部中断6去检测脉冲,然后记录脉冲一分钟有多少个,显示在数码管上,现在遇到了全局变量使用不了的问题,很懵逼,还请各位好友帮忙!
仿真电路图如下:
1.png

程序如下:
#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++;
}


回复

使用道具 举报

ID:235332 发表于 2020-4-12 13:46 | 显示全部楼层
问题是,将counter定义在了外面,在主函数里就使用不了,只有定义在主函数里才能使用
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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