You are on page 1of 8

LEBANESE UNIVERSITY

‫الجامعة اللبنانيّة‬
Faculty of Technology ‫كلية التكنولوجيا‬
CCNE - IME ‫قسم هندسة شبكات المعلوماتية‬
‫واالتصاالت – قسم الهندسة الصناعية‬

Final Exam-Session 2 Documents are Unauthorized


Second year - Semester4
Programmable Circuits September 13, 2021
2020-2021
Time 1.5 hour

Question 1 (6 points)
Consider an alarm system that is:
• triggered by a push button (PB0) connected to RB0,
• capable of activating one of three PWM signal alarms
The PIC16F877 microcontroller will be used to implement this system. The alarm signal is
generated by the2 µs
PWM module at PORTC.2 (RC2 / CCP1). A 20 MHz crystal oscillator is used.
The
S0 two possible alarm signals are shown in the figure below. They all have a duty cycle of 1 µs.
However, the first PWM signal (S1) of 3 µs and the second PWM signal (S2) of 4 µs.

3 µs

S1

4 µs

S2

1 µs

1. The PWM signals will be generated by the Timer2 prescaler set to 1. To generate the
signals S1 or S2, determine the two necessary values which must be applied to register
PR2.
2. All PWM signals (S1 and S2) have a common duty cycle of 1 µs. To ensure this,
determine the necessary value that should be applied to the CCPR1L register.
We are now interested in writing a simple program that generates an S1 signal if RB0 is set
to 1.
3. Write the assembly code of the configuration specifying the following parts:
a. The configuration of the inputs and outputs of PORTB and PORTC.
b. The configuration of the T2CON register in order to put the TIMER2 ON and
to make the prescaler equal to 1.
c. The configuration of the CCP1CON register to select the PWM mode.
d. The configuration of the CCPR1L register in order to specify the duty cycle
equal to 1 µs.
e. The configuration of register PR2 in order to generate the PWM signal (S1).
4. Write the assembler code of the main program which generates the signal S1 if RB0 is set
to 1, if not the generation of the PWM signal must be disabled by updating CCP1CON.

Page 1 of 8
Question 2 (7 points)

The circuit shown is an 8-bit bidirectional counter with two counting speeds. The counter is represented
by 8 LEDs connected to PORTB of a PIC 16F84A with 4 MHz external Cristal. The counting method
depends on the stat of three control inputs:

 Input ON_OFF connected to RA0. If ON_OFF = 0 the count is stopped and the counter output is
zero.
 Input DIR connected to RA1. If DIR=0 the count is forward, and if DIR=1 the count is backward.
 Input VIT connected to input RA2. If VIT=0 the counting value is changed with low speed, each
300 ms. If VIT=1 the counting value changes with high speed, each 100 ms.
Initially the count is zero.
1. Write a subroutine SETUP for the following configurations:
a) Configuration of inputs and outputs;
b) Configuration of TMR0:
- Prescalar 1:32;
- Internal clock.
2. Write a timing subroutine TEMPO_1 for duration of 300 milliseconds. Use the flag T0IF of the
register INTCON for the realization of this temporization.
3. Write a timing subroutine TEMPO_2 for duration of 100 milliseconds. Use the method of timing
loops.
4. Write the Assembly code of the main program. You have to define the variables of the memory
Data used in the previous questions.

Page 2 of 8
Question 3 (7 points)

Consider the following circuit composed of PIC16F877A, two 7-Seg BCD, variable resistor (RV1), and
push button (S1). The variable resistance (RV1) is connected to the analog input (RA1/AN1). The 7-Seg
BCD is connected to PORTD. The push button (S1) is connected to (RB0) as shown in the figure below.

Write a complete program that includes the following points:

1. Initialize the microcontroller in the “SETUP” subroutine such that:


 Inputs and outputs are defined.
 RA1(CH2) is an analog input and (Vref+=5V, Vref-=0V).

2. “A2D_CHANEL_2” subroutine should be doing an A/D conversion that includes:


 The configuration of ADCON0 allowing a conversion clock of Fosc/2, selection of
channel 2, then reading an analog input from AN2, and taking the 8 Most
Significant Bits of the digital result.
 Wait for 20 µs for the acquisition time.
 Start A/D conversion.
 Wait for conversion to complete.
 Read the converted value and store it in W register.
3. Main program such that:
 When the push button S1 is pressed, the microcontroller calls the subroutine
“A2D_CHANEL_2” to read the converted value and display it on the 7-Seg
BCD.

GOOD WORK

Page 3 of 8
PIC 16F84

Page 4 of 8
PIC 16F84

PIC 16F84

Page 5 of 8
PIC 16F877

Page 6 of 8
Page 7 of 8
Page 8 of 8

You might also like