Search this site

8051 Programming in C - Unit 7 - Review Questions & Answers from 8051 Microcontrollers & Embedded Systems by Mazidi

SECTION 7.1: DATA TYPES AND TIME DELAY IN 8051 C

1. Give the magnitude of the unsigned char and signed char data types.

2. Give the magnitude of the unsigned int and signed int data types. 

3. If we are declaring a variable for a person's age, we should use the________ data type.

4. True or false. Using a for loop to create a time delay is not recommended if you want your code be             portable to other 8051 versions.

5. Give three factors that can affect the delay size. 

Answers: 

1. 0 to 255 for unsigned char and-128 to +127 for signed char 

2. 0 to 65,535 for unsigned int and -32,768 to +32,767 for signed int

3. Unsigned char 

4. True

5. (a) Crystal frequency of 8051 system, (b) 8051 machine cycle timing, and (c) compiler use for 8051 C



SECTION 7.2: I/0 PROGRAMMING IN 8051 C

1. The address of Pl is ____________

2. Write a short program that toggles all bits of P2.

3. Write a short program that toggles only bit Pl.0 

4. True or false. The sbit data type is used for both SFR and RAM single-bit addressable locations.

5. True or false. The bit data type is used only for RAM single-bit addressable locations.

Answers: 

1. 90H 

2. #include <reg51.h>

void main() 

P2 = Ox55;

P2 = OxAA 

3. #include <reg51.h>

shit Pl Obit = Pl "0; 

void main() 

PlObit = O;

PlObit = 1; 

4. False, only to SFR bit

5. True 


SECTION 7.3: LOGIC OPERATIONS IN 8051 C 

1. Find the content of Pl after the following C code in each case. 

    (a) Pl=Ox37&0xCA;     

    (b) Pl=Ox37 ! OxCA; 

    (c) Pl=Ox37 ^ 0xCA; 

2. To mask certain bits we must AND them with _____________

3. To set high certain bits we must OR them with ____________

4. Ex-ORing a value with itself results in __________

5. Find the contents of P2 after execution of the following code. 

    P2=0;

    P2=P2 ! 0x99;

    P2= ~P2; 

Answers: 

1. (a) 02     (b) FFH     (c) FDH 

2. Zeros

3. One

4. All zeros

5. 66H 


SECTION 7.4: DATA CONVERSION PROGRAMS IN 8051 C

1. For the following decimal numbers, give the packed BCD and unpacked BCD representations.

    (a)15     (b)99 

2. Show the binary and hex formats for "76" and its BCD version.

3. 67H in BCD when converted to ASCII is _______H and _______H. 

4. Does the following convert unpacked BCD in register A to ASCII? 

    mydata = 0x09 + 0x30; 

5. Why is the use of packed BCD preferable to ASCII?

6. Which one takes more memory space: packed BCD or ASCII? 

7. In Question 6, which is more universal?

8. Find the checksum byte for the following values; 22H, 76H, 5FH, 8CH, 99H. 

9. To test data integrity, we add them together, including the checksum byte. Then drop the carries. The result must be equal to _______ if the data is not corrupted. 

10. An ADC provides an input of 0010 0110. What happens if we output that to the screen? 

Answers: 

1. (a) 15H = 0001 0101 packed BCD, 0000 0001,0000 0101 unpacked BCD 

    (b) 99H = 1001 1001 packed BCD, 0000 1001,0000 1001 unpacked BCD

2. 3736H = 00110111 00110110B and in BCD we have 76H = 0111 OllOB

3. 36H,37H 

4. Yes, since A = 39H

5. Space savings 

6. ASCII

7. ASCII

8. 21CH

9. 00 

10. First convert from binary to decimal, then to ASCII, then send to screen. 


SECTION 7.5: ACCESSING CODE ROM SPACE IN 8051 C 

1. The 8051 has _____ bytes of data RAM, while the 8052 has ________ bytes.

2. The 8051 has _______K bytes of code space and _______K bytes of external data space. 

3. True or false. The code space can be used for data but the external data space cannot be used for code.

4. Which space would you use to declare the following values for 8051 C? 

    (a) the number of days in the week

    (b) the number of months in a year 

    (c) a counter for a delay

5. In 8051 C, we should not use more than 100 bytes of the RAM data space for variables. Why? 

Answers: 

1. 128, 256 

2. 64K, 64K

3. True 

4. (a) data space, (b) data space, (c) RAM space

5. The compiler starts storing variables in code space. 



No comments:

Post a Comment