跪求利用共用体编写的C51单片机C语言程序例子,最好有祥细的程序讲解。谢了。
4个回答
展开全部
//共用体其实有时也会用到,特别是RAM不够的时候,我们可以定义一个union,一会把它当做这种类型的变量用,一会又作另外的变量用,当然要前面一个变量不用才能当另外类型变量用,
As an alternative, you may use the following union to store floating-point values.
union f {
float f; /* Floating-point value */
unsigned long ul; /* Unsigned long value */
};
This union contains a float and an unsigned long in order to perform floating-point math operations and to respond to the IEEE error states.
For example:
#define NaN 0xFFFFFFFF /* Not a number (error) */
#define plusINF 0x7F800000 /* Positive overflow */
#define minusINF 0xFF800000 /* Negative overflow */
union f {
float f; /* Floating-point value */
unsigned long ul; /* Unsigned long value */
};
void main (void) {
float a, b;
union f x;
x.f = a * b;
if (x.ul == NaN || x.ul == plusINF || x.ul == minusINF) {
/* handle the error */
}
else {
/* result is correct */
}
}
Copyright (c) Keil Software, Inc. and Keil Elektronik GmbH. All rights reserved.
As an alternative, you may use the following union to store floating-point values.
union f {
float f; /* Floating-point value */
unsigned long ul; /* Unsigned long value */
};
This union contains a float and an unsigned long in order to perform floating-point math operations and to respond to the IEEE error states.
For example:
#define NaN 0xFFFFFFFF /* Not a number (error) */
#define plusINF 0x7F800000 /* Positive overflow */
#define minusINF 0xFF800000 /* Negative overflow */
union f {
float f; /* Floating-point value */
unsigned long ul; /* Unsigned long value */
};
void main (void) {
float a, b;
union f x;
x.f = a * b;
if (x.ul == NaN || x.ul == plusINF || x.ul == minusINF) {
/* handle the error */
}
else {
/* result is correct */
}
}
Copyright (c) Keil Software, Inc. and Keil Elektronik GmbH. All rights reserved.
意法半导体(中国)投资有限公司
2020-01-15 广告
2020-01-15 广告
单片机(Microcontrollers)是一种集成电路芯片,是采用超大规模集成电路技术把具有数据处理能力的中央处理器CPU、随机存储器RAM、只读存储器ROM、多种I/O口和中断系统、定时器/计数器等功能(可能还包括显示驱动电路、脉宽调制...
点击进入详情页
本回答由意法半导体(中国)投资有限公司提供
展开全部
哎...不要动不动就说跪,好不好!年纪轻轻的,老是想着给人跪,不就是一个共用体的用法嘛,有那么夸张嘛,网上随便一搜就有大把,已经讲得很详细了,只要你用点心,就一定能掌握它的用法。哎...操弟要我怎么说你呢...十天学会单片机 不知你看的怎样了... 平时少看点那种片...不知十天还剩下几天...
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
使用共用体多数情况是为了灵活的访问自己所定义的变量。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
现在没有,有了一定告诉你的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询