0% found this document useful (0 votes)
67 views8 pages

Addis Ababa University

The document discusses a lab report submitted by Ezra Mohammed for Micro-Computer and Interfacing lab set 2. The report contains questions about header files, register banks, assembly code equivalents, tricks to store large numbers, modifying LED blinking code, differences between 8051 and ARM assembly, and controlling LEDs with a light sensor.

Uploaded by

EZRA MOHAMMED
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views8 pages

Addis Ababa University

The document discusses a lab report submitted by Ezra Mohammed for Micro-Computer and Interfacing lab set 2. The report contains questions about header files, register banks, assembly code equivalents, tricks to store large numbers, modifying LED blinking code, differences between 8051 and ARM assembly, and controlling LEDs with a light sensor.

Uploaded by

EZRA MOHAMMED
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

ADDIS ABABA UNIVERSITY

ADDIS ABABA INSTITUTE OF TECHNOLOGY


SCHOOL OF ELECTRICAL AND COMPUTER ENGINEERING
MICROELECTRONICS STREAM
MICRO – COMPUTER AND INTERFACING
LAB SET – II
LAB REPORT
BY:
EZRA MOHAMMED
ID:
UGR/6735/13

Submitted to: Kinde M.


Submission date: 5/11/2024
PART 1:
1. What does the header file contain?(Open and check content of header you have included)
Answer:

Fig 1. Header
The header file contain definitions, constants, and registers mappings that are necessary for
programming the micro controller and interacting with its hardware peripherals.
1. Register Definitions
2. Bit-Level Definitions
3. Special Function Register (SFR) Definitions 4.Interrupt Vector Definitions
5. Clock and Timer Definitions
6. I/O Port Definitions
7. Configuration Options.
2. Which register bank is being used?
Answer:

According to the code I have in the keli uvistion


RS1 = 0 and RS2 = 0: Register Bank 0
RS1 = 0 and RS2 = 0: Register Bank 1
RS1 = 0 and RS2 = 0: Register Bank 2
RS1 = 0 and RS2 = 0: register bank 3
But according to the above image the working register bank is 0.
3. The same code for the loop in c to the assembly

Answer:

Or
******************************************************************************
/*The Assembly equivalent code from the assembly window */
CLR MOV
MOV A R6,A
R7,A
LCALL wait(C:084E)
INC R7
CJNE R7,#0x00,C:0815
INC R6
CJNE R6,#0x27,C:080D
CJNE R7,#0x10,C:080D
MOV A,R5
ADD A,ACC(0xE0)
MOV R5,A
SJMP C:0802
******************************************************************************
4. We know that 8051 (AT89c51) is an 8-bit micr-controller; data bus and data registers are
8 bit wide which means they can only hold up to FFH (255 in decimal). What trick did
the compiler used to store 10000(3E8H, 11 bits) in the above for-loop code segment?
Answer:
R6 is used to count 256 times and with each iteration running 40 times (R7). The
product (256 * 40) approximates 10000.

5. Modify LED.C so that the LEDs continuously blink in a circular order instead of back
and forth. Note: If you chose to removing the second for loop to create a one direction
circular order, it works fine except one led will not blink or your LEDs will blink only for
the first round (use Keil debugger by adding register P1 in watch1; adding break point at
P1 = j and observe P1’s value for each j value pressing (Ctrl + F10) multiple times. One
bit of register P1 must be 1 all the time, or no LED will blink).
Answer:
******************************************************************************
void wait(void) {;}

void main(void)
{ unsigned int i;
unsigned char j;
while (1) {
for (j = 0x01; j < 0x80; j <<= 1) { P1 = j;
for (i = 0; i < 10000; i++) {
wait();
}}}}
PART2:LED Blinking on ARM:
1. What does the header file contain? (Open and check content of header you have included).
Answer:
The provided header file contains definitions for various memory-mapped registers and
constants specific to the LPC2141/42/44/46/48 micro-controller family.The definitions
included are of:

3. Vectored Interrupt Controller (VIC)


4. Pin Connect Block
5. General Purpose Input/Output (GPIO)
6. Memory Accelerator Module (MAM)
7. Phase Locked Loop (PLL)
8. VPB Divider
9. Power Control
10. External Interrupts 9.Reset
10. Code Security / Debugging
11. System Control Miscellaneous 12.Timers
13. Pulse Width Modulator (PWM)
14. UART (Universal Asynchronous Receiver Transmitter)
15. I2C Interface
16. SPI (Serial Peripheral Interface) 17.Real-Time Clock (RTC)
18. A/D Converter (ADC
19. D/A Converter (DAC) 20.Watchdog
21. USB Controller
2. Now debug your code using “DEBUG>>Strat/Stop Debug session” and observe the registers
content. In which mode are most of the instructions get executed? (Hint: use appropriate
CPSR ).Answer: Most of the instructions get are executed in user mode.
3. Now, observe the Disassembly window, click on “step over” (F10) to debug line by line. What
is the assembly code equivalence of the following C code? (You will get in the assembly
window).

Answer:

******************************************************************************
/* The Assembly Equivalent Code from the assembly
window */ MOV R1, #0x00000000
B 0x00000254
BL
wait(0x00000214) ADD
R1,R1,#0x00000001 LDR
R2,[PC,#0x0054]
CMP R1,R2
BCC 0x0000024C
MOV R0,R0,LSL #1
CMP
R0,#0x00800000 BCC
0x0000023C
******************************************************************************
4. Is there a difference with 8051 in assembly handling of variable ‘i’ whose value ranges from 0
to 10000?
Answer: Yes there is some difference between 80C51 and LPC2148.
80C51 LPC2148
The loop variable i is managed using two The loop variable i is managed using register
registers R6 and R7. R1.
At the beginning of the loop, both R6 and R7 At the beginning of the loop, R1 is loaded
are cleared to 0 (CLR A, MOV R6, A, MOV with 0 (MOV R1, #0x00000000).
R7, A).
The loop starts with the LCALL wait() The loop starts with a branch instruction (B
instruction. 0x00000254).
After calling wait(), R7 is incremented (INC After calling wait(), R1 is incremented by 1
R7), and a check is performed to see if it has (ADD R1, R1, #0x00000001).
reached 0 (CJNE R7, #0x00, C:0815). If not,
it continues the loop.
If R7 reaches 0, R6 is incremented (INC R6), The value stored at address PC + 0x0054
and a check is performed to see if R6 has (which is a variable related to the loop count)
reached 0x27 (CJNE R6, #0x27, C:080D). If is loaded into R2.
not, it jumps back to the beginning of the loop A comparison is made between R1 and R2
(CJNE R7, #0x10, C:080D). (CMP R1, R2), and if R1 is less than R2, the
loop continues (`BCC 0x0000024C`).
Once both R6 and R7 reach their respective If R1 reaches the limit (10,000 in this case),
limits, the loop exits. the loop exits.

6. Modify the ARM C code so that your LEDs can be controlled by a switch connected to
pin 1.24. The switch is not a normal ON/OFF rather a photodiode as shown below (Day
time off, night time on). APDS-9002 is a low-cost analog-output ambient light photo
sensor consisting a spectrally suited phototransistor which peaks in human luminosity
curve. You can find the datasheet here APDS900.
Answer:
******************************************************************************
void wait(void) {
; }
int main() {
unsigned int i, j; /* Delay and
LED var */ PINSEL2 = 0x000000;
IO1DIR = 0xffffffff;

// Set P1.24 as input for photodiode


IO1DIR &= ~(1 << 24); // Clear bit for input

while (1) {
if (IO0PIN & (1<<24)) { /*if pin p0.24 is at
high(daytime), turn off the LEDs*/
IO1PIN = 0;
} else {
for (j = 0x10000; j < 0x800000; j <<= 1) {
IO1PIN = j; /* Output to LED Port */
for (i = 0; i < 10000; i++) { /* Delay for
10000 Counts */ wait(); /* call wait function
*/
}
}
for (j = 0x800000; j > 0x10000; j >>= 1) {
IO1PIN = j; /* Output to LED
Port */ for (i = 0; i <
10000; i++) {
wait();
}
}
}
}
}
*************************************************************************************
7. Modify value of load resistance R2 to 1k because the V-L curve will be linear and
appropriate. Does it work? If not, why?
Answer: Yes, it was more or less linear.
8. What trick can you use to make your LEDs to switch at Luminance 100LUX using 1K
ohm resistor?
Answer:

1. Microcontroller with PWM:


 Use the LPC2138 microcontroller's ADC to convert the ALS output voltage to a
digital value.
 Based on the digital value (corresponding to lux level), use Pulse Width
Modulation (PWM) to control the LED brightness.
 By adjusting the PWM duty cycle, you can effectively control the average
brightness and achieve an "on" state at your desired lux threshold (around 100
lux).
2. Comparator Circuit:
 Introduce a comparator circuit with a voltage reference set to the voltage
corresponding to 100 lux (obtained from the calibration graph for a 1kΩ resistor).
 The ALS output voltage is fed to one input of the comparator.
 When the ALS voltage exceeds the reference voltage (indicating higher than 100
lux), the comparator output switches, triggering an LED driver circuit to turn on
the LED.

You might also like