📄 main._c
字号:
//ICC-AVR application builder : 2006-11-11 12:55:39
// Target : M16
// Crystal: 7.3728Mhz
#include "config.h"
void port_init(void)
{
PORTA = 0x03;
DDRA = 0x03;
PORTB = 0x00;
DDRB = 0x00;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00; //timer interrupt sources
Com_init(); //串行口初始化
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void Delay(void) //软件延时
{
unsigned char i,j;
for(i=200;i>0;i--)
{
for(j=200;j>0;j--)
;
for(j=200;j>0;j--)
;
}
}
void main(void)
{
uint8 SIO_buff[20]; //定义串口数据缓冲区
init_devices();
//指示单片机正常开始工作,一亮,二亮,都亮,都灭
PORTA = 0x02; //1脚为高,0脚为低,0脚灯亮
Delay(); //延时
PORTA = 0x01; //0脚为高,1脚为低,1脚灯亮
Delay(); //延时
PORTA = 0x00; //同时亮
Delay(); //延时
PORTA = 0x03; //同时灭
Com_putstring ("www.avrvi.com ",14,&RTbuf_UART0); //输出一个字符串到串行口
while(1)
{
if(Com_R_count(&RTbuf_UART0)!=0)
{
Com_getstring (SIO_buff,1,&RTbuf_UART0);
Com_Rbuf_Clear(&RTbuf_UART0); //清空buffer
if(SIO_buff[0]==1) //接收到一个一
{
Com_putstring ("ok!!",4,&RTbuf_UART0); //输出一个字符串到串行口
PORTA = 0x00; //同时亮
Delay(); //延时
PORTA = 0x03; //同时灭
}
} //end of if(Com_R_count(&RTbuf_UART0)!=0)
Delay();//延时
Com_putstring ("www.avrvi.com ",14,&RTbuf_UART0); //输出一个字符串到串行口
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -