Chapter cannot be written entirely in standard

Chapter4 TheC Programming basics: 1)Declarations: The ‘const’ and ‘volatile’ declarations are often critical,particularly to define SFRs.

Their address must be treated as a constant butthe contents are often volatile. ‘const’: It means that the value shouldnot be modified and that it is constant.’volatile’: It means that a variablemay appear to change “spontaneously”, with no direct action by the user’sprogram. The compiler neither therefore keep a copy of the variable in aregister for efficiency (like a cache) nor can assume that variable remainsconstant when it optimises the structure of a program. Ex: Rearranging theloops.

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!


order now

If the compiler did either of these, the program might miss externallyinduced changes to the contents of the memory associated with the variable.The Peripheral registers associatedwith the input ports should be treated as volatile in Embedded Systems. 2)Interrupts: An interrupt service routine cannot be written entirely instandard C because there is no way to identify it as an ISR rather than anordinary function. So it can never be called and compiler will optimize itaway. Therefore, to be recognized, twoadditions are needed to the ISR: i) #Pragma line: It associates thefunction with a particular interrupt vector. ii) __interrupt: This keyword should beat the beginning of the line that names the function. This ensures that theaddress of the function is stored in the vector and that the function ends withRETI rather than RET.

 3)Intrinsic Function: It is needed to set GIE bit and turnon interrupts. This is called __enable_interrupt (). It is declared inintrinsic.h, which must be included. Ex: __even_in_range (TAIV,10) tells thecompiler that TAIV can take only even values upto the 10 and encourages it to implementa more efficient jump table instead.

. 4)Masks to modify individual bits:  i) x | 0 =x   and  x|1=1 : Used for setting a bit.Taking OR of a bit with 0 leaves itsvalue unchanged while taking its OR with 1 sets it to 1. Ex: To set bit 3 of port i, we canwrite P1OUT=P1OUT|BIT3, this leaves the values of other bits unchanged.

It canbe written as, P1OUT |= BIT3. ii) x & 0 =0   and   x& 1=x : Used for clearing a bit after selecting.In this case, the mask should have allones except for the bit that we wish to clear after selecting , so use ~BIT3rather than BIT3 (~ is used for not). Ex: To clear BIT3 of port1, we can write:P1OUT  &=  ~BIT3. iii) Toggle of a particular bit:P1OUT^= BIT3 toggles  P1OUT.3 

x

Hi!
I'm Ruth!

Would you like to get a custom essay? How about receiving a customized one?

Check it out