Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC16F873A code help

Status
Not open for further replies.
Hi, JB

Before going further in your Quest ...

1) have a look to 16F886 Chip ... ( 883 if you insist ! ) ... cheaper then the 87x series !!!
2) simply Try PORTB.F1 = 1 ...
3) Download PIC Microcontrollers - Programming in C - Free Online Book - mikroElektronika

MainInit();

INTCON.F0 = 0; // Clear Interrupt Flag
INTCON.F3 = 1; // RB Change interrupt activated
Delay_ms(200);

...

PORTD.F0 = 1; // Wake up flag
INTCON.F0 = 0; // Clear Interrupt Flag

as an example ...

Alain
 
Last edited:
Thanks Alain, PORTB.F1 = 1 works perfectly for my application.

The only reason I am using the 16F873A is because there was a handful of them in the school's parts room, free for the taking.

Again guys, thanks for all the great help!!!
 
ohhh... thanks guys.

I should have known that, but I've been doing alot of work with visual basic lately.

Hi,

If you've been working with visual basic and know it well, why use C. For microcontrollers, use mikroBASIC in which syntax is similar to Visual BASIC.

Hope this helps.
Tahmid.
 
Visual Basic is a great language (VB6 is anyway), it's a shame C has to have two different operators when VB can get away just fine with one.

So true.
You should take a look at the .NET versions of Visual BASIC. I use VB2008 and it rocks. I say its way better than VB6.
 
So true.
You should take a look at the .NET versions of Visual BASIC. I use VB2008 and it rocks. I say its way better than VB6.
I like many of the things .NET brings to VB, however I do not like the unnecessary added complexity and the fact that they have deviated so much from the original syntax and methods.

IMHO they could have kept it largely the same in ease of use and still added the new functionality.
 
VB6 and .NET are completely different, it's very easy to program in .NET, C# is virtually Java!

I used to create GUI's in VB as it was so so easy, I now use C# and C++.

Plus with the express editions things are even easier (and cheaper!)
 
can anyone tell me why the delay function (included in mikroc) will not work for me?

Code:
void main() {

  PORTB = 0x00; //initialize portb
  PORTC = 0x00; //initialize portc
  TRISB = 0x00; //set portb as output
  TRISC = 0xFF; //set portc as input

  while (1) {                       // Endless loop
        if (PORTC.F0 == 0)          // If RC0 goes to low
        goto RAIN;                  //    goto RAIN
  }

  RAIN:
  PORTB.F0 = 1; // Set RB0 high
  PORTB.F4 = 1; // Set RB4 high

  Delay_ms(1000); //1 second delay

  while (1) {                       //Endless loop
        if (PORTC.F3 == 1)          // Motion Detector
           goto END;

        if (PORTC.F4 == 0)          // Over-current #1
           PORTB.F0 = 0;

        if (PORTC.F6 == 0)          // Over-current #2
           PORTB.F4 = 0;

        if (PORTB.F0 == 0 & PORTB.F4 == 0)
           goto END;
  }

  END:
  PORTB.F0 = 0;
  PORTB.F4 = 0;
}
 
Hi, JB

I think your code is somewhat ... how to tell ??? ... tortuous.
Code:
 while (1) {                       // Endless loop
        if (PORTC.F0 == 0)          // If RC0 goes to low
        goto RAIN;                  //    goto RAIN
  }

  RAIN:

could be simply replaced by

Code:
 while (PORTC.F0 == 1)          // Wait for RC.0 to go low

AND
Code:
 while (1) {                              //Endless loop
        if (PORTC.F3 == 1)          // Motion Detector
           goto END;

        if (PORTC.F4 == 0)          // Over-current #1
           PORTB.F0 = 0;

        if (PORTC.F6 == 0)          // Over-current #2
           PORTB.F4 = 0;

        if (PORTB.F0 == 0 & PORTB.F4 == 0)
           goto END;
        }
  END:
  PORTB.F0 = 0;
  PORTB.F4 = 0;
}

be replaced by

Code:
 while (PORTC.F3 == 0 & (  PORTB.F0 == 1 | PORTB.F4 == 1))       // STOP if RC3 =1 OR ( RB0 = 0 AND RB4 = 0 )
     {                       
        if (PORTC.F4 == 0)          // Over-current #1 
           PORTB.F0 = 0;

        if (PORTC.F6 == 0)          // Over-current #2
           PORTB.F4 = 0;

     }

 }

but Delay works fine !!! ... once code is somewhat cleaned up.

Alain
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top