hello world程序_Hello World程序,用于8051微控制器

hello world程序

适用于8051的“ Hello World”嵌入式测试程序 (‘Hello World’ Embedded test program for 8051)

#include <reg52.h>
sbitLED_pin = P1^5;
bit LED_state_G;

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)
	{
		LED_FLASH_Change_State();
		DELAY_LOOP_Wait(1000);
	}
}

void LED_FLASH_Init(void)
{
	LED_state_G=0;
}

void LED_FLASH_Change_State(void)
{
	if (LED_state_G ==1)
	{
		LED_state_G = 0;
		LED_pin = 0;
	}
	else
	{
		LED_state_G = 1;
		LED_pin =1;
	}
}

void DELAY_LOOP_Wait(const unsigned int DELAY)
{
	unsigned int x, y;
	for (x=0 ; x<= DELAY; x++)
	{
		for (y=0; y<=120 : y++)
	}
}

Explanation of various sections of the code in detail

详细解释代码的各个部分

1)超级循环 (1) The Super Loop)

In this function, we use a super loop in which we alternately call two functions LED_FLASH_Change_State(), and DELAY_ LOOP_Wait(). One functions is used to flash the LED by changing the state of glow and the other function is used to insert a delay of 1 second in between the interval. We declare few variables before using the super loop.

在此函数中,我们使用一个超级循环,在该循环中,我们交替调用两个函数LED_FLASH_Change_State()和DELAY_ LOOP_Wait() 。 一种功能是通过更改发光状态来使LED闪烁,另一种功能是在间隔之间插入1秒的延迟。 在使用超级循环之前,我们声明几个变量。

2)使用功能更改LED的状态,LED_FLASH_Change_State() (2) Using function to change the state of LED, LED_FLASH_Change_State())

On execution of this function, the state of L.E.D. changes on the specified port pin. If you want one single flash of LED the function must be called twice. Since the LED will be ON for 0.5 seconds and OFF for 0.5 seconds. So as to deliver the required numbers of hertz of flash( in this case 1Hz) we require this function to be called double the number.

执行此功能时,LED的状态在指定的端口引脚上改变。 如果您希望LED闪烁一次,则必须调用该函数两次。 由于LED会亮0.5秒,熄灭0.5秒。 为了提供所需的闪光赫兹数(在这种情况下为1Hz),我们要求将此功能称为两倍数。

3)使用函数DELAY_LOOP_Wait() (3) Using function DELAY_LOOP_Wait())

The delay duration depends upon the parameter. Parameter for an 8051 microcontroller is roughly around 12MHz (12 oscillatory cycles). The delay values are usually determined by trial and error. The delay may vary depending upon the compiler optimization settings and other factors. You can check the delay duration for your compiler. If it is keil simulator, you can view the delay using the performance analyzer when your simulation is running.

延迟持续时间取决于参数。 8051微控制器的参数大约为12MHz(12个振荡周期)。 延迟值通常由反复试验确定。 延迟可能会因编译器优化设置和其他因素而异。 您可以检查编译器的延迟时间。 如果是keil模拟器,则可以在运行模拟时使用性能分析器查看延迟。

翻译自: https://www.includehelp.com/embedded-system/hello-world-program-for-8051-microcontroller.aspx

hello world程序

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值