sssssssss
DESCRIPTION
ssssssfgvgvh bjbhvvjbTRANSCRIPT
![Page 1: sssssssss](https://reader033.vdocuments.mx/reader033/viewer/2022061606/568c35641a28ab023594107b/html5/thumbnails/1.jpg)
Session2 – CECE Electronics Team
![Page 2: sssssssss](https://reader033.vdocuments.mx/reader033/viewer/2022061606/568c35641a28ab023594107b/html5/thumbnails/2.jpg)
Session 1.
Assignment.
I/O Ports.
![Page 3: sssssssss](https://reader033.vdocuments.mx/reader033/viewer/2022061606/568c35641a28ab023594107b/html5/thumbnails/3.jpg)
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](https://reader033.vdocuments.mx/reader033/viewer/2022061606/568c35641a28ab023594107b/html5/thumbnails/4.jpg)
![Page 5: sssssssss](https://reader033.vdocuments.mx/reader033/viewer/2022061606/568c35641a28ab023594107b/html5/thumbnails/5.jpg)
![Page 6: sssssssss](https://reader033.vdocuments.mx/reader033/viewer/2022061606/568c35641a28ab023594107b/html5/thumbnails/6.jpg)
![Page 7: sssssssss](https://reader033.vdocuments.mx/reader033/viewer/2022061606/568c35641a28ab023594107b/html5/thumbnails/7.jpg)
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](https://reader033.vdocuments.mx/reader033/viewer/2022061606/568c35641a28ab023594107b/html5/thumbnails/8.jpg)
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](https://reader033.vdocuments.mx/reader033/viewer/2022061606/568c35641a28ab023594107b/html5/thumbnails/9.jpg)
do
{
kp=0;
kp= Keypad_Key_Click();
}while (!kp);
switch (kp) {
case 1: kp = 49; break; // 1
………… and so on
![Page 10: sssssssss](https://reader033.vdocuments.mx/reader033/viewer/2022061606/568c35641a28ab023594107b/html5/thumbnails/10.jpg)
![Page 11: sssssssss](https://reader033.vdocuments.mx/reader033/viewer/2022061606/568c35641a28ab023594107b/html5/thumbnails/11.jpg)
![Page 12: sssssssss](https://reader033.vdocuments.mx/reader033/viewer/2022061606/568c35641a28ab023594107b/html5/thumbnails/12.jpg)
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](https://reader033.vdocuments.mx/reader033/viewer/2022061606/568c35641a28ab023594107b/html5/thumbnails/13.jpg)
![Page 14: sssssssss](https://reader033.vdocuments.mx/reader033/viewer/2022061606/568c35641a28ab023594107b/html5/thumbnails/14.jpg)
Keypad with LCD Dual Segment
![Page 15: sssssssss](https://reader033.vdocuments.mx/reader033/viewer/2022061606/568c35641a28ab023594107b/html5/thumbnails/15.jpg)
![Page 16: sssssssss](https://reader033.vdocuments.mx/reader033/viewer/2022061606/568c35641a28ab023594107b/html5/thumbnails/16.jpg)
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](https://reader033.vdocuments.mx/reader033/viewer/2022061606/568c35641a28ab023594107b/html5/thumbnails/17.jpg)
![Page 18: sssssssss](https://reader033.vdocuments.mx/reader033/viewer/2022061606/568c35641a28ab023594107b/html5/thumbnails/18.jpg)
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](https://reader033.vdocuments.mx/reader033/viewer/2022061606/568c35641a28ab023594107b/html5/thumbnails/19.jpg)
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](https://reader033.vdocuments.mx/reader033/viewer/2022061606/568c35641a28ab023594107b/html5/thumbnails/20.jpg)
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](https://reader033.vdocuments.mx/reader033/viewer/2022061606/568c35641a28ab023594107b/html5/thumbnails/21.jpg)
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](https://reader033.vdocuments.mx/reader033/viewer/2022061606/568c35641a28ab023594107b/html5/thumbnails/22.jpg)
![Page 23: sssssssss](https://reader033.vdocuments.mx/reader033/viewer/2022061606/568c35641a28ab023594107b/html5/thumbnails/23.jpg)
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](https://reader033.vdocuments.mx/reader033/viewer/2022061606/568c35641a28ab023594107b/html5/thumbnails/24.jpg)
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](https://reader033.vdocuments.mx/reader033/viewer/2022061606/568c35641a28ab023594107b/html5/thumbnails/25.jpg)
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](https://reader033.vdocuments.mx/reader033/viewer/2022061606/568c35641a28ab023594107b/html5/thumbnails/26.jpg)
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](https://reader033.vdocuments.mx/reader033/viewer/2022061606/568c35641a28ab023594107b/html5/thumbnails/27.jpg)
![Page 28: sssssssss](https://reader033.vdocuments.mx/reader033/viewer/2022061606/568c35641a28ab023594107b/html5/thumbnails/28.jpg)