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

16F88: Inable to read pin

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







16F88: Inable to read pin
PostPosted: Wed Apr 20, 2005 2:28 pm     Reply with quote

hi!

I've got a problem with my PIC16F88 application: independent of what is going on, I always get a 1 when I read the PIN_A4 with input(PIN_A4).
I used following code:

Code:

#include <16F88.h>
#include "stdlib.h"

#fuses NOLVP, NOPUT, NOMCLR, BROWNOUT, NOWRT, NODEBUG, NOWDT, INTRC_IO, NOCPD

#byte OSCCON = 0x8F

#use delay(clock=4000000)

void main()

{


   OSCCON = 0b01101010;


   
   port_b_pullups(TRUE);
   setup_adc_ports(ADC_OFF|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_spi(FALSE);
   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);
   setup_vref(FALSE);
   
   
   
   set_tris_a(0b00011000);
   set_tris_b(0b00110000);

   output_float(PIN_A4);
   output_float(PIN_A3);
   

   port_b_pullups(true);
   
   while (1)
   {

      output_bit(PIN_B1, 1);
      output_bit(PIN_A0, input(PIN_A4));
      delay_ms(50);
      output_bit(PIN_B1, 0);
      delay_ms(50);
   }

}



The flashing LED on PIN_B1 indicates, that the program is running. The LED on PIN_A0 should change its state depending on the state on PIN_A4, but the LED always glows!
Does anybody know what to do in this case?
Thank you![/code]
i2c2k
Guest







PostPosted: Wed Apr 20, 2005 2:29 pm     Reply with quote

By the way I use the compiler version 3.150
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 20, 2005 3:06 pm     Reply with quote

In vs. 3.150, the setup_comparator() and setup_vref() functions don't
work properly for the 16F88. The comparators are being turned on
by the CCS code, when they should be turned off. This is what's causing
your problem.

To fix this problem, you need to comment out the calls to those functions,
and put in code to set the comparator and vref registers directly.
You need to make the following changes to your program, as shown in
bold below:


#byte CMCON = 0x9C
#byte CVRCON = 0x9D


void main()
{
OSCCON = 0b01101010;

port_b_pullups(TRUE);
setup_adc_ports(ADC_OFF|VSS_VDD);
setup_adc(ADC_OFF);
setup_spi(FALSE);
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);
CMCON = 7;

// setup_vref(FALSE);
CVRCON = 0;
i2c2k
Guest







PostPosted: Wed Apr 20, 2005 10:52 pm     Reply with quote

thanks very much!
do you know in which version this problem is fixed?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 20, 2005 11:31 pm     Reply with quote

Those two problems were certainly fixed by vs. 3.222. I just did a
test compilation with that version and the .LST file code looks OK.
It was probably fixed a lot earlier than that, but I don't want to go through
and test a lot of different versions in order to find the exact one.
If you have a question about a certain version, post that version
and I'll check it.
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