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.

[PIC] Push button problem led is not going off it is always high instead

Status
Not open for further replies.

Manjuhb

Newbie level 6
Joined
Dec 2, 2015
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
149
Hi All,

I have written simple code to blink an LED when switch is pressed. But problem I'm facing here is when I press the button LED is going high but it is not turning off after 10sec delay. Please let me where is the problem in the below code. I'm using CCS C compiler and here RA3 is defined as input
port and RC0 is defined output port.
Code:
WHILE (1)
   {
          
      IF (RA3 == 0)
      {
       RC0 = 1 ;
       delay_ms(10000);
       RC0 = 0 ;
      }
   }
 

Almost certainly it IS going off but turning on again straight away. The code does not visually blink the LED, if RA3 is low it turns it on, waits 10 seconds, turns it off then turns it back on again. It probably blinked off so fast you didn't notice it.

I suspect what you want to do is make it turn on for 10 seconds, turn off then wait until the switch is pressed again. If you want to do that, you need to add a pull-up resistor (~10K) between RA3 and VDD so it doesn't immediately re-enter the loop.

If you want it flash continously 10s on, 10s off when RA3 is low, add another delay after "RC0 = 0;" so it has timed on AND timed off periods in the loop.

Brian.
 

Hi,

Code:
WHILE (1)
   {
      RC0 = 0 ;
      IF (RA3 == 0)
      {
       RC0 = 1 ;
       delay_ms(10000);
      }
   }

Now the RC=0 is outside the "IF"
This ensure that RC in either case switches to 0...

Klaus
 

Hi Brian,

Thanks for your reply. Yes I have a 10K ohm resister across the RA3 and GND. When I press the switch RA3 will connect to the GND and when I release it will be connected to VCC through 10KK.

The Logic I need is the when I press the button RC0 should come on for 10 sec then it should go off.

But here the problem is when I release the button delay program is not executing and RC0 is not going low.

Please help me with this logic in CCS.

Thanks In advance,

- - - Updated - - -

Hi Klaus,

Thanks for your reply Yes I have tried this with if else condition but the problem is when I release the button immediately the LED is going off. Here that delay program is not executing.
 

Hi,

Thanks for your reply. Yes I have a 10K ohm resister across the RA3 and GND. When I press the switch RA3 will connect to the GND and when I release it will be connected to VCC through 10KK.
Confusing. Are you sure the description is correct?

When button is pressed, then port =0. Correct?
When port = 1, then LED is ON. Correct?

Klaus

- - - Updated - - -

Hi,

The 10s count from button press, not from button release.

If you press it for 9 seconds, then the LED is ON for 10 seconds.
If you press it for 11 seconds it is retriggered and the LED is ON for 20 seconds.

In general the LED is ON for n x 10s. N is integer, so 10s, 20s, 30s...

If you see other timing, then maybe delay() can't work with a parameter of "10000".

Klaus
 

Hi
as I remember CCS had problem with output to PORT, and there were output_low() and output_high() commands.
First of all try to check if led blin works
Code:
WHILE (1)
   {
      RC0 = 0 ;
       delay_ms(10000);
      RC0 = 1 ;
       delay_ms(10000);
   }

how about ANSEL ?
I dont remamber if delay_ms accepts more than int8 type data ???
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top