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
   33   34   35   36   37   38   39   40   41   42   43