#include
#define fosc 7372800UL //晶振7.3728MHZ
#define baud 9600//波特率
#define com0
void uart0_init(void)
{
UCSR0B = 0x00; //disable while setting baud rate
UCSR0A = 0x00;
UCSR0C =(1<
UBRR0H=(fosc/16/(baud+1))/256;
UCSR0B =(1<
void uart1_init(void)
{
UCSR1B = 0x00; //disable while setting baud rate
UCSR1A = 0x00;
UCSR1C = (1<
UBRR1H=(fosc/16/(baud+1))/256;
UCSR1B =(1<
void putchar0(unsigned char c)
{
while (!(UCSR0A&(1<
}
void putchar1(unsigned char c)
{
while (!(UCSR1A&(1<
}
unsigned char getchar0(void)
{
while(!(UCSR0A& (1<
}
unsigned char getchar1(void)
{
while(!(UCSR1A& (1<
}
void puts0(char *s)
{
while (*s)
{
putchar0(*s);
s++;
}
putchar0(0x0a);
putchar0(0x0d);
}
void puts1(char *s)
{
while (*s)
{
putchar1(*s);
s++;
}
putchar1(0x0a);
putchar1(0x0d);
}
int main(void)
{
unsigned char i;
#ifdef com0
uart0_init();
puts0("HELLO!");
#else
uart1_init();
puts1("HELLO!");
#endif
while(1)
{
#ifdef com0
if (getchar0()=='t')//按键盘t键开始测试
{
puts0("test ok!");
for (i=0;i<10;i++)
{
putchar0(0x30+i);
}
putchar0(0x0a);
putchar0(0x0d);
}
#else
if (getchar1()=='t')//按键盘t键开始测试
{
puts1("test ok!");
for (i=0;i<10;i++)
{
putchar1(0x30+i);
}
putchar1(0x0a);
putchar1(0x0d);
}
#endif
}
}
上一篇:基于AVR单片机的温度测量系统
下一篇:ATMEGA32熔丝位设置
推荐阅读最新更新时间:2024-03-16 13:32