Menu

SDCC + PICkit2 low count demo board 16f690

Fox
2009-10-13
2013-03-12
  • Fox

    Fox - 2009-10-13

    I am using a pic16f690 with the PICkit2 programer and its low pin count demo board. I am not even a novice so please forgive me if my C is crappy.
    RC0-RC3 are already wired to LEDS. I have RB4 turned on to give signal to RB6 when the switch is thrown.

    What I want to do:  when I throw a switch which is connected  RB6 and RB4 I want the pick to turn on RB7. when the switch is off, so is RB7

    <pre><code>
    #include <pic16f690test.h> //this is just the SDCC lib renamed, no modification.

    // Delay Function, some one elses that I found online… will credit them if indeed I need it.
    // Using Internal Clock of 8 Mhz
    #define FOSC 8000000L

    #define _delay_us(x) { unsigned char us; \
    us = (x)/(12000000/FOSC)|1; \
    while(-us != 0) continue; }

    void _delay_ms(unsigned int ms)
    {
    unsigned char i;
    do {
    i = 4;
    do {
    _delay_us(164);
    } while(-i);
    } while(-ms);
    }
    // rest is my code

    /*
    just ignore this stuff

    //configure
    //TRISB = 0x90; // same as Bs above
    //TRISA = 0xFF; // same
    //ADCON0 = 1;
    //ADCON1 = 1;
    */
    main (void)
    {

    TRISB4 = 0; //RB4 output
    TRISB6 = 1; //RB6 input which is on the recieving side of the switch attached to RB4
    TRISB7 = 0; //RB7 output
    TRISC0 = 0; // RC0 is an output attached to an LED on the demo board
    TRISC1 = 0; // RC1 is an output attached to an LED on the demo board
    TRISC2 = 0; // RC2 is an output attached to an LED on the demo board
    TRISC3 = 0; // RC3 is an output attached to an LED on the demo board
    RC0 = 0; //RC0 off
    RC1 = 0; //RC1 off
    RC2 = 0; //RC2 off
    RC3 = 0; //RC3 off
    RB7 = 0; //RB7 off
    RB4 = 1; //RB4 on (RB4 is wired to a simple switch which is connected to RB6)

    while (1) //main loop
    {
         RC3 = 1;
        _delay_ms(200);

       while (!RB6) //while the switch is off, do nothing
    {
        RB7 = 0;
        RC2 = 1;
       _delay_ms(200);
        }
      RC1 = 1;
    _delay_ms(200);
       while (RB6)
    {
         RB7 = 1;
         RC0 = 1;
      _delay_ms(200);

    }

    //just flash all LEDS when you reach the end of the program
    _delay_ms(200);
    RC2 = 0;
    RC3 = 0;
    RC0 = 0;
    RC1 = 0;
    _delay_ms(200);
    RC2 = 1;
    RC3 = 1;
    RC0 = 1;
    RC1 = 1;
    _delay_ms(200);
    RC2 = 0;
    RC3 = 0;
    RC0 = 0;
    RC1 = 0;
    _delay_ms(200);
    RC2 = 1;
    RC3 = 1;
    RC0 = 1;
    RC1 = 1;
    _delay_ms(200);
    RC2 = 0;
    RC3 = 0;
    RC0 = 0;
    RC1 = 0;
    _delay_ms(200);
    }

    }

    </code></pre>

    Heres what happens:

    switch off) The RC3 LED is On and RC2 is off. after half a second they inverse to off an on. It just sits in this pattern.

    Theres nothing to tell the pins to turn off until the end of the program.

    switch on) In sequence  on then off again, RC3>RC1>RC0  it does skip RC2 like it should. it repeates this sequence over and over again.
    and again nothing is set to turn off until they all blink on and off again at the end .when I turn the switch off from here, it keeps doing the pattern several times before reverting to the switch off pattern.

    All LEDs never go on and off again at the same time.

    Anyway, I am no where near an expert in C so I am expecting some pretty obvious newb mistakes in there. can anyone help me?

     
  • Fox

    Fox - 2009-10-13

    Sorry for the mess up there, but for some reason preview shows one thing and the post another.

     

Log in to post a comment.