打印
[Atmel]

用AtmelStudio6.2跑mega16例程(11):中断接收

[复制链接]
1947|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
这个程序得好理解就是用中断接收把收到的字节在PARTC上显示一下:



在Atmel  Studio6.2具体程序如下:

/*
* GccApplication18.c
*
* Created: 2014-9-10 20:20:00
*  Author: Administrator
*/


#include <avr/io.h>
#include <avr/interrupt.h>
#define uchar unsigned char
#define uint unsigned int

#define  FE           4
#define  PE           2
#define  DOR          3

uchar LEDdisp;
ISR(USART_RXC_vect)//USART串行接收中断
{
        uchar status,data;
        status=UCSRA;
        data=UDR;
        if((status&((1<<FE)|(1<<PE)|(1<<DOR)))==0)
        {
                LEDdisp=data;
        }
}
int main(void)
{
        DDRC=0xFF;
        PORTC=0xFF;
        DDRD=0xFA;
        PORTD=0xFF;
        UCSRA=0x00;
        UBRRH=0;
        UBRRL=25;            //系统时钟8MHz,波特率为9600bps
        UCSRB=0x90;
        UCSRC=0x86;
        while(1)
        {
                PORTC=LEDdisp;
               
        }
}
编译通过的截图:




相关帖子

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

本版积分规则

个人签名:http://shop34182318.taobao.com/ http://shop562064536.taobao.com

2398

主题

6950

帖子

67

粉丝