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

unable to read a digital pin from the E-port

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



Joined: 15 May 2008
Posts: 3

View user's profile Send private message

unable to read a digital pin from the E-port
PostPosted: Tue Dec 29, 2009 10:54 am     Reply with quote

Hello pic users,

I am unable to get the right response of any of the digital pins of the E-port from a 18f46k20. Can someone tell me what I am doing wrong?

Kind regards

citroenie
CCS PCH C Compiler, Version 4.057, 32216

My source code :
Code:

#include <18F46K20.h>

#fuses NOWDT,NOPROTECT,NOMCLR,INTRC_IO,NOLVP, NOWDT
#use delay(clock=4000000)

#use fast_io(a)
#use fast_io(b)
#use fast_io(c)
#use fast_io(d)
#use fast_io(e)

//=========================================   

void init(void)
   {
     setup_adc_ports(NO_ANALOGS);
     setup_adc(ADC_OFF);

     setup_comparator(NC_NC_NC_NC);

     setup_spi(FALSE);
     setup_wdt(WDT_OFF);

     setup_timer_0(RTCC_INTERNAL | RTCC_DIV_1);
     setup_timer_1(T1_DISABLED);
     setup_timer_2(T2_DISABLED, 255, 1);
     setup_timer_3(T3_DISABLED | T3_DIV_BY_1);

     set_tris_a(0b11111111);
     set_tris_b(0b11111111);
     set_tris_c(0b11111111); 
     set_tris_d(0b00000000);
     set_tris_e(0b11111111);
   }

//=========================================

void main(void)
   {
   boolean pine0;
   boolean pine1;
   boolean pine2;

   init();

   while(true)
      {
      pine0 = input_state(PIN_E0);
      pine1 = input_state(PIN_E1);
      pine2 = input_state(PIN_E2);

      output_bit(PIN_D2, pine0);
      output_bit(PIN_D3, pine1);
      output_bit(PIN_D4, pine2);

      
      }
   }
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 29, 2009 1:01 pm     Reply with quote

1. How are you testing this ? In a simulator or on real hardware ?
How do you know that it's failing ?

2. What external circuits are connected to the PortE and PortD pins ?

3. What voltage levels are you applying to the PortE pins ?
Guest








PostPosted: Tue Dec 29, 2009 2:04 pm     Reply with quote

Thanks for the reply.

I'm testing this on real hardware.

There are LEDS connected at the Dport. These LEDS will light up when a Dpin goes low. I can drive these pins by software. This seems to work.

The Epins are pulled high with a resistor of 10k to 5volt. It is shorted to ground to make an signal.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 29, 2009 2:53 pm     Reply with quote

Are the pins grounded by pressing a push-button switch ? How are
they grounded ?

I suggest trying a program that is very simple, and doesn't do anything
out of the ordinary, as shown below. It only tests PIN_E0 and does
output on PIN_D2.
Code:

#include <18F46K20.h>
#fuses INTRC_IO,NOPROTECT,NOMCLR,NOLVP, NOWDT
#use delay(clock=4000000)

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

while(true)
  {
   pine0 = input(PIN_E0);

   if(pine0)
      output_high(PIN_D2);
   else
      output_low(PIN_D2);

   delay_ms(100);
  }

}
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