[Atmel] 用AtmelStudio6.2跑mega16例程(10):同PC通讯

[复制链接]
895|0
 楼主| ddllxxrr 发表于 2014-9-9 21:25 | 显示全部楼层 |阅读模式
这个例和很简单就是象串口发数据。用proteus 7。10仿真通过.


以下是程序在Studio 6.2上通过:
  1. /*
  2. * GccApplication17.c
  3. *
  4. * Created: 2014-9-9 21:07:46
  5. *  Author: Administrator
  6. */


  7. #include <avr/io.h>
  8. #include "stdio.h"
  9. #define uchar unsigned char
  10. #define uint unsigned int
  11. #define RXC  7
  12. #define UDRE 5
  13. char j,k;
  14. void uart0_send(uchar i)
  15. {
  16.         while(!(UCSRA&(1<<UDRE)));
  17.         UDR=i;
  18. }

  19. void delay_ms(uint aa)
  20. {
  21.         for(k=0;k<aa;k++)
  22.         {
  23.                 ;
  24.         }
  25.        
  26. }
  27. int main(void)
  28. {
  29.         DDRC=0xFF;
  30.         PORTC=0xFF;
  31.         DDRD=0xFA;
  32.         PORTD=0xFF;
  33.         UCSRA=0x00;
  34.         UBRRH=0;
  35.         UBRRL=25;            //系统时钟8MHz,波特率为9600bps
  36.         UCSRB=0x18;
  37.         UCSRC=0x86;
  38.         while(1)
  39.         {
  40.                 uart0_send(j);
  41.                 j=0x4;
  42.                 delay_ms(50);
  43.         }
  44. }


本帖子中包含更多资源

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

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

本版积分规则

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

2404

主题

7002

帖子

68

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