input from pin

Help
Bashir
2007-05-27
2013-03-12
  • Bashir

    Bashir - 2007-05-27

    hello i am new to sdcc and pic programming.  i am using an pic16f690 chip.  it is on a board with 4 led lights on c0,c1,c2,c3 and a button which i think is on a3.

    the program is basically to activate and deactivate the leds in order. 

    the problem is that when i press the button (pin a3) while the program is running it halts the led sequence that is running.  so that makes me suspect that it is part of the inturrupt code but when i added cde to isr() it didnt execute that (to turn on 2 of the leds).  i then thought maybe i could do it with another function button() that when toggled it would do the other code but unfortunitely that didnt work either.

    is there something wrong with my code?  i basically need help with taking input to the pickit and maybe inturupt functions.

    is there somewhere i can get more documentation for this, i spent hours on the net and could hardly find anything.  the sdcc manual deals more with compiling rather than codeing.  any help is greatly appreciated.  thank you.

    here is my code

    #define __16f690
    #include"pic/pic16f690.h"

    /* Setup chip configuration */
    typedef unsigned int config;
    config at 0x2007 __CONFIG = _CP_OFF &
    _WDT_OFF & 
    _PWRTE_OFF &
    _MCLRE_ON;

    #define C0 0x0e /* pin 1 on PORTC */
    #define C1 0x0d /* pin 1 on PORTC */
    #define C2 0x0b /* pin 1 on PORTC */
    #define C3 0x07 /* pin 1 on PORTC */

    void delay(int);

    void isr() interrupt 1
    {
        TRISC = 0x09;
        delay(180);

    }
    void button(void)
    {
        while (1)
        {
            TRISC = 0x09;
            delay(180);
        }
    }

    void main (void)
    {
    int Delay_Value;
    Delay_Value = 60;
    while (1)
    {
        TRISC = C0;
        delay(Delay_Value);

        TRISC = C1;
        delay(Delay_Value);

        TRISC = C2;
        delay(Delay_Value);

        TRISC = C3;
        delay(Delay_Value);

        TRISC = C2;
        delay(Delay_Value);

        TRISC = C1;
        delay(Delay_Value);

        TRISC = C0;
        delay(Delay_Value);
       
        TRISA = 0xFF;
        if (PORTA==1)
        {
            button();
        }

        }
    }

    void delay(int i)
    {
        unsigned int j;
        do
        {
            for(j=0; j<1000; j++) {}
            i--;
        }while(i > 0);

        return;
    }

     
    • Bashir

      Bashir - 2007-05-27

      here is a picture of the kit i have

      http://www.arrowne.com/innov/in83/pics/c9i18_microchip_image1.jpg

      thanks for the help.

       
    • AP2k

      AP2k - 2007-05-30

      First off is that I dont see that you have given a value to any of the interrupt registers (INTCON, PIR1, PIR2).

      Second, your isr should be "void isr() interrupt 0", not 1.

      Thirdly:

      ===================
      if (PORTA==1)
      {
           button();
      }

      void button(void) 
      {
          while (1)
          {
                TRISC = 0x09;
                 delay(180); 
          }
      }
      ===================

      It seems when you hit the button, it goes to the button() method which is an endless loop. Obviously, then, your light sequence will be interrupted, but not from an interrupt event.

       
    • Bashir

      Bashir - 2007-05-31

      thanks for responding. 

      well i am fine with using button() as a fake interrupt if it would work.   i actually tried to incorporate it because i couldn't get interrupts working.  unfortunately i still cant get the event of button() to work.

      i tried removing all the interrupt stuff (and fixed it up a little) to get the below code.  the thing is when button() is activated it should light up the middle two leds constantly but it fails to light up anything.  this happened with or without the button() function or interrupt function.  which makes no sense.

      i am not sure if i am properly reading the output of the button correctly such that it gives true to the logic argument and activates button().  the below code does teh startup actions correctly but fails when the button is pressed it halts that but doesnt do what is in the function which leads me to believe something else is happening. 

      NOTE: according to my code (since the if statement is at the end of the led light sequence) if the button is pressed then it should finish the rest of that led rotation and then go to button() but it halts the led sequence anywhere in the main() function. 

      thanks for the help.

      #define __16f690
      #include"pic/pic16f690.h"

      /* Setup chip configuration */
      typedef unsigned int config;
      config at 0x2007 __CONFIG = _CP_OFF &
      _WDT_OFF & 
      _PWRTE_OFF &
      _MCLRE_ON;

      #define C0 0x0e /* pin 1 on PORTC */
      #define C1 0x0d /* pin 1 on PORTC */
      #define C2 0x0b /* pin 1 on PORTC */
      #define C3 0x07 /* pin 1 on PORTC */

      void delay(int);
      void button(void);

      void main (void)
      {
      int Delay_Value;
      Delay_Value = 60;
      while (1)
      {
          TRISC = C0;
          delay(Delay_Value);

          TRISC = C1;
          delay(Delay_Value);

          TRISC = C2;
          delay(Delay_Value);

          TRISC = C3;
          delay(Delay_Value);

          TRISC = C2;
          delay(Delay_Value);

          TRISC = C1;
          delay(Delay_Value);

          TRISC = C0;
          delay(Delay_Value);
         
          TRISA = 0xFF;
          if (PORTA==1)
          {
              button();
          }

          }
      }

      void delay(int i)
      {
          unsigned int j;
          do
          {
              for(j=0; j<1000; j++) {}
              i--;
          }while(i > 0);

          return;
      }

      void button(void)
      {
          TRISA = 0xFF;
          while (PORTA==1)
          {
              TRISC = 0x09;
              delay(180);
          }
      }

       

Log in to post a comment.