pic discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/c-programming-part2.pdf · in...

30
PIC Discussion By: Eng. Tamar Jomaa

Upload: others

Post on 15-Oct-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

PIC DiscussionBy: Eng. Tamar Jomaa

Page 2: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

C programming-part2

Outlines:

1) 7-Segment

2) EEPROM

3) Timers

4) Interrupt

5) Lab#9:Application to Interrupt

Page 3: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

7-Segment

One press on RB0 automatic counter from 0 to 9 (increment by 1)

One press on RB1 automatic counter from 0 to 9 (even numbers)

One press on RB2 automatic counter from 0 to 9 (odd numbers)

Example

#1

Page 4: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

7-Segment

Solution:

Example

#1

Page 5: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

EEPROM

In Micro C:

EEPROM_write(address,data)

EEPROM_read(address)

Example

#1

Write 0x10 in address 0x5.

Page 6: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

EEPROM

Example

#1

Solution:

Page 7: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

EEPROM

Example

#2

Fill all EEPROM locations with 0x55.

Page 8: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

EEPROM

Example

#3

Write 0x07 in address 0x05, then read data

from address 0x05 to portB .

Page 9: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

EEPROM

Example

#4

Program to take the data existed on PORT A and display it

on PORT B:

first, the data must be taken from PORT A and stored in

the EEPROM address location 0X10, and then be taken

again from EEPROM and be displayed on PORT B.

Page 10: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

EEPROM

Example

#4

Solution:

Page 11: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

Timers

PIC16f84A

PIC16f877A

Page 12: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

Timers

Page 13: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

Timers

Example

#1

Display the value of TMR0 in portB.

Page 14: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

Timers

Example

#1

Solution:

External clock source on RA4

PSA=1, so tmr0 will count 1:1

Page 15: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

Timers

Example

#1

another Solution:

External clock source on RA4

PSA=0, so tmr0 will count according to prescale

001≡ 1:4 increase by one ever 4 clocks.

Page 16: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

Timers

Example

#1

another Solution:

internal clock source as oscillator

PSA=0, so tmr0 will count according to prescale

000≡ 1:2 increase by one ever 2 clocks.

Page 17: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

Interrupt

Example

#1

Connect 4 LEDs to bins (RA0,RA1,RA2 and RA3) of

portA, and then toggle these LEDs using the

interrupt on(RB4-RB7), so that RB4 controls RA0,

RB5 controls RA1 and so on.

Page 18: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

Interrupt

Example

#1

Page 19: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

Interrupt

Example

#2

Flasher on RA0 then use the interrupt method to

control the flashing speed. Use interrupt on change

RB.

Page 20: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

Interrupt

Example

#2

Page 21: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

Interrupt

Example

#3

If RB4 is pressed the counter will count F,E,D,….0If RB4 is pressed the counter will count A,9,8,…..0If RB6 is pressed the counter will count 5,4,3,…..0The default counting from: 70

Page 22: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

Interrupt

Example

#3

Page 23: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

Interrupt

Example

#4

PortB= value of TMR0

PSA=111 TMR0 increase by one every 256 push

on RA4

If TMR0 goes from FF to 00 Interrupt occurs and

RA0 toggle.

Page 24: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

Interrupt

Example

#4

Page 25: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

Lab#9:

Application to Interrupt

Iqama project If the crier (muezzen) after

doing the athan pushes the

button related to that athan,

two seven segments will

decrease from (25,20,10 or 5

minutes) according to the pray

time, and when they reach zero

then the iqama time comes.

LED will flashing indicating

that the crier (muezzen) must

do the iqama now.

The buttons will be

connected on bins (RB4, RB5,

Rb6 and RB7) respectively, and

will be accessed using

interrupt method.

Iqama

project

Page 26: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

Lab#9:

Application to Interrupt

Iqama

project

Page 27: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

Lab#9:

Application to Interrupt

Iqama

project

Page 28: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

Lab#9:

Application to Interrupt

Iqama

project

Modified Iqama project by adding another push

button for the Fajer. When the program finish display

25 in the two 7segments as flasher. (5 marks)

Page 29: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

Lab#9:

Application to Interrupt

Iqama

project Do the modified Iqama project software and

hardware.

Attach the CD for the MicroC code and simulation

and send to me hard copy report.

Only 3 students in every group.

Page 30: PIC Discussion - site.iugaza.edu.pssite.iugaza.edu.ps/tjomaa/files/C-programming-part2.pdf · In Micro C: EEPROM_write ... Presentation Title Author: 微软中国 Created Date: 11/23/2012

10/01/1434

Be free to ask any question.

Eng. Tamar Jomaa