ATmega16做的流水灯为什么显示不正常?

whwclp 2018-12-18 05:29:38
#include <mega16.h>
#include <stdlib.h>
#include <delay.h>

#define uchar unsigned char
#define uint unsigned int
#define BIT(x) (1<<(x))

#define dlyTime 500

uchar i;
uchar light;
uchar keyFlag=0;
uchar light;

uchar key_press(){
uchar j;
j=PIND;
j=j&0x0C;
if(j==0x0C){
return 0;
}
else{
return 1;
}
}

interrupt [2] void int0(){
delay_ms(10);
if(key_press()){
keyFlag=1;
i=0;
light=0;
PORTA=0xFF;
delay_ms(dlyTime);
while(key_press());
}
}

interrupt [3] void int1(){
delay_ms(10);
if(key_press()){
keyFlag=2;
i=0;
light=0;
PORTA=0xFF;
delay_ms(dlyTime);
while(key_press());
}
}

void port_init(void){
DDRA|=0xFF;
PORTA|=0xFF;
DDRD&=~BIT(2);
DDRD&=~BIT(3);
PORTD|=BIT(2);
PORTD|=BIT(3);
}

void main(void){
i=0;
light=0x00;
port_init();

MCUCR|=0x0A;
GICR|=BIT(7);
GICR|=BIT(6);
GICR&=~BIT(5);
GIFR|=BIT(7);
GIFR|=BIT(6);
#asm("sei");

while(1){
if(i==8){
i=0;
light=0;
PORTA=0xFF;
delay_ms(dlyTime);
}
if(keyFlag == 1) light = light | (0x80 >> i);
if(keyFlag == 2) light = light | (0x01 << i);
PORTA = ~(light);
delay_ms(dlyTime);
i++;
};
}
...全文
751 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
皮皮涵 2019-01-09
  • 打赏
  • 举报
回复
可能引脚没设置好吧
fly 100% 2018-12-22
  • 打赏
  • 举报
回复
显示没有保持住吧
weixin_38401582 2018-12-21
  • 打赏
  • 举报
回复
中断那里有问题
平底锅锅锅 2018-12-21
  • 打赏
  • 举报
回复
流水灯先单个控制,引脚要对上。硬件连接也要正常。
yishumei 2018-12-20
  • 打赏
  • 举报
回复
楼主,流水灯是什么现象?

27,374

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 单片机/工控
社区管理员
  • 单片机/工控社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧