Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 15

Advanced programming techniques with Embedded C

1/10/2012

Microcontroller 8051

Interrupts
The C51 compiler provides a method of calling a C function when an interrupt occurs This support allows you to create interrupt service routines in C The compiler automatically generates the interrupt vector and entry and exit code for the interrupt routine

1/10/2012

Microcontroller 8051

Interrupts
The interrupt function attribute, when included in a declaration, specifies that the associated function is an interrupt function The interrupt number and the register bank are specified Additionally, you can specify the register bank used for that interrupt with the using function attribute
1/10/2012 Microcontroller 8051 3

Interrupts

1/10/2012

Microcontroller 8051

Example
unsigned int interruptcnt; unsigned char second; void timer0 (void) interrupt 1 using 2 { if (++interruptcnt == 4000) { /* count to 4000 */ second++; interruptcnt = 0; }
1/10/2012 Microcontroller 8051 5

/* second counter */ /* clear int counter */

Intrinsic Library Routines


The libraries included with the compiler include a number of routines that are implemented as intrinsic functions NonNon-intrinsic functions generate ACALL or LCALL instructions to perform the library routine Intrinsic functions generate in-line code (which inis faster and more efficient) to perform the library routine
1/10/2012 Microcontroller 8051 6

Intrinsic Function Description


_crol_
_cror_ _irol_ _iror_ _lrol_ _lror_ _nop_ _testbit_ Rotate character left Rotate character right Rotate integer left Rotate integer right Rotate long integer left Rotate long integer right No operation (8051 NOP instruction) Test and clear bit (8051 JBC instruction)
Microcontroller 8051 7

1/10/2012

In-line assembly
>ASM and ENDASM directives are used along with #pragma directives.

1/10/2012

Microcontroller 8051

Generating assembly source file

>#pragama src directive is used to generate assembly code for C program.

1/10/2012

Microcontroller 8051

Disabling interrupts
#pragma disable This directive instructs the compiler to disable the interrupt for the duration of the function.

1/10/2012

Microcontroller 8051

10

Function parameters
By default c functions pass up to three parameters in registers,the remaining in fixed memory locations. Parameter passing in registers can be disabled by calling #pragma NOREGPARMS.

1/10/2012

Microcontroller 8051

11

Function parameters

1/10/2012

Microcontroller 8051

12

1/10/2012

Microcontroller 8051

13

Return values

1/10/2012

Microcontroller 8051

14

I request Electronics and communication ENGINEERING students to visit my blog for more abhishek1ek.blogspot.com awhengineering.blogspot.com THANK YOU
1/10/2012 Microcontroller 8051 15

You might also like