(i) Explain two advantages of writing the software (firmware) for a microcontroller in ‘C’ as oppose to using assembly.
(ii) For the decimal number 77 determine the 8 bit binary value and
the corresponding hexadecimal number.
(iii) For the PIC16 family of microcontrollers how many bits wide
is the Program Counter. Explain the purpose of the program
counter
(iv) If the PIC microcontroller is clocked by a 1MHz crystal,
calculate the instruction clock (internal clock) frequency and
hence how many instructions are executed per second.
1.Advantages of writing the software for a microcontroller in ‘C’
2. Decimal Number is ‘ 77 ’
8 bit binary value is ‘ 01001101 ‘
Hexadecimal value is ‘ 4D ‘
3. The actual hardware inside the program counter holds 22-bits + 1-bit which is always 0 instructions are 24-bits long, but the program memory is actually 32-bits wide. The compiler adds 0 to the 22-bit program counter to make it 23-bits. The 22-bit program counter holds the binary value b010 (decimal 2) then 0 is added to this value which makes it b0100 (decimal 4) b0100 accesses the instruction located at byte range 4-7. The program counter is incremented by b0010 (decimal 2). The 22-bit program counter now holds the value b0100 (decimal 4). When the 0 is added to the 22-bit program counter, the new address to be accessed is b01000 (8-11 bytes).
Purpose of the Program Counter: Program Counter (PC) keeps track of the program execution by holding the address of the current instruction. It is automatically incremented to the next instruction during the current instruction execution.
4. Formula to calculate instruction execution time in PIC microcontroller is
“ t = (No. of clock cycles x 4)/ (Clock Frequency) “
Instruction clock frequency is 4us and 4 clock cycles to executed a command for 1MHz.
(i) Explain two advantages of writing the software (firmware) for a microcontroller in ‘C’ as oppose...