CENG 303 Midterm I 2008 Memory at address 0x300 Name: Bit 7 GND LED 8 Bit 6 GND LED 7 Bit 5 GND LED 6 Bit 4 GND LED 5 Bit 3 VCC LED 4 Bit 2 VCC LED 3 Bit 1 VCC LED 2 Bit 0 VCC LED 1 Microprocessor XYZ Bit 7 Sw 8 R VCC GND Memory at address 0x301 Bit 6 R Sw 6 Bit 5 Sw 7 R Bit 4 Bit 3 Bit 0 Sw 5 R R GND VCC Sw 3 R Sw 2 R VCC GND Bit 2 Bit 1 GND VCC GND Sw 4 VCC GND VCC GND VCC Sw 1 R GND VCC The microprocessor XYZ is connected to 8 LEDs (Light Emitting Diodes) and 8 Limit Switches as shown in the above figure. The LEDs are turned on or off by means of memory address 0x300. Each bit of this address is connected to one LED. LED1 is turned on/off by BIT0, LED2 is turned on/off by BIT1, and so on. Similarly, the status of limit switches are checked by means of memory address 0x301. Each bit of this address is connected to one limit switch. Limit switch Sw1 is connected to BIT0, limit switch Sw2 is connected to BIT1, and so on. Be careful, some of the resistors (for limit switch connection) are connected in pull-up configuration, and the others are connected in pull-down configuration. 1|Page CENG 303 Midterm I 2008 Name: Q1. (20pt) If the content of memory at address 0x301 is 0xCC, which limit switches are closed? 0xCC 1 SW8 1 SW7 0 0 1 1 0 SW2 0 SW1 SW1, SW2, SW7 and SW8 are closed. Q2. (20pt) If the content of memory at address 0x301 is 0x90, which limit switches are closed? 0x90 1 SW8 0 0 1 SW5 0 SW4 0 SW3 0 SW2 0 SW1 SW1, SW2, SW3, SW4, SW5 and SW8 are closed. Q3. (30pt) Write a C-language program fragment such that whenever you press Sw n, LED (n+3) mod 8 will be turned on. You can write this program in a single statement. But, for the sake of simplicity, I wrote it in 3 statements. unsigned char x; x = (*(unsigned volatile char *)(0x301)^0x0F) >> 5; x |= (*(unsigned volatile char *)(0x301)^0x0F) << 3; *(unsigned volatile char *)(0x300) = x ^0x0F; Q4. (30pt) When the following C-language program is executed, a) What happens to the above XYZ microprocessor system, if SW1, SW3 and SW5 are closed? b) What happens to the above XYZ microprocessor system, if SW2, SW4, SW6, SW7 and SW8 are closed? int main() { *(unsigned volatile char*)0x300 = 0x45; if(((*(unsigned volatile char*)0x301) & 0x74) == 0x74) { *(unsigned volatile char*)0x300 <<= 2; } 2|Page CENG 303 Midterm I 2008 Name: else { *(unsigned volatile char*)0x300 = *(unsigned volatile char*)0x301 ^ 0xFF; *(unsigned volatile char*)0x300 |= (0x13>>1); } return 0; } a) If SW1, SW3 and SW5 are closed, then 0x301 will contain 0x1A. That means, else part will be executed in the above program. After executing the first statement in the else part. (00011010 XOR 11111111) = 11100101 LED2, LED4, LED6, LED7 and LED8 will be turned on. After executing the second statement in the else part. 0x13>>1 00001001 = 9 11100101 XOR 00001001 = 11101101 LED2, LED6, LED7 and LED8 will be turned on. b) if SW2, SW4, SW6, SW7 and SW8 are closed, then 0x301 will contain 0xE5. That means, else part will be executed in the above program. After executing the first statement in the else part. (11100101 XOR 11111111) = 00011010 LED1, LED3, LED5 will be turned on. After executing the second statement in the else part. 0x13>>1 00001001 = 9 00011010 XOR 00001001 = 00010011 LED3, LED4, LED5 will be turned on. 3|Page