![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #16 |
|
heh i know im not the only one that helped but your welcome
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics | |
| |
| | #17 |
|
Hi 3v0, Thanks to your example (and patience) I think I figured it out and I'm able to keep my original BoostC variable names and macro names. Thank you. Thank you all for the fine examples. I learned a lot from all of them. Kind regards, Mike Code: typedef union
{ struct
{ unsigned b0:1;
unsigned b1:1;
unsigned b2:1;
unsigned b3:1;
unsigned b4:1;
unsigned b5:1;
unsigned b6:1;
unsigned b7:1;
};
struct
{ unsigned asbyte:8;
};
} bitbyte;
bitbyte x;
#define flags x.asbyte // switch flag bits
#define RunSw x.b0 // Motor on/off switch on RC0 (flags.b0)
#define DirSw x.b2 // Motor fwd/rev switch on RC2 (flags.b2)
while(1)
{ if(RunSw) // if "Run" switch press
{ RunSw = 0; // clear switch flag bit
MotorOn ^= 1; // toggle motor on/off pin
}
}
Last edited by Mike, K8LH; 6th July 2009 at 12:34 PM. | |
| |
| | #18 |
|
Nice! Ill be sure to Add a section for structures in the C18 TIPS & TRICKS v10 PDF
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics | |
| |
| | #19 |
|
If one used struct's to define the bits and coded using the struct members, it should work on both compilers. This allows one to avoid the boostC name.bit.
__________________ Please post questions to the forums. PM's are for personal communication. BCHS/3v0's Tutorials Junebug USB PIC programmer kit., USB Bit Whacker, The 15 Minute Printed Circuit Board! (+drill time) Last edited by 3v0; 5th July 2009 at 05:01 PM. | |
| |
| | #20 |
|
Yeah, I'm lookin' into that right now. Trying the following to access bits as sw.Run, sw.Jog, sw.Dir, and byte-wide access as sw.flags for parallel switch logic in ISR. I suppose I could get used to doing it this way, if I have to (grin). Regards, Mike Code: typedef union
{ struct
{ unsigned Run:1; // Run switch flag (sw on RC0)
unsigned Jog:1; // Jog switch flag (sw on RC1)
unsigned Dir:1; // Dir switch flag (sw on RC2)
unsigned unused:5; // spare/unused bits
};
struct
{ unsigned flags:8; // byte wide flag access
};
} bitbyte;
bitbyte sw;
Last edited by Mike, K8LH; 6th July 2009 at 12:35 PM. | |
| |
|
| Tags |
| bits, c18, structure |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| C18 Byte Structure | AtomSoft | Micro Controllers | 15 | 8th December 2008 02:07 PM |
| Structure of resistor question | jasonbe | Electronic Theory | 25 | 3rd December 2008 05:40 PM |
| Programming structure in C | demestav | Micro Controllers | 8 | 12th May 2007 04:37 AM |
| How to initialize CCS static structure | janetsmith2000@yahoo.com | Micro Controllers | 1 | 6th March 2004 04:09 PM |
| Basic structure | Win32_under_the_API | Micro Controllers | 1 | 2nd September 2003 05:13 PM |