NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

Experiment 6

Interrupt

part1:External Interrupt INT0
-------
ISIS:
RB0:switch to VCC then 10K to gnd
RB7:led to res=220 to gnd
RC0:switch to VCC then 10K to gnd
RD0: led to res=330 to gnd
------
code :

#include "ee445.h"
#define led PORTBbits.RB7
void interrupt high_priority chk_isr (void)
{
if (INT0IF==1) {
led=~led;
INT0IF=0;
}
}
void main(void)
{
OSCCON=0x70;
TRISC0=1; TRISD0=0;
TRISB7=0;
TRISB0=1;
INT0IF=0;
INT0IE=1;
INTEDG0=1;
GIE=1;
while(1) {RD0=RC0;}
}
##############
part2:External Interrupt INT2
to Measure On and OFF Times
of a Square Wave

-----------
ISIS:
pin 25: virtual terminal
pin 20:led to res=330 to gnd
pin 35: switch to VCC to 10K to gnd
---------
code :
#include "ee470.h"
unsigned int NTO,NticksH, NticksP;
unsigned char NTOH, NTOP, pass;
void interrupt high_priority measure_time(void)
{
if (TMR0IF==1) { NTO++; TMR0IF=0;}
if (INT2IF==1)
{
INT2IF=0;
switch(pass) {
case 1:
TMR0H=0; TMR0L=0;
15 NTO=0;
16 RD1=1;
17 printf("Start of Period ON");
18 pass=2;
19 INTEDG2=0;
20 break;
21 case 2:
22 NTOH=NTO;
23 RD1=0;
26 NticksH=TMR0L;
27 NticksH +=(TMR0H<<8);
28 pass=3;
29 INTEDG2=1;
30 break;
31 case 3:
32 NTOP=NTO;
33 RD1=1;
34 NticksP=TMR0L;
35 NticksP |=(TMR0H<<8);
36 printf("Done with one periodrn");
37 printf("ON Time for the switch=%g seconds, ON+OFF Times for the switch=%g seconds,rn",
38 (8.3886*NTOH+NticksH*256.0*(0.5e-6)),(8.3886*NTOP+NticksP*256.0*0.5e-6));
39 pass=1;
40 break;
41 }
42 }
43 }
44
45 void main(void)
46 {
47 OSCCON=0x70;
48 ADCON1=0xF;
49 serial_init(51,1);
50 TRISC6=0;
51 TRISB2=1;
52 TRISD1=0;
53 IPEN=0;
54 T0CON=0b00000111;
55 TMR0IF=0; TMR0IE=1;
56 INT2IF=0;
57 INT2IE=1;
58 INTEDG2=1;
59 GIE=1;
60 pass=1;
61 RD1=0;
62 TMR0ON=1;
63 while(1) {;}
64 }
############
part3:Timers Interrupts

------------
ISIS:
pin34: led to res=330 to gnd
pin40:led to res=330 to gnd

RC0 to RC7:to DSW(douple switch)
and the other hand pin to gnd
and between RC and DSW there are
RESpack(pin1 to VCC ,pin2 to 26RC7 ...pin9 to 15RC0)

RD0 to RD7 : bargraph(pin 9&10 out)
to respack (pin 11 to gnd)
-----------
code :

2 #include "ee445.h"
3 #define SWL PORTBbits.RB1
4 #define LEDL PORTBbits.RB7
5 // high priority starts from program memory location 0x8
6 void interrupt high_priority INT_TMR0_or_TMR1(void)
7 {
8 if (INTCONbits.TMR0IF==1)
9 {
10 SWL=~SWL;
11 TMR0H=64536>>8; TMR0L=64536&0x00FF;
12 INTCONbits.TMR0IF=0;
13 }
14 else
15 if (TMR1IF==1)
16 {
17 LEDL=~LEDL;
18 TMR1H=65203>>8; TMR1L=65203&0x00FF;
19 PIR1bits.TMR1IF=0;
20 }
21 }
22 void main(void)
23 {
24 unsigned char x,k;
25 ADCON1=0xF;
26 OSCCON=0x70;
27 // OSCTUNE=0x40;
28 TRISBbits.RB1=0;
29 TRISBbits.RB7=0;
30 TRISC=0xFF;
31 TRISD=0;
32 RCONbits.IPEN=1;
34 T0CON=0x88; TMR0H=64536>>8; TMR0L=64536&0x00FF;
36 T1CON=0x1; TMR1H=65203>>8; TMR1L=65203&0x00FF;
38 TMR0IF=0; TMR1IF=0; TMR0ON=1;
39 TMR0IE=1; TMR1IE=1; TMR1ON=1;
40 PEIE=1;
41 GIE=1;
42 while(1) {PORTD=PORTC;}
43 }
###############
part 4:Level Change Interrupt
SW1 and SW2 connected to pins RB4
and RB5 respectively and LED1 and
LED2 connected to pins RC4 and RC5
respectively. SW1 (SW2) changes the
state of LED1 (LED2) under RB4-7 interrupt
--------
ISIS:
pin 37:switch to VCC then 10K to gnd
pin 38:switch to VCC then 10K to gnd
pin 23:led to res=220 to gnd
pin 24:led to res=220 to gnd
----------
code:
#include "ee445.h"
3 #define LED1 RC4
4 #define LED2 RC5
5 #define SW1 RB4
6 #define SW2 RB5
8 void interrupt high_priority chk_isr (void)
9 {
10 unsigned char temp;
11 if (RBIF==1)
12 {
13 temp=PORTB;
14 LED1=SW1;
15 LED2=SW2;
RBIF=0;
17 }
18 }
20 void main(void)
21 {
22 OSCCON=0x73;
23 ADCON1=0xF;
24 DDRCbits.RC4=0;
25 DDRCbits.RC5=0;
26 DDRBbits.RB4 = 1;
27 DDRBbits.RB5 = 1;
28 RBIF=0;
29 RBIE=1;
30 GIE=1;
31 LED1=0; LED2=0;
32 while(1);
33 }
###########
part 5:
Frequency Meter

------
ISIS:
pin25:virtual terminator
RC0: to signal genrator (sin)
then connect to osclliscope (pinA)

and signal generator(squ)connected
to gnd
------
code:
#include "ee445.h"
10 unsigned long NTicksT1;
11 unsigned char T1prescaler;
float freq;
13 void interrupt high_priority T0_isr(void)
14 {
15 if (TMR0IF==1) {
16 TMR1ON=0;
17 TMR0ON=0;
18 NTicksT1=T1prescaler*((TMR1H<<8)+TMR1L);
19 TMR0IF=0; GIE=0;
20 printf("NTicksT1=%urn",NTicksT1);
21 }
22 }
23 void main(void) {
24 unsigned char pres;
25 OSCCON=0x73;
26 ADCON1=0xF;
27 serial_init(51,1);
28 TRISC0 = 1;
29 T1CON=0b00000010;
30 T1prescaler=1;
31 TMR1H=TMR1L=0;
33 TMR0IF=0;
34 GIE=1;
35 TMR0IE=1;
38 T0CON=0b00000101;
40 TMR0H= (65535+1-31250)>>8;
41 TMR0L= ((65535+1-31250)<<8)>>8;
42 TMR0ON=1;
43 TMR1ON=1;
44 while(1);
45 }
##############
part6:Square Wave generation
using Timer1 and Interrupt
from CCP2 in
Compare Mode

----------
ISIS:
RA0: led to res=330 to gnd
pin15:to SW-SPDT(above to 10k to VCC)
and (below to gnd)
pin16:to oscilloscope (pinA)
pin25:to V.Termianl(Rxd)
pin26:to V.terminal(Txd)
-----------
code:
#include "ee470.h"
#define bittgl(var,bitno) ((var) ^= (1 << (bitno)))
void interrupt high_priority ccp2_int(void)
{
if (CCP2IF==1)
{
CCP2IF=0;
bittgl(PORTC,1);
#asm
#endasm
}
}
unsigned int get_num(void)
{
unsigned int num=0;
unsigned char ch='0';
while(ch != '=')
{
num=num*10+(ch-'0');
ch=getch();
putch(ch);
}
return num;
}
void main(void)
{
unsigned int f, Ntoggle;
float Ttick, Ttoggle;
OSCCON=0x73;
ADCON1=0xF;
CCP2CON=0b00001011;
T3CON=0x0;
serial_init(51,1);
T1CON=0x0;
TRISC1=0;
TRISC0=1;
TRISA0=0;
Ttick=4.0/(8.0e6);
printf("Enter frequency as an integer followed by=rn");
f=get_num();
printf("you entered %urn",f);
Ttoggle=(float) (1.0/f)/2.0;
Ntoggle=(int) (Ttoggle/Ttick);
CCPR2H=(Ntoggle>>8);
CCPR2L= (Ntoggle & 0x00FF);
TMR1ON=1;
GIE=1;
PEIE=1;
CCP2IE=1;
CCP2IF=0;
while(1)
{
RA0=RC0;
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.