📄 soft_test.c
字号:
// Test Soft-Uart : See Atmel Applicaton Note 305
// File: soft_test.c
// Target : mega16
// Crystal: 7.3728 Mhz
// Date 05/30/2007
// for Imagecraft ICCAVR Ver. 6.31
// Usage : if you need more then one UART
// Customer settings : SEE soft_uart.s
// 程序被移植到mega16上
// 古欣 AVR与虚拟仪器 www.avrvi.com
// 连接:电源跳线5V,晶振跳线7.3728M,串口使用跳线JP4的1和2短接
// 程序原型Written/adapted by Dipl.Ing.J.Zastrow
#include <iom16v.h>
#include <macros.h>
//function prototypes for soft_uart.s
//one byte return value in R16 !!!
extern unsigned char getit(void);
//one byte argument in R16 !!!
extern putit(register unsigned char key);
//initialise TxD,RxD port pins
extern void init_soft_uart(void);
void port_init(void)
{
//default settings all inputs and pull up
PORTA = 0xFF;
DDRA = 0x00;
PORTB = 0xFF;
DDRB = 0xFF;
PORTC = 0xFF;
DDRC = 0x00;
PORTD = 0xFF;
DDRD = 0x00;
}
//call this routine to initialise all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
MCUCR = 0x00;
TIMSK = 0x00;
SEI(); //re-enable interrupts
//all peripherals are now initialised
}
//Simply connect RS232 SPARE to
//PD0 to receive and PD1 to transmitt
void main(void)
{
unsigned char s=0,i=0;
unsigned char buf[]="www.avrvi.com\r\n";
//defaul
init_devices();
//do custom settings in soft_uart.s !!!
init_soft_uart();
for(i=0;i<16;i++)
{
putit(buf[i]);
}
while(1){
putit('T'); //T
putit('E'); //E
putit('S'); //S
putit('T'); //T
putit(':'); //:
s = getit();//输入一个数
putit(s); //输出一个数
putit(0x0D);//HU
putit(0x0A);//LF
}//end while
}//end main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -