mega8 iccavr的硬中断程序

硬中断的调试:

在调试中用了以前的串口程序。

程序下载:

/****************************************/
/*         http://truemans.inf            */
/*         硬中断实验                    */
/*         作者:HB                        */
/*         2010年8月5日                    */
/*  目标MCU:MEGA8   晶振:内部晶振  8MHZ    */
/****************************************/
#include <iom8v.h>
#include <macros.h>

#include "uart.h"

extern signed char        bufRxSize;
extern signed char        bufTxSize;

unsigned char            flagInt0;

/* 接收中断 */
#pragma interrupt_handler Int0_interrupt:iv_INT0
void Int0_interrupt( void )
{
    flagInt0=1;
}

void main(void)
{
    unsigned char temp;
    CLI(); //disable all interrupts
    InitUSART();
    putS("Hello,world!\r\n");
    putS("Press Any Key to Continue…:");
    putChar(getChar());
    GICR  = 0×40;                    //int0中断使能
    MCUCR    =    MCUCR | 0×02;    //下降沿沿触发
    DDRD=DDRD | 0×18;            //将D3、D4用于输出
    SEI(); //re-enable interrupts    
    TransmitStr("\r\n\r\nDemo Start!!\r\n");
    TransmitStr("\r\nBy tremans.info\r\n");
    while(bufTxSize);
    while(1)
    {       
        if(bufRxSize)
        {
            TransmitByte(ReceiveByte(),0);
            TransmitByte(‘\n’,0);
            TransmitByte(‘\r’,1);
            PORTD = ~(PORTD & 0×18);
        }
        if(flagInt0)
        {           
            TransmitStr("New interrupt 0!\r\n");
            flagInt0=0;
        }
    }   
}

Leave a comment

0 Comments.

Leave a Reply


[ Ctrl + Enter ]