• TwitterFacebookGoogle PlusLinkedInRSS FeedEmail

Mikroc Serial Interrupts

5/19/2018 

Interrupts are common features in almost all processor family, be it old 8051, AVR, PIC, ARM or the x86 used in desktops. So their in depth and clear knowledge is required for successful system software engineers. This guide will explain the interrupt system in general and their application using PIC18 architecture. We will also learn about handling of interrupts in HI-TECH C for PIC18. What are Interrupts?

Interrupts, as the name suggests interrupts the normal execution and Requests and urgent attention of CPU. Interrupts are situations that the CPU can’t predict when they will happen, they can happen any time, so the CPU does not wait for them. So the CPU keeps on doing its normal job unless and interrupt occurs. For example when the (Serial Communication Hardware) will receive data is unknown, it can receive data any time.

Mikroc For Avr

Interrupts can be easily handled by means of reserved words interrupt and iv. MikroC PRO for PIC implictly declares function interrupt which cannot be.

So the CPU keeps on doing its normal job, which may be for example read temperature using r and display on. The CPU keeps on doing the 'normal' job, but as soon as the USART receive data it informs the CPU using an interrupt. The CPU save its current state (so that it can resume), and jumps to the ISR (interrupt service routine) immediately.

Where we can process the command or put it in a FIFO queue (to process latter). The ISR is generally kept very small and fast.

As soon as the ISR ends, the CPU restores its saved state and resumes where it left. In this way CPU does not missed any data byte.

Keycraft Download Wc3 Frozen. Example of sources of Interrupts in PIC18 (also common in other MCUs) • External interrupts – they are named INTx (like INT0, INT1 etc), they provide a means for external hardware to generate interrupts. Like if you connect a touchscreen controller to your PIC MCU. Then the touchscreens PENINT (pen interrupt) can be connected to INT0 (or any other INTx). Then when ever the pen (or stylus) touches the screen it will interrupt the CPU. This interrupt will be explained in details in its own tutorial.

• TIMER interrupts – They are also very common in MCUs. Today’s MCUs comes with very sophisticated timers that can do lots of magic for you. They have they related interrupts. In most simple situation they can act like alarm clocks that can interrupt the CPU at predefined intervals. If you toggle a i/o pin in response to these alarms (interrupts), what you have is a frequency generator!. • Analog to Digital Converter Interrupts – A/D Converter takes some time to complete its operation.

So the CPU can either wait for it to complete or set up an AD conversion complete interrupt. In the latter case CPU can do other tasks while A/D converter converts the input. As soon as A/D converter completes its job it will inform CPU to read the value from its buffer.. • Data Interrupts – MCUs have many different types of data i/o engines, like USART, SPI, I2C, Parallel etc. They can also interrupt the CPU when data transmission is complete or data arrives from external source.

Like an RFID reader send a packet because a user just brought his or her card near the reader. Or the GSM module detected an incoming call. How interrupts are managed? In general each interrupt source have following related bits.

• Enable Bit – The are suffixed with IE (Interrupt Enable) example TMR0IE stands for TIMER0 Interrupt Enable. It can be used to enable/disable the related interrupt.

When set to ‘1’ it enables the interrupt. • Flag Bit – It is set automatically by the related hardware when the interrupt condition occurs. It is generally suffixed with IF (Interrupt Fag). When it is set to ‘1’ we know that interrupt has occurred. For example when TMR0IF is set by TIMER0, it indicates that TIMER0 has overflowed. • Priority Bit – We can leave this for now to keep things simple.