sssssssss

28
Session2 CECE Electronics Team

Upload: zeiad-zaf

Post on 19-Mar-2016

239 views

Category:

Documents


1 download

DESCRIPTION

ssssssfgvgvh bjbhvvjb

TRANSCRIPT

Page 1: sssssssss

Session2 – CECE Electronics Team

Page 2: sssssssss

Session 1.

Assignment.

I/O Ports.

Page 3: sssssssss

Key pa d i n te r fa c in g .

L c d i n te r fa c in g .

Interrupt.

Page 4: sssssssss
Page 5: sssssssss
Page 6: sssssssss
Page 7: sssssssss

Libraries Routines:

Keypad_Init : Initializes port for working with keypad.

char keypadPort at PORTD; //Definition

Keypad_Init(); // Call function

Keypad_Key_Press : Reads the key from keypad when key

gets pressed.

Page 8: sssssssss

Return: The code of a pressed key (1..16).

If no key is pressed, returns 0.

char kp;

kp = Keypad_Key_Press();

Keypad_Key_Click : the function waits until some key is

pressed and released. When released, the function returns

1 to 16, depending on the key.

char kp;

kp = Keypad_Key_Click();

Page 9: sssssssss

do

{

kp=0;

kp= Keypad_Key_Click();

}while (!kp);

switch (kp) {

case 1: kp = 49; break; // 1

………… and so on

Page 10: sssssssss
Page 11: sssssssss
Page 12: sssssssss

Lcd_Init : Initializes Lcd module.

Lcd_Out : Prints text on Lcd starting from specified position.

Both string variables and literals can be passed as a text.

Lcd_Init();

Lcd_Out(1, 3, "Hello!");

Lcd_Chr : Prints character on Lcd at specified position. Both

variables and literals can be passed as a character.

Lcd_Chr(2, 3, 'i');

Page 13: sssssssss
Page 14: sssssssss

Keypad with LCD Dual Segment

Page 15: sssssssss
Page 16: sssssssss

Definition:

An interrupt is an asynchronous signal indicate for an event which

needs processor’s attention immediately regardless to the instruction it

executes at this moment.

It’s like a Doorbell.

CECE Academic Team

Page 17: sssssssss
Page 18: sssssssss

Interrupt Flag (IF):

A bit that is automatically set if the interrupt source (event)

happens.

Global Interrupt Enable (GIE):

Enables (if set) all un-masked interrupts (interrupts with

IE=1) or disables (if cleared) all interrupts.

Interrupt Enable (IE):

If the GIE was ‘1’, this bit forces the CPU to respond to the

interrupt signal when IF=1 when the waited event happens.

Page 19: sssssssss

Interrupt service routine (ISR):

The code which the CPU jumps to when an interrupt

happens.

Actually, the CPU will automatically jumps to the (interrupt

vector) 0004h.

From there the code should be written to force the MCU to

jump to the ISR address.

Page 20: sssssssss

When the event (interrupt source) happens, the following

steps happen:

The corresponding interrupt flag (IF) will equal ‘1’.

If the interrupt enable (IE)was ‘1’, and the global interrupt

enable (GIE)was ‘1’ also, the GIE is cleared by hardware to

disable any further interrupt . To avoid responding to further

interrupts.

The return address is pushed into the stack and the PC is

loaded with 0004h (the interrupt vector).

Page 21: sssssssss

In the ISR, you can determine the source of interrupt by

polling the interrupt flag bits and do the required action for

it.

(Context Switching) You have to save key registers values

before interrupt has happened e.g. W register and STATUS

register. This has to be implemented in software

If you use high level language the compiler will do it for you.

In the end of the ISR, you’ve to clear the IF in software then

set the GIE bit in the end of the ISR code.

Page 22: sssssssss
Page 23: sssssssss

Many peripherals use interrupts when finishing its job (ex.

USART, ADC, Timers …), or when there is a problem needs

to be configured (ex. EEPROM Write Complete ).

Here, we’ll talk about the simplest type of interrupt, and the

rest of interrupt sources should be handled in the same

way.

Very important :

If you configure the MCU to respond to more than one

interrupt source at the same time, to determine which one

has happened, pull their flags in the ISR (check which one

equals 1).

Page 24: sssssssss

RB0/INT

The RB0/INT pin is a single external interrupt source.

When the waited edge (+ve or –ve edge as selected)

happens on RB0 pin, the interrupt signal is generated.

It can be configured to react to signal raising edge or signal

falling edge.

Page 25: sssssssss

Steps :

Configure the interrupt source to work as you want, here :

falling or rising edge.

Set the GIE bit.

Set the IE bit of the interrupt.

Write the ISR.

Page 26: sssssssss

CECEAcademic Team

void main( ) {

INTCON.GIE=1;

INTCON.INTE=1;

trisc=0;

portc=0;

while(1);

}

void interrupt( ) {

INTCON.GIE=0;

INTCON.INTF=0;

portc.f0=1;

delay_ms(500);

portc.f0=0;

delay_ms(500)

}

Page 27: sssssssss
Page 28: sssssssss