View previous topic :: View next topic |
Author |
Message |
rb8720
Joined: 04 Jun 2007 Posts: 13
|
Help with flashing led |
Posted: Mon Jun 04, 2007 1:03 pm |
|
|
I am using the command GPIO = (1<<4) to send a signal to the led to turn it on and GPIO = 0 to turn it off. The problem is the Annode of the led has to be connected to the pin and Cathode to ground. I need to do just the opposite and flash the led with the cathode to the pin and the annode to power. What command would i use to do this.
Thanks,
rb8720 |
|
|
inservi
Joined: 13 May 2007 Posts: 128
|
|
Posted: Tue Jun 05, 2007 12:51 am |
|
|
Hello,
If you use a general purpose pin then with anode to power and cathode to the pin (with resistor) , GPIO = (1<<4) will switch the led off and GPIO = 0 will switch the led on.
for sample:
Code: |
...
output_high(PIN_B0); // The led is off
...
output_low(PIN_B0); // The led is on
...
|
Best regards,
dro _________________ in médio virtus |
|
|
Guest
|
|
Posted: Tue Jun 05, 2007 9:10 am |
|
|
Inservi,
Thanks for the reply. How could I apply that to more than one pin. What I need to happen is Pin 5 on, Delay, pin 5off, delay, Pin 5 on, delay, Pinn5 off, delay, Pin5 and pin2 on, delay, pin 5 and 2 off, delay,pin 3 on, delay, pin3 off, delay pin3 on, delay pin 3 off, delay, Repeat sequence.
I have the fill doagram of how it is wired. How would i display that on here ? |
|
|
rb8720
Joined: 04 Jun 2007 Posts: 13
|
|
Posted: Tue Jun 05, 2007 9:11 am |
|
|
BTW, I am the gues in the reply, I forgot to login. |
|
|
rb8720
Joined: 04 Jun 2007 Posts: 13
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Jun 05, 2007 9:48 am |
|
|
The link isn't working. |
|
|
rb8720
Joined: 04 Jun 2007 Posts: 13
|
|
|
inservi
Joined: 13 May 2007 Posts: 128
|
|
Posted: Wed Jun 06, 2007 1:44 am |
|
|
Hello,
I assume that 'pin 5 on' is pin 5 high then led off.
Here is a very simple example. I added a sample to the use of the pre-processor for delay and pin 3.
Code: | #include <12F683.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOCPD //No EE protection
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES PUT //Power Up Timer
#FUSES BROWNOUT //Reset when brownout detected
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#use delay(clock=8000000)
#define pin5On output_high( PIN_A5 ) ;
#define pin5Off output_low( PIN_A5 ) ;
#define pin2On output_high( PIN_A2 ) ;
#define pin2Off output_low( PIN_A2 ) ;
#define pin3On output_high( PIN_A3 ) ;
#define pin3Off output_low( PIN_A3 ) ;
#define yourDelay 1000
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC);
setup_vref(FALSE);
setup_oscillator(OSC_8MHZ);
while(true) {
output_high( PIN_A5 ) ;
delay_ms( yourDelay ) ;
output_low( PIN_A5 ) ;
delay_ms( yourDelay ) ;
output_high( PIN_A5 ) ;
delay_ms( yourDelay ) ;
output_low( PIN_A5 ) ;
delay_ms( yourDelay ) ;
output_high( PIN_A5 ) ;
output_high( PIN_A2 ) ;
delay_ms( yourDelay ) ;
output_low( PIN_A5 ) ;
output_low( PIN_A2 ) ;
delay_ms( yourDelay ) ;
pin3On ;
delay_ms( yourDelay ) ;
pin3Off ;
delay_ms( yourDelay ) ;
pin3On ;
delay_ms( yourDelay ) ;
pin3Off ;
delay_ms( yourDelay ) ;
}
} |
If this logique is not your, you can easily change the 'output_high' by output_low'
I suppose that your diagram is not complete because so the electronic is not right.
dro. _________________ in médio virtus |
|
|
Guest
|
|
Posted: Tue Jul 10, 2007 12:55 pm |
|
|
Inservi, I think that is close to what i need but for LED_on the output has to go low. The outpunt pins are wired to the ground of an oprocoupler and must go low to activate it.
Thanks,
RB8720 |
|
|
inservi
Joined: 13 May 2007 Posts: 128
|
|
Posted: Tue Jul 10, 2007 1:43 pm |
|
|
Hello,
You are right. you need to change "high" by "low" and "low" by "high".
Using pre-processor is a good way to control this kind of modifications.
dro. _________________ in médio virtus |
|
|
|