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
Bit7MSB Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0LSB
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