Page 39 - PIC18F4550微處理機C語言設計實務
P. 39

૵ሔଡ଼ΥႧԊձ C ႧԊ 1




                       ҢࡁΎл͜ɓࡈഐ࿴ۨ࿒ၾ΍ۨ͜࿒ΥԻԴٙ͜ᇍԷdᜫᛘ٫ঐ੄නکə༆Зʩ
                 ᜊᅰί዆᜗ഐ࿴ʕাኳ᜗π׳ٙᗫڷf

                 Էνj

                   union
                   {
                       unsigned char allbyte;
                       struct
                       {
                           unsigned flag0:1;      //  bit0
                           unsigned flag1:1;      //  bit1
                           unsigned count:3;     //  bit2~bit4
                           unsigned :3;          //  bit5~bit7
                       }bits;
                   }byte_member;


                                ӚϞ܁ѓ                            count               ag1         ag0
                       
                     Bit7€MSB        Bit6     Bit5     Bit4     Bit3     Bit2     Bit1     Bit0€LSB
                    
                                                            allbyte

                       ν؈ࠅπ՟዆ࡈ Byte ۆ̙˸Դ͜ byte_member.allbyte ਂᛘᄳd߰ࠅπ՟຅ʕٙዹ

                 ͭٙ bitdԷν bit0 ۆԴ͜ byte_member.bits.flag0 ਂᛘᄳf

                       ɓছЗʩᜊᅰၾഒ࿁ЗѧᜊᅰΥࣛ͜dɽ௅ʱ݊͜Ը່֛ PIC ʫ௅तࣿᅲπኜ
                 €SFRٙዹͭЗʩfЗʩ֛ѧٙৎ֐Зѧމ 0dϘಂ܁ѓٙ˙جމ€FSR ٙЗѧ
                 *8bits+ ਋୅ЗʩdШ݊ܝಂ XC8 ٙو͉ۆܔᙄԴ͜ഐ࿴ЗʩԸԴ͜f


                 Էνj

                   /* PORTA ֛ѧ܁ѓ */
                   extern volatile unsigned char PORTA @ 0xF80;
                   ܁ѓ PORTA Зໄ݊ί 0xF80
                   /* PORTA Зʩ܁ѓ */
                   typedef union {
                       struct {
                           unsigned RA0:1;
                           unsigned RA1:1;
                           unsigned RA2:1;
                           unsigned RA3:1;
                           unsigned RA4:1;
                           unsigned RA5:1;

                                                                                                             29
   34   35   36   37   38   39   40   41   42   43   44