Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 26th November 2008, 12:42 AM   #1
Default C18 Byte Structure

Hey all i wanted to know something....

You know how you can Set a Byte or better yet PORT and then set individual bits like

LATA = 0x01;

or just

LATAbits.LATA0 = 1;

How can i create my own varriable like that?

If i wanted to name it... MyCon

and use it like :

MyCon = 0x01;
MyConbits.Con0 = 1;

How can i do that/this?

Im going to look through the headers and see if i can figure it out but if anyone knows off the top of head plz & thanks

Last edited by AtomSoft; 26th November 2008 at 12:42 AM.
AtomSoft is offline  
Old 26th November 2008, 12:46 AM   #2
Default

Would i have to make:

Code:
extern volatile near unsigned char       MYCON;
extern volatile near union {
  struct {
    unsigned CON0:1;
    unsigned CON1:1;
    unsigned CON2:1;
    unsigned CON3:1;
    unsigned CON4:1;
    unsigned CON5:1;
    unsigned CON6:1;
    unsigned CON7:1;
  };
} MYCONbits;
And add structures to better name it if wanted; like If they had multiple purposes.

Got It:

Code:
union{
  unsigned char mycon;
  struct {
      unsigned CON0:1;
      unsigned CON1:1;
      unsigned CON2:1;
      unsigned CON3:1;
      unsigned CON4:1;
      unsigned CON5:1;
      unsigned CON6:1;
      unsigned CON7:1;
  };
} MYCON;

then

#define MyCon MYCON

Last edited by AtomSoft; 26th November 2008 at 12:25 PM.
AtomSoft is offline  
Old 26th November 2008, 05:14 PM   #3
Default

The use of MyCon MYCON and mycon in your example is a potential source of confusion.

Here is an example from my code for LCD handling.
Code:
union {
  unsigned int all; 
  struct {
    unsigned reset:1;
    unsigned rs:1;
    unsigned rw:1;
    unsigned enable:1;
    unsigned data:8;
  } bits;
} lcd;

...
  lcd.all <<= 1;          // shift entire lcd
  lcd.bits.reset = 1;     // set reset bit
  lcd.bits.enable = 0;    // clear enable bit
or if you want to use an unnamed struct instead of bits

Code:
union {
  unsigned int all; 
  struct {
    unsigned reset:1;
    unsigned rs:1;
    unsigned rw:1;
    unsigned enable:1;
    unsigned data:8;
  };
} lcd;
...
  lcd.all <<= 1;     // shift entire lcd
  lcd.reset = 1;     // set reset bit
  lcd.enable = 0;    // clear enable 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)
3v0 is offline  
Old 26th November 2008, 05:43 PM   #4
Default

Awesome!!!!

I wanted this for my GLCD actually because i will be using 2 shift registers 1 for data and 1 for control lines. And i wanted to make a structure i can set easily and just shift out afterward to avoid confusion.

Thanks again!
AtomSoft is offline  
Old 26th November 2008, 06:10 PM   #5
Default

Glad to help.

I have yet to play with the GLCD's. Is there a reason you do use a single shift register for both?

3v0
__________________
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)
3v0 is offline  
Old 26th November 2008, 06:41 PM   #6
Default

The GLCD i use is Parallel and has about 13 lines which need to goto the PIC. I use 2 8 bits and have some unused but its better than 13 used pic pins.

It will cost 4 pins to use the 2 registers but i save like 9 pins then which is very good to me lol

GLCDs are fun but getting an image on them is a hassle. I think a TFT LCD would be simpler lol
AtomSoft is offline  
Old 26th November 2008, 07:17 PM   #7
Default

Im Using a AGM1264F which has a ks0108 on it. I think 2 one for left side and one for the right side.
OFF TOPIC:
Damn i think i got a virus. Im going to be gone for some hours (going to reinstall windows). Hopefully i dont forget to re-install something needed

Last edited by AtomSoft; 26th November 2008 at 07:18 PM.
AtomSoft is offline  
Old 26th November 2008, 07:33 PM   #8
Default

What shift registers are you using. Most often I use 74xx595's which can be cascaded. Without any trickery to reduce the number of lines it looks like this.
Attached Files
File Type: pdf BB2.1C.pdf (15.2 KB, 29 views)
__________________
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)
3v0 is offline  
Old 27th November 2008, 01:23 AM   #9
Default

Im using SN74LS164's and from what i can tell i cant link them. I just came home and finished reinstalling almost everything i have to reinstall adobe acrobat so i cant see that PDf as of yet but will soon.
AtomSoft is offline  
Old 27th November 2008, 01:43 AM   #10
Default

I was thinking you should be able to so I looked around
EE Design - Technical - Expanding Outputs using the 74LS164 Shift Register
Quote:
To cascade more 74164 shift register IC, you will need to connect the last output (QH) to the 'B' input of the second 74164 shift register IC. Now, it is necessary to shift 16 times before you get a valid output. In this case, all the clock pins are tied together in the same line.
Quote:
Originally Posted by AtomSoft View Post
Im using SN74LS164's and from what i can tell i cant link them. I just came home and finished reinstalling almost everything i have to reinstall adobe acrobat so i cant see that PDf as of yet but will soon.
I use the 595's out of habit. You can find versions with higher source/sink capacity but I do not recall the number right now.

EDIT: I could have posted the eagle file and saved you system reloading work.
__________________
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; 27th November 2008 at 01:44 AM.
3v0 is offline  
Old 27th November 2008, 05:25 AM   #11
Default

Im using SN74LS164's and from what i can tell i cant link them. I just came home and finished reinstalling almost everything i have to reinstall adobe acrobat so i cant see that PDf as of yet but will soon.
AtomSoft is offline  
Old 27th November 2008, 07:35 PM   #12
Default

Quote:
Originally Posted by AtomSoft View Post
Im using SN74LS164's and from what i can tell i cant link them. I just came home and finished reinstalling almost everything i have to reinstall adobe acrobat so i cant see that PDf as of yet but will soon.
I'm sure you can, and rather than search through everything try this.
From the link 3v0 gave you:
Quote:
To cascade more 74164 shift register IC, you will need to connect the last output (QH) to the 'B' input of the second 74164 shift register IC. Now, it is necessary to shift 16 times before you get a valid output. In this case, all the clock pins are tied togather in the same line.
perhaps, too, this will be of some help:

The Quintessential PIC Microcontroller

how to connect 74ls164 chips in cascade for running leds schematics

Last edited by BeeBop; 27th November 2008 at 07:37 PM. Reason: link added
BeeBop is offline  
Old 28th November 2008, 12:34 AM   #13
Default

Wow thanks! Im having some huge ISP issues right now. Ill have to read it in a minute. Thanks again
AtomSoft is offline  
Old 8th December 2008, 04:23 AM   #14
Default

forgot to say i used 3v0 link NICE! thx and Beebop thx for link im reading it now i know what a delay lol thanks guys you all rock!

Last edited by AtomSoft; 8th December 2008 at 04:23 AM.
AtomSoft is offline  
Old 8th December 2008, 07:29 AM   #15
Default

Quote:
Originally Posted by AtomSoft View Post
forgot to say i used 3v0 link NICE! thx and Beebop thx for link im reading it now i know what a delay lol thanks guys you all rock!
Takes one to know one!
BeeBop is offline  
Reply

Tags
byte, c18, structure

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
LCD+keypad interface -> menu structure. Concepts sought. Assembly. PIC. astronomerroyal Micro Controllers 23 29th August 2008 04:59 AM
Urgent help needed ! Structure for project rngd General Electronics Chat 7 8th March 2008 06:20 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



All times are GMT. The time now is 03:02 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker