main.c

来自「bootloader」· C语言 代码 · 共 104 行

C
104
字号
head	1.1;access;symbols;locks	ICCAVR:1.1; strict;comment	@ * @;1.1date	2006.11.14.14.10.17;	author ICCAVR;	state Exp;branches;next	;desc@对方@1.1log@Initial revision@text@//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 peripheralsvoid 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[4];  //定义串口数据缓冲区  init_devices();  //指示单片机正常开始工作,一亮,二亮,都亮,都灭  PORTA = 0x02;       //1脚为高,0脚为低,0脚灯亮  Delay();           //延时  PORTA = 0x01;	     //0脚为高,1脚为低,1脚灯亮  Delay();           //延时  PORTA = 0x00;      //同时亮  Delay();           //延时  PORTA = 0x03;      //同时灭    Com_putstring ("ww",2,&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 ("ww00",4,&RTbuf_UART0); //输出一个字符串到串行口  }}@

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?