Some PIC Programming Problems!!!


Supose we have declared some variables in a cblock that starts at location x20. We hav declared variables (registers) called Count1, Count2 and Count3



Write a PIC 16F628 code fragment that will accomplish the following:

1)   If (Count1==0)
      Then call is_zero
      Else call is_not_zero
      Call   xyz

2)  If (Count1>=Count2)
     Then call Count1_bigger
      Else call Count2_bigger
      Call xyz

3) Polling a pin
    Suppose  pin B0 is set to be an input pin.  It is normally set to zero, but occassionally will go high to 1. When it goes high to 1, we wish to call
    a subroutine called went_high.


    while(true)
    {
       while( pin B0==0);   <---- this is called "polling a pin" . while it is zero, keep checking, when it turns to 1, exit loop
       call went_high;
     }


4) This is a two part question.

a) Pins B0,B1,B2 and B3 are set for input. We wish to check each pin in the order specified. If the value of the pin is zero, call
is_zero and if the value of the pin in one, call is_one.

b) Your answer to part a probably has much repetitive code. Rewrite and eliminate the repetive code!


        for (pin=B0 ; while pin<=B3;   pin ++)
             if (pin==0)
                   call is_zero
             else
                   call is_one