Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to store different values from a single variable into two variables

Status
Not open for further replies.

Brien Cheow

Newbie level 6
Joined
Apr 29, 2015
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
168
I need help on methods in which i can store 2 different values from my timer0 interrupt(number of overflows assigned to a single variable).
i have tried alot of different ways and i still cannot get it to work...
Please help me... Using Silicon Laboratory IDE interface.
 

bigdogguru

Administrator
Joined
Mar 12, 2010
Messages
9,831
Helped
2,348
Reputation
4,690
Reaction score
2,274
Trophy points
1,413
Location
Southwest, USA
Activity points
62,510
Can you elaborate with a more detailed example, it's a bit unclear as to what you are attempting to accomplish.

Perhaps a structure or union typedef maybe a possible solution.

BigDog
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
524
Trophy points
1,393
Activity points
0
I will give you example based on PIC.

Code:
unsigned int x = 0;

unsigned int x  = (TMR1H << 8) | TMR1L;
 

xenos

Full Member level 4
Joined
May 9, 2015
Messages
212
Helped
82
Reputation
164
Reaction score
81
Trophy points
28
Location
127.0.0.1
Activity points
1,182
Code:
unsigned x = ((unsigned)TMR1H)<<8 | TMR1L;

or

Code:
union {
          unsigned x;
          struct {
                 unsigned char lo,hi;
          } b;
} x;
x.b.lo = TMR1L;
x.b.hi = TMR1H;

Something like that?
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
524
Trophy points
1,393
Activity points
0
The title is wrong.

How to store different values from a single variable into two variables

It should be

How to store different values from two variables into a single variable.
 

Brien Cheow

Newbie level 6
Joined
Apr 29, 2015
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
168
i dont really understand the mechanics of how to use union guys and milan the title is correct what i am trying to achieve here is to get the number of overflows at different intervals from my timer interrupt.
Code:
void timer0_interrupt_init()
{
    TMOD = 0x01;
  //  TR0 = 0;
    //TL0 = 0xEF; 
	//TH0 = 0xD8; 
	TR0 = 1;
    EA = 1;
    ET0 = 1;
   
 //  while(TF0==0);

   //TF0 = 0;
 
  
}

void timer0 (void) interrupt 1
{ 
   
  
    s++;
 // sp = &s;
    TL0 = 0xEF; //lower bit
	TH0 = 0xD8; //higher bit
    TF0 = 0;

	
}
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
524
Trophy points
1,393
Activity points
0
If you want to move TH0 and TL0 into one variable then you have to do like this.

Code:
unsigned int x = 0;

x  = (unsigned int)(TMR1H << 8) | TMR1L;
 

Brien Cheow

Newbie level 6
Joined
Apr 29, 2015
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
168
Milan again i am not trying to fuse anything ,instead what i want to do is get the int value s at different intervals and store it.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top