希望各位各抒己见程序如下:出现问题如下:
Device 3% full.
Cannot find source file C:\icc\examples.avr\C\usart\iostudio.s
Done.
本人用的是iccavr编译软件,程序如下:
#include<iom16v.h>
#include<macros.h>
#include<stdio.h>
#define uchar unsigned char
#define uint unsigned int
//#define mclk 8000000
#pragma interrupt_handler uart_rx:12
uchar flag_uart,i,a,flag_on,flag_time;
void delay(uint ms)
{
uint i,j;
for(i=0;i<ms;i++)
{
for(j=0;j<1141;j++);
}
}
void uart_init(viod)
{
uchar baud;
UCSRB=0x00;
UCSRA=0x00;
UCSRC=(1<<URSEL)|(0<<UPM0)|(3<<UCSZ0);
baud=8000000/16/19200-1 ;
UBRRL=baud;
UBRRH=baud>>8;
UCSRB=(1<<TXEN)|(1<<RXEN)|(1<<RXCIE);
SREG=BIT(7);
DDRD|=0X02;
}
void main()
{
uart_init();
while(1)
{
if(flag_uart==1)
{
flag_uart=0;
switch(flag_on)
{
case 0:puts("turn on");//printf("turn on");
break;
case 1:UDR='B';//printf("turn off");
break;
case 2:UDR='C';//printf("error!\n");
break;
}
while(!(UCSRA&(BIT(TXC))));
UCSRA|=BIT(TXC);
}
}
}
void uart_rx()
{
UCSRB&=~BIT(RXCIE);
a=UDR;
flag_uart=1;
if(a==1)
flag_on=0;
else if(a==2)
flag_on=1;
else
flag_on=2;
UCSRB|=BIT(RXCIE);
} |