Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

pic16f84 + piezo pulse + led

Status
Not open for further replies.

vaka85

Advanced Member level 4
Joined
May 9, 2008
Messages
100
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
2,112
Hi all,
I've a very easy problem to solve (not easy for me).. But I'm a noob in pic programming and then I need help.

briefly: when there's a pulse in input, pic turn on a led in output.
Here is the code, I am using mikroC..
when I compile, there are a lot of errors, for example it doesn't recognize LATA and RA1...
maybe the problem is some missing file in "include" but I don't know.

Code:
#include "16F84.H"

#pragma config FOSC = HS
#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config PBADEN = OFF

void main(void) {
    // set portA as inputs
     LATA = 0x00;
     TRISA = 0xFF;
    // set portB as outputs
     LATB = 0x00;
     TRISB = 0x00;

while(1)   // continually
   {
     // CLRWDT();
    //  EnablePullups();      // enable internal pullups on PORTB

      if (RA1)      // if there's a trigger pulse
      {
        RB0 = 1;     // turn the LED on
         for (j =0; j < 64000; j++) { //delay
         }
        RB0 = 0;   // turn the LED off
         for (j =0; j < 64000; j++) { //delay
         }
      }

   }
}

any idea?
thanks
 

There is no requirement for enabling the latches to configure the port pins as input or output. You only need to configure the TRIS bits of the corresponding ports to do so. By setting the TRIS bits to 1 configures the port pins as Input & setting the TRIS bits to 0 configures the port pins as output.Don;t check a condition as:
if (RA1).
.
It is wrong. Check the portA pin as a whole by addressing if(PORTA.f1) which means that if that pin goes high,then the following code will be executed.Try this, This may help you.
Regards,
Jerin. :)
 
  • Like
Reactions: vaka85

    vaka85

    Points: 2
    Helpful Answer Positive Rating
woooo! it works!!
thank you so much!!

another question:
if I have several pulse in input, very close, this script isn't so suitable for this application. How can I modify it?
I mean: I need that for every pulse, even if it's 0.2 seconds after the previous one, the led turns on.

Actually it turns on for, maybe about 0.5 seconds, but in meanwhile there can be another pulse, so it should "reset"...
I hope I was clear...

I have to use interrupts?

thanks
 

You want to provide a delay of 0.2 seconds between the toggling of the state of LED? If the delay gets smaller & smaller then you won't be able to see the change in state of the LED because the change in state will be so fast. Can you once more post your requirement more clearly?
Regards,
Jerin. :)
 

Sorry, my english isn't so good :)

I have a piezo inside a drum. every time I hit the drum, the led must turn on and off for a moment..

So, the actual code isn't so good for doing this...
The hits might be very close.. so I need that, for every hit, the "routine" that turns the led on restarts from the beginning... like a "reset" maybe :)

I am not sure if I was clear...

Thanks
 

Actually it is working the same way as you have asked. When the drum hits the piezo material,the LED blinks & when the drum leaves it stops blinking isn't it?
That is what you are asking by the word "RESET" rite?
Regards,
Jerin. :)
 

yes but... I am not convinced :)

I'll do some tests, then I'll write here again, because I have some other things to ask...

Thank you Jerin!

see you soon ;)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top