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.
 

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
 

I will give you example based on PIC.

Code:
unsigned int x = 0;

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

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?
 

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.
 

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;

	
}
 

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;
 

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.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…