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

[复制链接]
 楼主| ddllxxrr 发表于 2014-9-10 20:57 | 显示全部楼层 |阅读模式
这个程序得好理解就是用中断接收把收到的字节在PARTC上显示一下:



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

  1. /*
  2. * GccApplication18.c
  3. *
  4. * Created: 2014-9-10 20:20:00
  5. *  Author: Administrator
  6. */


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

  11. #define  FE           4
  12. #define  PE           2
  13. #define  DOR          3

  14. uchar LEDdisp;
  15. ISR(USART_RXC_vect)//USART串行接收中断
  16. {
  17.         uchar status,data;
  18.         status=UCSRA;
  19.         data=UDR;
  20.         if((status&((1<<FE)|(1<<PE)|(1<<DOR)))==0)
  21.         {
  22.                 LEDdisp=data;
  23.         }
  24. }
  25. int main(void)
  26. {
  27.         DDRC=0xFF;
  28.         PORTC=0xFF;
  29.         DDRD=0xFA;
  30.         PORTD=0xFF;
  31.         UCSRA=0x00;
  32.         UBRRH=0;
  33.         UBRRL=25;            //系统时钟8MHz,波特率为9600bps
  34.         UCSRB=0x90;
  35.         UCSRC=0x86;
  36.         while(1)
  37.         {
  38.                 PORTC=LEDdisp;
  39.                
  40.         }
  41. }
编译通过的截图:




本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

2404

主题

6995

帖子

68

粉丝
快速回复 在线客服 返回列表 返回顶部