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

inputs not working

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



Joined: 07 May 2004
Posts: 263

View user's profile Send private message

inputs not working
PostPosted: Wed May 20, 2009 7:20 pm     Reply with quote

I'm using a pic18f2221 and CCS pch 4.086.

In my program I'm reading some pins, but they always read low, even when pulled to 5V.
Here is the code
Code:

    if(Dio_states[0]==2)//input
        values[10]=input(PIN_B5);
    if(Dio_states[1]==2)//input
        values[11]=input(PIN_B4);
    if(Dio_states[2]==2)//input
        values[12]=input(PIN_B3);
    if(Dio_states[3]==2)//input
        values[13]=input(PIN_B2);
    if(Dio_states[4]==2)//input
        values[14]=input(PIN_B1);
    if(Dio_states[5]==2)//input
        values[15]=input(PIN_B0);
    if(Dio_states[6]==2)//input
        values[16]=input(PIN_C7);
    if(Dio_states[7]==2)//input
        values[17]=input(PIN_C6);
    if(Dio_states[8]==2)//input
        values[18]=input(PIN_C5);
    if(Dio_states[9]==2)//input
        values[19]=input(PIN_C2); 
printf("\r\nStates");
for(i=0;i<10;i++)
    {
        printf("%d ",Dio_states[i]);
    }
printf(" values ");
for(i=10;i<20;i++)
    {
        printf("%d ",values[i]);
    }



The states always start off as '2' and they are not getting changed. Looking at the printF output I get
Digital values 0 0 0 0 0 0 0 0 0 0 States2 2 2 2 2 2 2 2 2 2
this is with pin B4 pulled High. I checked it with a voltmeter and it is really 5V. The weird part is that pin B5,C7,C6, C5 and C2 work, but the others don't. The others always return a 0.

I wrote a simple program that does nothing but read the pins and it works
Code:

void main ()
{   
    while (1)
    {
        printf("%d %d %d %d %d %d %d %d %d %d\r\n",input(PIN_B5),input(PIN_B4),input(PIN_B3),input(PIN_b2),input(PIN_b1),input(PIN_B0),input(PIN_C7),input(PIN_C6),input(PIN_C5),input(PIN_C3));
        delay_ms(100);
    }
}


I do not have fastIO enabled.
Any idea what could be causing this?

Thanks
Ringo
_________________
Ringo Davis
Ringo42



Joined: 07 May 2004
Posts: 263

View user's profile Send private message

PostPosted: Wed May 20, 2009 8:17 pm     Reply with quote

I found the line that kills the inputs, but it still makes no sense.

This code does the same thing
Code:

#include <18F2221.h>
#device adc=10
#fuses HS,noWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)

#include <stdlib.h>
#use rs232(baud=19200, xmit=PIN_C0, rcv=PIN_C1)


void main ()
{   
    setup_adc_ports(All_ANALOG);
    setup_adc( ADC_CLOCK_INTERNAL );
    while (1)
    {
        printf("%d %d %d %d %d %d %d %d %d %d\r\n",input(PIN_B5),input(PIN_B4),input(PIN_B3),input(PIN_b2),input(PIN_b1),input(PIN_B0),input(PIN_C7),input(PIN_C6),input(PIN_C5),input(PIN_C3));
        delay_ms(100);
    }
}

If I take out the 2 ADC lines then it works great. I can't eliminate them though becasue I'm using ADC as well. I updated to the latest compiler 4.093 as well, still no luck.

Any ideas?
Ringo
_________________
Ringo Davis
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Wed May 20, 2009 8:56 pm     Reply with quote

Look at the data sheet and see on which pins ALL the Analog ports you
enabled are located and that will explain why enabling ALL_ANALOG has
the effect you are seeing.

Enabling the ADC overrides the other functions on those pins. To
enable just some of the ADCs look in the 18F2221.h header file for the
ADC control definitions.
Ringo42



Joined: 07 May 2004
Posts: 263

View user's profile Send private message

PostPosted: Wed May 20, 2009 9:02 pm     Reply with quote

Thanks, I just found this. This is the first pic I used that has ADC pins on something other than port A and E.
_________________
Ringo Davis
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