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 inputs (A4/A5) using 16f688 w/int 8Mhz

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



Joined: 22 Nov 2003
Posts: 32

View user's profile Send private message

Problem with inputs (A4/A5) using 16f688 w/int 8Mhz
PostPosted: Mon Sep 27, 2004 11:48 am     Reply with quote

I'm having trouble getting the A4 and A5 inputs working on a 16F688. These pins are also used for the oscillator and I suspect that the problem is in the configuration. Has anyone had experience with this chip that could help me out? My test code is posted below.

Thanks.

Bob

Code:

#include <16F688.h>
#use delay(clock=8000000)
#fuses NOWDT, INTRC_IO, BROWNOUT, MCLR, NOCPD, NOPUT, NOIESO, NOFCMEN

// PIC PORT MAPPING
#byte _PORTA      = 0x105
#byte _PORTC      = 0x107

// PIC PIN MAPPING
#bit M1_IN     = _PORTA.5
#bit M2_IN     = _PORTA.4
#bit M1_OUT    = _PORTA.2
#bit M2_OUT    = _PORTC.0

void main()
{
   set_tris_a( 0b11111000 );
   set_tris_c( 0b11000110 );

   setup_oscillator( OSC_8MHZ );
   setup_adc_ports( sAN5|sAN6|VSS_VDD );
   setup_adc( ADC_CLOCK_INTERNAL );
   setup_timer_1( T1_DISABLED );
   setup_comparator( NC_NC_NC_NC );
   setup_vref( FALSE );

   while( TRUE )
   {
      M1_OUT = M1_IN;
      M2_OUT = M2_IN;
   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 27, 2004 2:34 pm     Reply with quote

I would try a much more simple test program. First, try toggling
pin A4. (ie., test it as an output). Then edit the code and change
it to toggle pin A5. Once that is working, then set it up to read pin A4
and output that state on Pin A5. (Then do vice-versa).

Don't setup the TRIS. Use the compiler in standard i/o mode (the
default mode) and let it handle the TRIS for this test.

Normally, in a simple test program, I wouldn't setup the ADC ports,
but I looked at the CCS startup code for this chip with PCM 3.212,
and it's not correct. It's supposed to setup port A as all digital and
turn off the A/D. It doesn't do it correctly. So that's why I put those
two lines in there.

Code:
#include <16F688.h>
#use delay(clock=8000000)
#fuses NOWDT, INTRC_IO, BROWNOUT, MCLR, NOCPD, NOPUT, NOIESO, NOFCMEN

void main()
{
setup_oscillator(OSC_8MHZ);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_comparator(NC_NC_NC_NC);

   while(1)
   {
    output_high(PIN_A4);
    delay_ms(500);
    output_low(PIN_A4);
    delay_ms(500);
   }
}
bcs99



Joined: 22 Nov 2003
Posts: 32

View user's profile Send private message

thanks
PostPosted: Mon Sep 27, 2004 5:35 pm     Reply with quote

I tried your suggestion and A4/A5 worked good as outputs, using the code you gave. However as inputs the value read was always high which led me to see the circuit problem Embarassed . Thanks.

Bob
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