View previous topic :: View next topic |
Author |
Message |
aldina
Joined: 09 Oct 2009 Posts: 26
|
Problem with dimming output |
Posted: Wed Mar 02, 2022 12:26 pm |
|
|
Hi,
Can you help me with a basic output question:
I'm trying to dimming a LED on C1 output pin when C4 input is HIGH and C0 is LOW. When C0 is HIGH and (C4 is HIGH or LOW), LED is ON without dimming. Here is my code:
Code: |
#include <16F526.h>
#device ADC=8
#fuses INTRC,NOWDT,MCLR,PROTECT,IOSC8,NOPROTECTDF
#use delay(clock=8000000)
void main(void)
{
int8 i = 0;
// Configuration of inputs
// C0 - to have LED without Dim.
// C4 - to have LED with Dim.
SET_TRIS_C(0x11); // 01 0001
setup_comparator(NC_NC_NC_NC);
// Configuration of outputs
output_low(PIN_C1); // LEDs Output
while (true)
{
//restart_wdt();
if((input(PIN_C0) == 1) && (input(PIN_C4) == 1))
{
OUTPUT_HIGH(PIN_C1);
delay_ms(1);
}
if((input(PIN_C0) == 1) && (input(PIN_C4) == 0))
{
OUTPUT_HIGH(PIN_C1);
delay_ms(1);
}
if((input(PIN_C0) == 0) && (input(PIN_C4) == 1))
{
for(i=0 ; i<3 ; i++) // PWM:
{
OUTPUT_HIGH(PIN_C1);
delay_ms(1);
OUTPUT_LOW(PIN_C1);
delay_ms(10);
}
}
if((input(PIN_C0) == 0) && (input(PIN_C4) == 0))
{
OUTPUT_LOW(PIN_C1);
delay_ms(1);
}
} // while
} // main
|
I always have 0.4V on PIN C4 input, even when I don't supply it. I don't know why.
And as I have C4 input I have always dimming on C1 output (LEDs).
I search for some shunt on the PCB but i can't found any. But when I'm measuring C4 voltage I have 0.4V but LEDs go Down (turn off).
Thank you for any help. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Wed Mar 02, 2022 1:27 pm |
|
|
while I don't have that PIC
... first your delays are too FAST ! try 100ms..
normal human eyes are sloooow responders...
...if you're measuring with a DVM, they only sample at a 3Hz rate, again real sloooow
..delete the 'protect' fuse.... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 02, 2022 1:33 pm |
|
|
What are the connections to pins C0 and C4 ?
Are they push-buttons ? If so, you need the
circuits to look something like this:
Code: |
+5v
|
<
> 4.7K
< ___ Switch
To | _|_|_
PIC -----------------o o------
pin C0 |
--- GND
-
+5v
|
<
> 4.7K
< ___ Switch
To | _|_|_
PIC -----------------o o------
pin C4 |
--- GND
-
|
|
|
|
|