Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

C18 Byte Structure

Status
Not open for further replies.

AtomSoft

Well-Known Member
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:
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:
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
 
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!
 
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
 
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:
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 was thinking you should be able to so I looked around
**broken link removed**
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.

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. :)
 
Last edited:
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.
 
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:
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:
forgot to say i used 3v0 link NICE! thx and Beebop thx for link im reading it now :D i know what a delay lol thanks guys you all rock!
 
Last edited:
HEH :D this is a sample of how im using it:
Code:
#include <p18f4620.h>

#pragma config OSC = INTIO67
#pragma config PWRT = OFF, BOREN = OFF, BORV = 1
#pragma config WDT = OFF, WDTPS = 32768
#pragma config MCLRE = ON

union {
  unsigned char byte;
  struct {
    unsigned di:1;      //	Data/Instruction
    unsigned rw:1;      //	Read/Write
    unsigned cs1:1;     //	Chip Select 1
    unsigned cs2:1;     //	Chip Select 2
    unsigned reset:1;   //	Reset
    unsigned dumba:1;   //	3 Dummy fillers: dumb(a,b,c)
    unsigned dumbb:1;
    unsigned dumbc:1;
  };
} glcd;

void main (void)
{

	OSCCON = 0x72;              //	8 MHz internal clock
	OSCTUNEbits.PLLEN=1;        //	Enable PLL 8 x 4(PLL) = 32 MHz
	while(!OSCCONbits.IOFS);    //	Wait for osc to be stable

	while(1){
		glcd.di = 1;
		glcd.rw = 1;
		glcd.cs1 = 0;
		glcd.cs2 = 1;
		glcd.reset = 1;
	}
}
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top