这个例和很简单就是象串口发数据。用proteus 7。10仿真通过.
以下是程序在Studio 6.2上通过:
- /*
- * GccApplication17.c
- *
- * Created: 2014-9-9 21:07:46
- * Author: Administrator
- */
- #include <avr/io.h>
- #include "stdio.h"
- #define uchar unsigned char
- #define uint unsigned int
- #define RXC 7
- #define UDRE 5
- char j,k;
- void uart0_send(uchar i)
- {
- while(!(UCSRA&(1<<UDRE)));
- UDR=i;
- }
- void delay_ms(uint aa)
- {
- for(k=0;k<aa;k++)
- {
- ;
- }
-
- }
- int main(void)
- {
- DDRC=0xFF;
- PORTC=0xFF;
- DDRD=0xFA;
- PORTD=0xFF;
- UCSRA=0x00;
- UBRRH=0;
- UBRRL=25; //系统时钟8MHz,波特率为9600bps
- UCSRB=0x18;
- UCSRC=0x86;
- while(1)
- {
- uart0_send(j);
- j=0x4;
- delay_ms(50);
- }
- }
|