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

📄 union_1.c

📁 Low End Microchip PICs C函数
💻 C
字号:
// Program UNION_1.C
//
// Illustrates the use of a union to such that a long and two bytes share
// the same memory space.
//
// Peter H. Anderson, Baltimore, MD, Jan, '01

#case

#device PIC16F877 *=16 ICD=TRUE

#include <defs_877.h>
#include <lcd_out.h>

#define TRUE !0
#define FALSE 0

struct TWO_BYTES
{
	byte l;
	byte h;
};

union LONG
{
	unsigned long w;
	struct TWO_BYTES b;
};

unsigned long make_ad_meas(void);

void main(void)
{

   union LONG adval;
   lcd_init();
   adval.b.h = 0x01;
   adval.b.l = 0x80;
   printf(lcd_char, "%lx", adval.w);

   adval.w = make_ad_meas();
   lcd_clr_line(1);
   printf(lcd_char, "%lx", adval.w);
   while(1)		/* loop continually */	;
}

unsigned long make_ad_meas(void)
{
   union LONG x;
   x.b.h = 0x02;
   x.b.l = 0x80;
   return(x.w);
}

#include <lcd_out.c>



⌨️ 快捷键说明

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