Sunteți pe pagina 1din 1

Atilim University Name, Surname :

Department oI Mechatronics Engineering Student ID :


MECE 308



Midterm Exam #2
Date: 14.05.2010, Duration 90 minutes

(50pts) Q1. Write a program (in CCS PIC-C language) that uses timer interrupts and outputs continuously illustrated signal Irom one
oI the digital I/O pin oI PIC16F877A. What is t duration and period T oI the signal that you generate? Assume that the
microcontroller is operated with a 4 MHz crystal (clock oscillator Irequency).

Questions Q.2 through Q.6 are related to the Iollowing CCS PIC-C code and illustration:
Below code mainly displays time in hours:minutes:seconds on a LCD.

LineI #incIude Iof877o.h
LineZ #fuses XT, MOWDT, PUT, MOPPOTECT, MOLVP
Line3 #use deIoy(cIock~4000000)
Line4 #incIude Icd.c
Lineb
Lineo inf hours ~ 0, minufes ~ 0, seconds ~ 0,
Line7
Line8 void moin() {
Line9 Icd_inif(),
LineI 0 for (,,) {
LineI I if (++seconds ~ o0) {
LineI Z seconds ~ 0,
LineI3 if (++minufes ~ o0) {
LineI 4 minufes ~ 0,
LineIb if (++hours ~ Z4) {
LineIo hours ~ 0,
LineI7 }
LineI 8 }
LineI 9 }
LineZ0 prinff(Icd_pufc, "\fTime~7u:7u:7u", hours, minufes, seconds),
LineZI deIoy_ms(I000),
LineZZ }
LineZ3 } //end of moin funcfion

(10pts) Q2. In the illustrated circuit, there are certain on purposely leIt missing components and missing connections to PIC16F877A.
On the circuit, indicate all necessary components and their values, and connections to the PIC16F877A so that it will operate
properly.
(10pts) Q3. Add a reset pushbutton (normally open) to the circuit diagram, so that when it is pressed it will reset the PIC16F877A.
(10pts) Q4. Write a Iunction, which accepts three input parameters that can be used to set the clock to a desired time. II necessary,
add source code, so that this Iunction can be called Irom the main Iunction. Indicate using line numbers to where this Iunction should
be inserted.
(10pts) Q5. Write necessary instructions to use Iast I/O on PortB, and set the RB0 pin oI PortB to be used Ior output while all other
pins oI PortB are set Ior input. Indicate using line numbers to where the instructions should be inserted.
(10pts) Q6. Write necessary instructions so that when time is 15:30:00 an LED connected to RB0 pin oI PortB will be turned-ON,
and when time is 15:31:00 the LED will be turned-OFF. Show the LED connection on the circuit diagram. Indicate using line
numbers to where the instructions should be inserted.
LCD-Power SuppIy-Sround
und Contrust connections
LCD Pin I fo ground
LCD Pin Z fo +bV
LCD Pin 3 fo mid-ferminoI of o
frimpof whose fwo-end
ferminoIs ore connecfed fo
ground ond +bV, respecfiveIy
MCU-LCD connections
MCU Pin , Mo LCD Pin, Mo
PD0, I9 E, o
PDI, Z0 PS, 4
PDZ, ZI PW,b
PD4, Z7 DATA, II
PDb, Z8 DATA, IZ
PDo, Z9 DATA, I3
PD7, 30 DATA, I4
Time15:30:0
16F877A
LCD
MCU

S-ar putea să vă placă și