PIC Discussion

Post on 07-Jan-2016

49 views 1 download

description

PIC Discussion. By: Eng. Tamar Jomaa. C programming-part2. Outlines: 7-Segment EEPROM Timers Interrupt Lab#9:Application to Interrupt. 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) - PowerPoint PPT Presentation

Transcript of PIC Discussion

PIC DiscussionBy: Eng. Tamar Jomaa

C programming-part2

Outlines:

1) 7-Segment2) EEPROM 3) Timers4) Interrupt5) Lab#9:Application to Interrupt

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

7-Segment

Solution:

Example

#1

EEPROMIn Micro C:EEPROM_write(address,data)EEPROM_read(address)

Example

#1

Write 0x10 in address 0x5.

EEPROM

Example

#1

Solution:

EEPROM

Example

#2

Fill all EEPROM locations with 0x55.

EEPROM

Example

#3

Write 0x07 in address 0x05, then read data from address 0x05 to portB .

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 inthe EEPROM address location 0X10, and then be taken again from EEPROM and be displayed on PORT B.

EEPROM

Example

#4

Solution:

Timers

PIC16f84A

PIC16f877A

Timers

Timers

Example

#1

Display the value of TMR0 in portB.

Timers

Example

#1

Solution:

External clock source on RA4

PSA=1, so tmr0 will count 1:1

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.

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.

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.

Interrupt

Example

#1

Interrupt

Example

#2

Flasher on RA0 then use the interrupt method to control the flashing speed. Use interrupt on change RB.

Interrupt

Example

#2

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

Interrupt

Example

#3

Interrupt

Example

#4

PortB= value of TMR0PSA=111 TMR0 increase by one every 256 push on RA4If TMR0 goes from FF to 00 Interrupt occurs and RA0 toggle.

Interrupt

Example

#4

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

Lab#9:Application to Interrupt

Iqama project

Lab#9:Application to Interrupt

Iqama project

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)

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.

١٤٤٤/٠٩/٣٠

Be free to ask any question. Eng. Tamar Jomaa