打印
[AVR单片机]

定时器中断进不了跑马等程序

[复制链接]
555|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
jerry342622|  楼主 | 2016-5-22 17:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 jerry342622 于 2016-5-22 17:05 编辑

请问大侠,为什么这程序进不跑马灯里面去啊?编译都是OK的,
/*============================================================
File Name :timer1.c
说明 :
1. 检测溢出标志
2. 每1秒,PORTC 向左或向右移动一位
=============================================================*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>


void initialize_timer(void);
  extern interrupt_count=1;
unsigned char Left_Bit=1;   //左移位自变量
unsigned char Right_Bit=0;   //左移位自变量
unsigned char  flag_bit;           //中断查询标志位

void initialize_timer(void)
{
     TCNT0=0x00;                                                // {(0xff-0x70)+1}*1024*(1/14.7456)=10ms
         TCCR0=0x07;                                                // 定时器0 prescaer=1024 时钟 预分频 (CS02 :0)
         TIMSK=0x01;                                                // OCIE0=1; 定时器0溢出中断
     sei();                                                                // 使能全局中断
}
         


SIGNAL(SIG_OVERFLOW0)
{
            interrupt_count=interrupt_count++;
         TCNT0=0x00;

}





int main(void)
{
        unsigned char  count=0;

   initialize_timer();
        DDRA=0xFF ;  //置PA口为输出,方向置“1”
        PORTA=0X3F  ;  //字符显示口同是输出

        DDRB=0Xf0;//设置PD IO口为输入方式,高4位不管
    PORTB|=0X0f;//设置IO口低4位为输入方式且带上拉电阻,即高电平

        DDRC=0xFF ;  //置PC口为输出位显示口,方向置“1”
        PORTC=0x00 ;// 位显示全关闭,置零


        if(1)
         {
                    if(interrupt_count>=20)                        
                            {                                                        //跑马灯        
                           
                                        if(Right_Bit<=1)
                                                {
                                                PORTC=Left_Bit;
                                                Left_Bit=(Left_Bit<<1);
                                                if(Left_Bit>=0x80)         //移位到达最大位时,返回到右边第一位
                                                                Right_Bit=0x80;
                                                                interrupt_count=0;

                                                }
                                        else                                                        // 右移  
                                                {
                                                PORTC=Right_Bit;
                                                Right_Bit=(Right_Bit>>1);
                                                if(Right_Bit<=1)
                                                   Left_Bit=1;
                                interrupt_count=0;
                                                }
        
                             }
        
                                                              
                 
                 }

  }

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

3

帖子

0

粉丝