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

PIC16F727 problem with input on pin

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








PIC16F727 problem with input on pin
PostPosted: Fri Aug 07, 2009 6:10 am     Reply with quote

Hello.
First of all i'm using PICC (CCS)

[+5V]---[ 10K pullup] ---|^|---[KEY (button)]---[GROUND]

[^] is the Pin of PIC.

All of keyboard Pic Pins have 10K Pullups. (in theory) when button is pressed the pin is grounded and should give logical 0;
However when im reading the value of pin without pushing the key it is readed as 0.

the pin list:
#define KDB0 PIN_A5
#define KDB1 PIN_A4
#define KDB2 PIN_A3
#define KDB3 PIN_A2
#define KDB4 PIN_A1
#define KDB5 PIN_A0
#define KDB6 PIN_B7
#define KDB7 PIN_B6
#define KRS PIN_B5
#define KRW PIN_B4
#define KE PIN_B3




2'nd problem is with PIN B0 and B1.

The pin are High after powerup. Then...
When i try to change value of the pin (no matter if i try to output HIGH or LOW by output_LOW or output_HIGH) the pin goes LOW.

When i use output_float(PIN_B0) and output_float(PIN_B1) the pin goes HIGH
but when i do that PIN_B2 goes LOW ;/


the concept is [+5V]------[RESISTOR]-----[PIC PIN].
in theory when pin goes LOW the diode flashes.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Aug 07, 2009 6:56 am     Reply with quote

you might want to post

1- what pic ?
2- YOUR CODE ( with #fuse statements )
3- your compiler version ( which you can get when you enter +V on the command line and hit enter )

based on the little i see - perhaps you are using a 16F62x ?
and perhaps the 'trouble' pins are set to be UART mode or whatever
but you aren't sharing enuf info to tell

so it is all surmise so far
Guest








PostPosted: Fri Aug 07, 2009 8:57 am     Reply with quote

the fuses are : #NOWDT, #PLLEN, #INTRC_IO, #NOPUT
+ device =* (duno what it is);
+ noadc

the wrote the test code ... that is olny based on output_HIGH/LOW and delay_ms( ) ...


if(input(KEYBOARD_KEY)) { blinkink code (output high, delay, low ect) } // this do not work

but : if (!input(KEYBOARD_KEY)) {blinkink code (output high, delay, low ect) } // this work all the time ... no matter if i push the button or not... for that reason i suspect that i've always get logical 0 on the pin.

the pic type is in the subject (16F727)
Guest








PostPosted: Fri Aug 07, 2009 9:01 am     Reply with quote

Some one wrote on the microchip forum (as a reply for my post there):


The pin's are configured as analog-inputs by default. You have to configure them to digital mode, before you can use them as digital i/o. This is explained in the i/o-ports chapter of the datasheet, where you'll find the description of the ANSELx - registers.

I think, your second problem with port b might be caused by this, too.

Hope this helps,
Stefan

// my question is : how to make pins to run in 'digital' mode ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 07, 2009 12:55 pm     Reply with quote

Quote:
how to make pins to run in 'digital' mode ?

It would help us to understand your posts if you identified yourself
as someone other than "guest". I wasn't sure who did the last post.
Also, if you're quoting someone, highlight the text and press the Quote
button. This will clearly show it's a quote.

To answer your question, normally CCS puts in start-up code (which can
be seen in the .LST file, just after main) you) to configure the Analog pins
for Digital i/o. When the PIC is newly supported, sometimes they don't
do this correctly.

To manually configure the Analog pins for digital i/o, do this:
Code:
setup_adc_ports(NO_ANALOGS);


Look in the .h file for your PIC to see other configuration options for
that function.
Guest








PostPosted: Sat Aug 08, 2009 2:13 pm     Reply with quote

First of all I'm posting as 'guest' cuz I've not created account... for now.

Software details:

IDE Version: 4.074
PCB Version: 4.074
PCM Version: 4.074
PCH Version: 4.074
PCB Version: 4.068
+
MPLAB IDE v8.30

I'm using ICD2 programmer/debugger.

Program details:
Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <16F727.h>
#device *=16
//#device ICD=TRUE // when used compiler returns error
#device adc=8
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOPUT                    //No Power Up Timer
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV19               
#FUSES PLLEN                 
#FUSES DEBUG                    //Debug mode for use with ICD
#FUSES NOVCAP               
#use delay(clock=8000000)

void main()
{

   port_b_pullups(FALSE);  // < EXTERNAL PULLUPS ALREADY INSTALLED
   setup_adc_ports(all_ANALOG);  // < SHOULD BE NO ANALOGS (all digital) but input returns 0... still.
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
   setup_oscillator(OSC_8MHZ);

...
}

IN THEORY ADC PINS SHOULD BE DIGITAL... BUT THEY ARE NOT...
they behave as analog inputs pins ;/

PLZ HLP ... somebody.. :((
Ttelmah
Guest







PostPosted: Sat Aug 08, 2009 2:37 pm     Reply with quote

What do you think 'NO_ANALOGS' means.
What do you think 'ALL_ANALOG' means.....

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Aug 08, 2009 2:48 pm     Reply with quote

If you have problem and you don't understand it, then make a simple
little program to test that one thing. In your case, you believe that
input pins are not acting as digital pins. So, make a program that reads
one pin over and over again. If the pin is read as a "logic high" level,
then send a '1' to the terminal window. If it's read as a "logic low" level,
then send a '0'. This will tell you if your code and hardware are working
correctly. Example:
Code:

#include <16F727.h>   
#fuses INTRC_IO,NOWDT,NOBROWNOUT,NOPUT
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//===============================
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_comparator(NC_NC_NC_NC);

while(1)
  {
   if(input(PIN_B0))  // Read pin B0
      putc('1');     // If read a high level, then send a '1'
   else
      putc('0');  // If read a low level, then send a '0'

   delay_ms(500);  // Wait 1/2 second
  }

}

The sample rate is kept at once every 1/2 second, so we don't fill up the
whole terminal window with 1's and 0's too quickly.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Aug 08, 2009 3:02 pm     Reply with quote

Quote:

setup_adc_ports(all_ANALOG); // < SHOULD BE NO ANALOGS (all digital) but input returns 0... still.

What do you think 'NO_ANALOGS' means.
What do you think 'ALL_ANALOG' means.....

This shows up a common problem with newbies. A 'pro' tells you to
change something, but it doesn't immediately solve the whole problem,
probably because there are multiple problems in the code.
So then a newbie changes the line back to the incorrect code.

Suppose your car wouldn't run properly. Suppose someone said that
one of your tires is flat. You pump it up, but the car still doesn't run.
There might be an additional problem of a dead battery.
Would you let the air out of the tire and make it flat again, simply
because fixing that problem didn't make the car start ?
Guest








PostPosted: Sun Aug 09, 2009 1:00 pm     Reply with quote

PCM programmer wrote:
If you have problem and you don't understand it, then make a simple
little program to test that one thing. In your case, you believe that
input pins are not acting as digital pins. So, make a program that reads
one pin over and over again. If the pin is read as a "logic high" level,
then send a '1' to the terminal window. If it's read as a "logic low" level,
then send a '0'. This will tell you if your code and hardware are working
correctly. Example:
Code:

#include <16F727.h>   
#fuses INTRC_IO,NOWDT,NOBROWNOUT,NOPUT
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//===============================
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_comparator(NC_NC_NC_NC);

while(1)
  {
   if(input(PIN_B0))  // Read pin B0
      putc('1');     // If read a high level, then send a '1'
   else
      putc('0');  // If read a low level, then send a '0'

   delay_ms(500);  // Wait 1/2 second
  }

}

The sample rate is kept at once every 1/2 second, so we don't fill up the
whole terminal window with 1's and 0's too quickly.




The readed value is 0 all the time...



ps. by setting NO_ANALOGS the compiler should set all pins in to the digital mode. (i think)...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Aug 09, 2009 3:13 pm     Reply with quote

Quote:
PCM Version: 4.074

The readed value is 0 all the time...

Your compiler version has bugs for the 16F727. The setup_adc_ports()
function does not make Port B into a digital port if you specify
NO_ANALOGS. To fix that bug, you need to add the two lines shown in
bold below:
Quote:

#include <16F727.h>
#fuses INTRC_IO,NOWDT,NOBROWNOUT,NOPUT
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#byte ANSELB = 0x186
//===============================
void main()
{
setup_adc_ports(NO_ANALOGS);
ANSELB = 0; // Set Port B to be all digital i/o

while(1)
{
if(input(PIN_B0)) // Read pin B0
putc('1'); // If read a high level, then send a '1'
else
putc('0'); // If read a low level, then send a '0'

delay_ms(500); // Wait 1/2 second
}

}



Also, the 16F727 has an internal voltage regulator. It requires an
external ceramic capacitor (0.1 to 1.0 uF) to operate correctly.
They want you to choose one of the following PIC pins for the capacitor:
pin A0, A5, or A6. Then add one of the following parameters to the
#fuses statement, to enable that pin: VCAP_A0, VCAP_A5, or VCAP_A6
For example, if you select pin A0, then use this fuse:
Quote:
#fuses INTRC_IO,NOWDT,NOBROWNOUT,NOPUT, VCAP_A0

Then put a 0.1 uF (100 nF) ceramic capacitor between pin A0 and ground.
Keep the leads very short.

Question: Do you really need to use this PIC ? It's a specialized PIC.
It has many features which are different from a normal PIC.
If you are just experimenting with PICs to learn about them, I suggest
that you choose a more simple, ordinary PIC, such as a 16F877 or
16F88, or something like that.


Also, there is no comparator on the 16F727. I put that line in there
because you had it in your program. I wasn't at a location where I
had access to the PIC data sheet. So don't use setup_comparator()
with this PIC.
Guest








PostPosted: Sun Aug 09, 2009 5:20 pm     Reply with quote

Tomorrow i'll try this solution Smile
I hope it 'll work Smile

Thx for your time...
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