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 support@ccsinfo.com

problem with detect high with any pin that set to input
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
amir6682



Joined: 23 May 2011
Posts: 14

View user's profile Send private message

problem with detect high with any pin that set to input
PostPosted: Fri May 27, 2011 7:26 am     Reply with quote

I want to write program that detect high for example if I set them to high, some led turn on. The program that was written with myself is:
Code:

#include <16f887.h>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 20000000)

void main()
{
set_tris_C(0xFF);       ' input
set_tris_D(0xF0);        'output
OUTPUT_C(0x00);
OUTPUT_D(0x00);

X:
     if(input(PIN_C0)==1)       // Read the switch pin.
      output_high(PIN_D0);  // If it's not pressed, turn off the LED
      else
      output_low(PIN_D0);  // If it's pressed, turn on the LED
 
     if(input(PIN_C1)==1)       // Read the switch pin.
      output_high(PIN_D1);  // If it's not pressed, turn off the LED
      else
      output_low(PIN_D1);  // If it's pressed, turn on the LED

   
  goto X;
}

It is good with Proteus but have a problem with micro in real hardware. In start some led is on without anything was high and when one of input port set to high, some led have weak light same that turned on. Question Question Exclamation Exclamation
temtronic



Joined: 01 Jul 2010
Posts: 9171
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri May 27, 2011 7:34 am     Reply with quote

You have to read the datasheet and see what internal peripherals(adc,ccp,uart,etc.) are on the same pins that you are using and disable those peripherals. The device.h file will have a list of configuration options listed.

Also, it's best to let the compiler contorl the 'set_tris_...' functions, as one wrong bit set by you will not allow the program to work properly.

Also, Proteus is FULL of errors, as you've found out!
amir6682



Joined: 23 May 2011
Posts: 14

View user's profile Send private message

PostPosted: Fri May 27, 2011 10:03 am     Reply with quote

Can you help me, and get the sample code to me that turns the led on when its input is high.
LED1---> Pin B0
LED2---> Pin B1
LED3---> Pin B2
LED4---> Pin B3
LED5---> Pin B4
when Pin C0 ---> high ---> LED1 ON
C1---->high---> LED2 ON
....
So thanks.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri May 27, 2011 11:09 am     Reply with quote

Quote:
#include <16f887.h>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 20000000)

void main()
{
set_tris_C(0xFF); ' input
set_tris_D(0xF0); 'output
OUTPUT_C(0x00);
OUTPUT_D(0x00);

You are using Port C for input pins for the switches. Don't set it to
be an output port. In CCS, the output_c() function also sets the TRIS
for Port C to be 0x00 (all outputs). Delete the line shown in bold above.

Also, make sure that your external circuit on each switch pin looks like this:
Code:

           +5v
            |
            <
            > 4.7K       
            <         ___  Switch 
To          |        _|_|_
PIC -----------------o   o------
pin                            |             
                              --- GND
                               -   
amir6682



Joined: 23 May 2011
Posts: 14

View user's profile Send private message

PostPosted: Fri May 27, 2011 11:29 am     Reply with quote

Thank you, I migrate from mikrobasic to ccs recently and I think that here is same that but I'm in wrong. We have to clear port before declare it to input or output in there. But my mean is:
Micro <0--------------------0> +4v from Op-amp <0------------0>Sensor
I want to detect output from 10 op-amp to LED light.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri May 27, 2011 12:33 pm     Reply with quote

Quote:
Can you help me, and get the sample code to me that turns the led on when its input is high.
LED1---> Pin B0
LED2---> Pin B1
LED3---> Pin B2
LED4---> Pin B3
LED5---> Pin B4
when Pin C0 ---> high ---> LED1 ON
C1---->high---> LED2 ON
....


The most simple way to do this is shown below. Just read Port B and
write it out to Port C.
Code:

#include <16f887.h>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 20000000)

//=======================
void main()
{
int8 temp;

while(1)
  {
    temp = input_b();
    output_c(temp);   
  }

}
amir6682



Joined: 23 May 2011
Posts: 14

View user's profile Send private message

help
PostPosted: Sun May 29, 2011 2:23 am     Reply with quote

Thank, i do it but i have problem. Any input port is high but all Led is on. And when i change input port any change see on led. I want when input is low, led off too and reverse.
temtronic



Joined: 01 Jul 2010
Posts: 9171
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun May 29, 2011 5:01 am     Reply with quote

LED wiring might be reversed ?

'positive logic' LED

From port pin----470R resistor----anode of LED--|>|---cathode to GROUND.

This way, a 'high' on the port pin will turn on the LED,a 'low' will turn it off.
amir6682



Joined: 23 May 2011
Posts: 14

View user's profile Send private message

PostPosted: Sun May 29, 2011 1:27 pm     Reply with quote

anything reversed.LED connected with 320 Ohm to ground.
Micro <0-------0> 320Ohm<0-------0>A LED<0-----0>K LED<0-----0>GND
in start and without any change<LEDs are on.


Last edited by amir6682 on Sun May 29, 2011 2:29 pm; edited 1 time in total
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Sun May 29, 2011 2:15 pm     Reply with quote

A 320 Ohm resistor should be fine.
_________________
The search for better is endless. Instead simply find very good and get the job done.
amir6682



Joined: 23 May 2011
Posts: 14

View user's profile Send private message

PostPosted: Sun May 29, 2011 2:32 pm     Reply with quote

My problem is that inputs don't appear on LED. When any change happen, anything changed on LED, and LED turn on forever.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun May 29, 2011 4:43 pm     Reply with quote

Post a schematic of your board.
amir6682



Joined: 23 May 2011
Posts: 14

View user's profile Send private message

PostPosted: Sun May 29, 2011 10:29 pm     Reply with quote

http://031.img98.net/out.php/i360887_amir.bmp
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun May 29, 2011 10:47 pm     Reply with quote

Post your compiler version. It's a 4-digit number given at the top of the
.LST file. It looks like this type of number:
http://www.ccsinfo.com/devices.php?page=versioninfo
amir6682



Joined: 23 May 2011
Posts: 14

View user's profile Send private message

PostPosted: Sun May 29, 2011 11:12 pm     Reply with quote

4.120
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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