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

📄 hello.c

📁 CODE for embedded C ,hand coding version
💻 C
字号:
/*---------------------------------*-
 Hello.C(v1.00)
  Author : 06_Digital_Media 
 ------------------------------------
 A "Hello Embedded World "test program for 8051
 -*----------------------------------*/
 
 #include<reg52.h>
 //LED is to be connected to this pin
 sbit LED_pin = P1^5;
 //Store the LED state
 bit LED_state_G;
 
 //Function prototypes
 void LED_FLASH_Init(void);
 void LED_FLASH_Change_State(void);
 void DELAY_LOOP_Wait(const unsigned int);
 
 /*-----------------------------------------------*/
 void main(void)
 {
	 LED_FLASH_Init();
	 while(1){
		//Change the LED state (OFF to ON ,or vice versa)
		LED_FLASH_Change_State();
		//Delay for *approx * 1000 ms
		DELAY_LOOP_Wait(1000);
		 }
	 }
	 
	 
	/*-------------------------------------------*-
	LED_FLASH_Init();
	Prepare for LED_Change_State() function -see below
	-*----------------------------------------------*/
	
	void LED_FLASH_Init(void){
		LED_state_G = 0;
		}
  /*-----------------------------------------*-
  LED_FALSH_Change_State()
  Change the state of an LED (or pulses a buzzer,etc) on a specified port
  pin
  Must call at twice the required flash rate:thus,for 1 Hz flash (on for
  0.5 seconds,off for 0.5 seconds) 
  this function must be called twice a second
  -*-----------------------------------------*/
  
  void LED_FLASH_Change_State(void)
  {
	  //Change the LED from OFF to ON (or vice versa)
	  if(LED_state_G==1){
		  LED_state_G= 0;
		  LED_pin = 0;
		  
		  }
		  else{
			  LED_state_G= 1;
			  LED_pin =1;
			  }
	  }
	  
  /*------------------------------------------*-
  DELAY_LOOP_Wait()
  Delay duration varies with parameter
  Parameter is "ROUGHLY*,the dealy ,in milliseconds,
  on 12MHz 8051 (12 osc cycles)
  You need to adjust the timing for your application
  -*-------------------------------------------------*/
  
  void DELAY_LOOP_Wait(const unsigned int DELAY)
  {
	  unsigned int x,y;
	  for(x = 0  ;  x<= DELAY ;x++){
		  for(y=0 ;y<=120;y++);
		  }
	  }
	  
	  /*-----------------------------------------*-
	  -----END OF FILE---------------------------
	  -*-----------------------------------------*/
	  
	  
	  

⌨️ 快捷键说明

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