⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main._c

📁 用的avr icc 开发的atmega16的超声波测距仪模型。
💻 _C
字号:
#define MAIN_C
#include "includes.h"
//ICC-AVR application builder : 2007-1-22 9:46:41
// Target : M16
// Crystal: 4.0000Mhz
void port_init(void)
{
 PORTA = 0xFF;
 DDRA  = 0x00;
 PORTB = 0xfe;// SEND ECHO
 DDRB  = 0x01;
 PORTC = 0xff; //m103 output only
 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();
 Init_LCD();
 timer1_init();
 MCUCR = 0x00;
 GICR  = 0x00;
 TIMSK = 0x24; //OVR(0x20)+ICP(0x04) interrupt sources
 SEI(); //re-enable interrupts
 //all peripherals are now initialised
}

void display_temprature(void)
  {
   temprature= readTempDS18B20();

   temprature_flag=(temprature>>8)&0xf8;//h8bit(5bit)
   
    if(temprature_flag==0)              //signed temprature 
	 {
	    temprature/=8;
		temprature*=5;
	    LCD_Cursor(1,8);
	    LCD_DisplayCharacter('+');
		speed=3314+temprature*6/10;  //set speed for echo
	 }
	 
	 if(temprature_flag!=0)
	 { 
	   temprature=~temprature+1;
	   temprature&=~0xf800;
       temprature/=8;
	   temprature*=5;
       LCD_Cursor(1,8);
	   LCD_DisplayCharacter('-');
	   speed=3314-temprature*6;  //set speed for echo	 
     }
	 
	//temprature=speed;//testing!!!!!!!!!!!!!!!!!!!!!!!!
	 
	 ASCII_T[0]='0'+temprature/1000;
	 temprature%=1000;
	  ASCII_T[1]='0'+temprature/100;
	 temprature%=100;
	  ASCII_T[2]='0'+temprature/10;
	 temprature%=10;
	  ASCII_T[3]='0'+temprature;
	 LCD_Cursor(1,9);
	 LCD_DisplayCharacter(ASCII_T[0]);	//100BIT
	 LCD_Cursor(1,10);
	 LCD_DisplayCharacter(ASCII_T[1]);	//10BIT
	 LCD_Cursor(1,11);
	 LCD_DisplayCharacter(ASCII_T[2]);	//1BIT
	 LCD_Cursor(1,12);
	 LCD_DisplayCharacter('.');// . BIT	
	 LCD_Cursor(1,13);
	 LCD_DisplayCharacter(ASCII_T[0]);//0.1BIT			 
     LCD_Cursor(1,14);
	 LCD_DisplayCharacter('`');	//UNIT
	 LCD_DisplayCharacter('C');	//UNIT
  }

void main(void)
 {  //initial and the picture of starting work 
    init_devices();
    LCD_DisplayString(1,2,"NOW");
	LCD_DisplayString(2,1,"  ULTRASONIC ");
	display_temprature();
    delay_nms(3000);
	ClearLine(2);
  while(1)
   {    
	    display_temprature();
		
	    LCD_DisplayString(1,1,"40KHz");
		TIMSK = 0x00; //delay for voiding  self noise 
		pwm_40KHz(16);
        timer1_start();
		pwm_20KHz(8);
		delay_nms(5);//lenth shoud far more than 1m for self noise
		TIMSK = 0x24; //OVR(0x04)+ICP(0x20) interrupt sources
		delay_nms(200);// one frush per second
  }
}  

⌨️ 快捷键说明

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