CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Problem with dimming output

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
aldina



Joined: 09 Oct 2009
Posts: 26

View user's profile Send private message Send e-mail

Problem with dimming output
PostPosted: Wed Mar 02, 2022 12:26 pm     Reply with quote

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: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Mar 02, 2022 1:27 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Mar 02, 2022 1:33 pm     Reply with quote

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
                               -
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group