Addis Ababa University
Addis Ababa University
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:
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:
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;
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: