title: Simulator Hello World in MPLAB IDE: Put stimulus on pins using Pin/Register Actions
body: <p>I've written a hello-world program for an 8-bit PIC microcontroller and want to run it on the MPLAB X IDE simulator. </p>
  
  <p>I want to create a stimulus on its pins, and have the result appear in the microcontroller's register which corresponds to the input pins, (having set a watch on the register).</p>
  
  <p>What I have achieved so far: The program seems to run fine on the simulator, and I can create an "asynchronous" stimulus, i.e. fire a change of the stimulus (such as applying a logic 0 on an input pin) when I click the "fire" button. This changes the contents of the <code>PORTC</code> register. However I cannot get "synchronous" stimulus to work (e.g. automatically toggling the stimulus logic value applied to an input pin). <code>PORTC</code> does not change. (However the simulator output suggests the stimulus is being applied).</p>
  
  <p>There are examples written by Microchip for the MPLAB 8.x IDE simulator which I have tried to apply to MPLAB X (v2.0) but I cannot get working. To establish what I'm doing wrong, (or if I'm encountering a bug), <strong>perhaps someone could help in one of the following ways:</strong> </p>
  
  <ul>
  <li>Give an example of a working hello-world</li>
  <li>Spot any errors in the process I've followed (see below for my steps)</li>
  <li>Follow my steps to see if the problem can be replicated</li>
  </ul>
  
  <p><strong>This is what I have tried:</strong></p>
  
  <p>Summary of steps followed:</p>
  
  <ol>
  <li>Create project and set target device to be "PIC16F77"</li>
  <li>Add source file <code>main.c</code></li>
  <li>Set the simulator as the hardware tool, and XC8 as the C compiler</li>
  <li>Add a variable watch on the <code>PORTC</code> special function register</li>
  <li>Configure an asynchronous stimulus</li>
  <li>Configure a synchronous stimulus</li>
  <li>Build project</li>
  <li>Run in debug mode </li>
  <li>Single-step the program and look for changes of the <code>PORTC</code> register.</li>
  </ol>
  
  <p>Create a new project in the MPLAB X IDE with a source file <code>main.c</code>, and selecting "PIC16F77" as the target device:</p>
  
  <pre><code> #include &lt;htc.h&gt;  
   __CONFIG(  
        FOSC_HS  
       &amp; WDTE_OFF  
       &amp; PWRTE_OFF  
       &amp; BOREN_OFF  
   );  
   void main(void) {  
       // set tristate port directions: 1=input, 0=output  
       TRISC = 0b11111111;  
       while (1);  
   } 
  </code></pre>
  
  <p><strong>I add a variable watch on the <code>PORTC</code> SFR register:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/dzVGz.png" alt="enter image description here"></p>
  
  <p><strong>Configure an asynchronous stimulus in the window/tab <code>Stimulus &gt; Asynchronous</code> :</strong></p>
  
  <p><img src="https://i.stack.imgur.com/HQJ6p.png" alt="enter image description here"></p>
  
  <p><strong>Configure a synchronous stimulus in the window/tab <code>Stimulus &gt; Pin/Register Actions</code></strong></p>
  
  <p><img src="https://i.stack.imgur.com/yfIpZ.png" alt="enter image description here"></p>
  
  <p>Then finally:</p>
  
  <p>I build the project, run in debug mode, pause, and single-step through the program.</p>
  
  <p>When I click on the "fire" button of the asynchronous stimulus and then click the Step-Over button, the value in PORTC register changes as expected.</p>
  
  <p>But when running through the program, the synchronous stimulus never seems to have any effect. It appears that the stimuli are repeatedly being applied, but there is no effect on the value in the <code>PORTC</code> register. It can be seen in the window/tab: <code>Output &gt; Stimulus</code> that the stimulus is being applied:</p>
  
  <p><img src="https://i.stack.imgur.com/lFGqu.png" alt="enter image description here"></p>
  
  <p>I don't understand why the asynchronous stimulus works fine, but the synchronous stimulus appears to be applied but is not producing the desired effect. </p>