微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

控制器忙时接收数据

如何解决控制器忙时接收数据

我正在尝试在 proteus 的代码视觉中使用中断。 INT0 增加计数器值,INT1 减少计数器值。为此,我声明了两个函数 interrupt [EXT_INT0] void ext_int0_isr(void)interrupt [EXT_INT1] void ext_int1_isr(void),但是当我运行代码时,它不起作用,并且在 proteus 中收到无限警告“控制器在忙碌时收到数据”。如果您能帮助我,我将不胜感激。

#include <mega8535.h>
#include <alcd.h>
#include <stdio.h>
#include <delay.h>
int i = 0 ;
int j = 0 ;
char number[16];

// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{ 
#asm("cli")// Global disable interrupts

i++;

//go to products counting
if(i < 10) goto ENTERED; 

//go to products packaging process
if(i >= 11) 
{
lcd_clear();
lcd_gotoxy(2,0);
lcd_putsf("Products Are");

for (j=0; j < 10; j++)
{
lcd_gotoxy(1,1); 
lcd_putsf("Being Packaged.");
delay_ms(500);
lcd_gotoxy(1,1);
lcd_putsf("Being          ");
delay_ms(500);
}
}
i=1;

ENTERED:
if(i < 11)
{
sprintf(number,"Number Of People=%d  \n (one Entered)",i); 
}

}

// External Interrupt 1 service routine
interrupt [EXT_INT1] void ext_int1_isr(void)
{ 
#asm("cli")// Global disable interrupts

i--;

//go to products counting
if(i < 11) goto WENTOUT; 

//go to products packaging process
if(i >= 11) 
{
lcd_clear();
lcd_gotoxy(2,1);
lcd_putsf("Being          ");
delay_ms(500);
}
}
i=1;

WENTOUT:
if(i < 11)
{
sprintf(number,"Number Of People=%d \n (one went out)",i); 
}

}

void main(void)
{

// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Falling Edge
GICR|=(1<<INT1) | (1<<INT0) | (0<<INT2);
MCUCR=(1<<ISC11) | (0<<ISC10) | (1<<ISC01) | (0<<ISC00);
MCUCSR=(0<<ISC2);
GIFR=(1<<INTF1) | (1<<INTF0) | (0<<INTF2);
// Alphanumeric LCD initialization
// Connections are specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS - PORTA Bit 0
// RD - PORTA Bit 1
// EN - PORTA Bit 2
// D4 - PORTA Bit 4
// D5 - PORTA Bit 5
// D6 - PORTA Bit 6
// D7 - PORTA Bit 7
// Characters/line: 16

lcd_init(16);

sprintf(number,"Number Of People=%d",i);

while (1)
      {
      lcd_gotoxy(4,0);
      lcd_puts(number);
      #asm("sei")// Global enable interrupts
      delay_ms(50);
      lcd_clear();
      }
}

解决方法

问题是我试图放入 LCD 的字符串长度超过 LCD 的容量,在我缩短字符串后问题解决了。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?