Page 38 - PIC18F4550微處理機C語言設計實務
P. 38
PIC18F4550 ฆஈଣዚ C ႧԊணࠇྼਕ
Էνj
bit global_flag; /* Όਹᜊᅰ */
static bit flag; /* ᎑࿒ᜊᅰ */
܁ѓʘܝఱ̙˸ٜટᜊᅰԴ͜f
global_flag = 0; // ਗ਼ global_flag வࡈ bit ৰމ 0
global_flag = 1; // ਗ਼ global_flag வࡈ bit ணމ 1
/* ν؈ global_flag މॆdڌͪഃ 1dۆnnn*/
if (global_flag)
{...............................}
■ 結構中的位元變數
ഐ̙˸ҪʔΝۨ࿒ٙᜊᅰණΥϓɓࡈഐۨ࿒d್வᗙܸٙʔΝۨ࿒ٙᜊᅰ
ɰ̍ўəЗʩᜊᅰf܁ѓɓࡈᜊᅰމ̍ўЗʩٙഐۨ࿒ࣛdఱ̙˸л͜ഐᜊ
ᅰΤ၈ h ЗʩϓࡰԸπ՟Չʕܸ֛ٙЗʩf
Էνj
struct Byte_Struct ഐΤ၈
{
unsigned flag0:1;
unsigned flag1:1;
unsigned count:4; ഐϓࡰ
unsigned :2;
}stByte @ 0x10; ഐᜊᅰ
unsigned flag0:1; 㚬 ڌͪ flag0 ЦəɓࡈЗʩf
unsigned flag1:1; 㚬 ڌͪ flag1 ЦəɓࡈЗʩf
unsigned count:4; 㚬 ڌͪ count Цə̬ࡈЗʩf
unsigned :2; 㚬 ڌͪϞՇࡈЗʩӚϞ܁ѓᜊᅰf
stByte @ 0x10; 㚬 @ ܸ֛݊Դ͜াኳЗѧٙจ່dจу stByte வࡈഐᜊ
ᅰٙࣸό݊ୌΥ Byte_Struct ה܁ѓٙࣸόdഐᜊᅰٙΤ၈݊ stBytedவ stByte
ᜊᅰ̕͜ɓࡈЗʩଡ଼d੶ࠗԴ͜ (@)0x10 ЗѧԸπ՟f
π՟˙όމ
stByte.flag0 = 0; // ̥ϞɓࡈЗʩdה˸̥Ϟ 0 ၾ 1
stByte.flag1 = 1;
stByte.count = 4; // Цə̬ࡈЗʩdᇍఖމ 0 Ց 15f
28