Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Convert the following pseudocode into PIC 18 assembly language code. shift_left_

ID: 1715353 • Letter: C

Question

Convert the following pseudocode into PIC 18 assembly language code.

shift_left_label:
   function_shift_left();
   if(SW1 is pressed)
       goto shift_right_label;
   else
       goto shift_left_label;
      
shift_right_label:
   function_shift_right();
   if(SW2 is pressed)
       goto shift_left_label;
   else
       goto shift_right_label;

      
function_shift_left()
{
pattern=1;
for(i=0; i<8; i++)
   {
   patter=patter<<1;
   function_delay();
   }
}

function_shift_right()
{
pattern=0x80;
for(i=0; i<8; i++)
   {
   patter=patter>>1;
   function_delay();
   }
}

function_delay()
{
   for(i=0; i<=255; i++)
       for(j=0; j<=255; j++)
           nop;
}

Explanation / Answer

The PIC18 MCU provides many flow-control and conditional branch instructions for implementing program loops. Instructions for initializing and updating loop indices and variables are also available.

A PIC18 instruction takes either one or two instruction cycles to complete. By choosing an appropriate instruction sequence and repeating it for a certain number of times, a time delay can be created.