Continue to Site

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.

Basic Bit operations in MikroC

Status
Not open for further replies.

tyassin

Advanced Member level 1
Joined
Jul 22, 2004
Messages
467
Helped
86
Reputation
170
Reaction score
41
Trophy points
1,308
Activity points
3,804
Hi

I am new to PICs and MikroC. I think I have a really easy question.
Here it goes:

Lets say you have a variable of the type int with a value of variable=0b0000000011111111 and you assign this to a SFR which is 8-bit.
As an example:

Code:
CCP1CON =variable


What happens now? Will the CCP1CON register contain all zeroes og ones ie. the MSBs or the LSBs of the variable.

Another case is when something like this is written:

Code:
CCP1CON.F4=variable


Is it the LSB in the variable that is wirtten to the 5-bit in the CCP1CON register?

A last question is what is the difference between:
CCP1CON.F4 and CCP1CON.B4

Thank you
 

Hi,
That's a very good question.
I think the CCP1CON register will contain 255.
I think the LSB will be written.
I think the .F4 is same as .B4.

Just to be sure, why don't you try these out yourself. MikroC has a simulator in it with which you can check the values of registers, so you could give it a shot.

Hope this helps.
Tahmid.
 

Dear Friend

there's no difference between .F4 and .B4
you can use any of them
second option is with _bit ie TMR1IF_bit for Timer1 interrupt flag bit
i could not find the use of sending 16 bit integer value to the 8 bit register.
if you do so, the lsb(8 bits) of the integer will be copied to the register

hope this will help you

another thing what you can do is that you write the program and compile it
run the debugger in step mode
you can see the changes happened in the registers after each step. this will clear your doubts well


regards

ml
 

Yes I think I will start up MikroC and begin working

The reason for these question is the need for 10-bit resoluation on the PWM duty cycle. I found some libraries on the MikroE forum. One guy made a library which was quite lenghty. Another guy made what seemed to be really compact code, doing exactly the same.

Here is his code:

Code:
void PWM1_10bit(int duty_ratio) 
{
      CCPR1L = duty_ratio >> 2;
      CCP1CON.F4 = duty_ratio;
      CCP1CON.F5 = duty_ratio >> 1;
}

Thank you for your help
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top