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

Need Input(pin_A0) for PIC16F690 Help
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
RandyP



Joined: 15 Jun 2015
Posts: 16
Location: Dallas, TX

View user's profile Send private message Visit poster's website

Need Input(pin_A0) for PIC16F690 Help
PostPosted: Mon Jun 15, 2015 5:31 pm     Reply with quote

Hi everyone, this is my first time in the forum. I tried searching for a solution before posting.

Having a problem with a larger program caused me to try a simpler program to isolate the problem. I am using old stuff: ICD2, with a little PIC development board which came with a 16F690, CCS (~8 years old) inside MPLAB V7.31. I am using MPLAB V7.31 as it is the closest in age to the other stuff. I don't have (and can't find) the proper USB driver (Windows VISTA) for the ICD2 so I can't get into debug mode. I can program the device though.

Here's what I believe is my problem: I can turn output pins on and off easily enough but I can't seem to be able to input an input pin. My code is simple and by using output commands and delays (not in there now for simplicity) I can tell that the input looks like it is being by passed no matter what the condition of the input pin (high or low). Here is the program:



Code:

///////////Blinking LED Program///////////////////////////


// #device PIC16F690

#if defined(__PCB__)
#include <16C56.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_A3, rcv=PIN_A2)

#elif defined(__PCM__)
#include <16F690.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=4000000)
#use standard_io(A)
// #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#elif defined(__PCH__)
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#endif

void display() // blinking function
{
   output_high(56);
   delay_ms(2000);
   output_low(56);
   delay_ms(2000);
} // end display


void main()
{
   port_a_pullups(FALSE); // using port A as input
   output_low(pin_C0);    // my output pin



 LOOP:
  {
  while(input(pin_A0));              // Pin A0 is my input pin
     display();                            // I have tried Pin = input(A0);
  goto LOOP;                 // while(Pin), while(!Pin), etc
  }                                           // program goes to display function
   output_low(pin_C0);         // regardless if A0 is hi or lo
} // end main

_________________
Randy Principe
Electrical Engineering Technician
dyeatman



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

View user's profile Send private message

PostPosted: Mon Jun 15, 2015 6:02 pm     Reply with quote

Look at the datasheet page 6 and you will see A0 is used for several
functions including the ICSP Data line so you cant use it with the ICSP
plugged in. Try using RA2 after turning off CCP1 and AN2.
See setup_CCP1() and setup_ADC().
For debug the 16F690 requires a special header. See the ICD2 Readme.htm file
http://nnp.ucsd.edu/phy120b/pic_manuals_pdf/Readme_for_MPLAB_ICD_2.htm
_________________
Google and Forum Search are some of your best tools!!!!
RandyP



Joined: 15 Jun 2015
Posts: 16
Location: Dallas, TX

View user's profile Send private message Visit poster's website

PostPosted: Mon Jun 15, 2015 6:42 pm     Reply with quote

I will, thank you. I wish I understood the PIC micros better!
Thanks again. I will post when it works.
_________________
Randy Principe
Electrical Engineering Technician
RandyP



Joined: 15 Jun 2015
Posts: 16
Location: Dallas, TX

View user's profile Send private message Visit poster's website

Still not working
PostPosted: Tue Jun 16, 2015 4:32 pm     Reply with quote

Hi everyone,

As previously suggested I tried using pin A2, then A3 as my input pin.
I disabled the following:
CCP1, Comparator, Vref, Timer1, ADC, MCLR


In my real application I need 5 output pins and 5 input pins, with none of the things I disabled above. Just read 5 inputs one at time, and if high turn on a corresponding output pin. I chose the PIC16F690 because that's what I had and the little development board came with it. Maybe I am not using the best chip.

Here's my code if anyone can see anything wrong. I got rid of the function and loop. Any more help would be really appreciated. Thanks.

Code:

#if defined(__PCB__)
#include <16C56.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_A3, rcv=PIN_A2)

#elif defined(__PCM__)
#include <16F690.h>
#fuses HS,NOWDT,NOPROTECT,NOMCLR
#use delay(clock=4000000)
#use fast_io(A)   // needed for set_tris

#elif defined(__PCH__)
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#endif

int pin;

void main()
{   
   SETUP_CCP1(0);
   SETUP_COMPARATOR(NC_NC_NC_NC);
   SETUP_TIMER_1(0);
   SETUP_VREF(FALSE);
   SETUP_ADC(0);
   port_a_pullups(FALSE);
   set_tris_a(0x3f);
   set_tris_c(0x00);
   output_c(0x0f);   //visual... works here
   delay_ms(2000);
    

     pin=input(pin_A3);        //Pin_A3 tied to 5V on pwb
   output_high(pin_C0);      //visual... works here
   delay_ms(2000);            
                        
      output_bit(pin_C0,pin);      // 'pin' should be 1 or high
      if(pin)               
         {
               output_high(56);   //no output here  :cry:
               delay_ms(2000);
               output_low(56);
               delay_ms(2000);
         }
   else output_high(56);//visual... works here   
                 

} // end main

_________________
Randy Principe
Electrical Engineering Technician
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 16, 2015 5:25 pm     Reply with quote

Quote:
CCS (~8 years old)

What's your CCS version number ? It's given at the top of the .LST file,
which will be in your project directory after a successful compilation.
The version number will be a 4-digit number such as 3.249, 4.141, 5.046,
etc.

Quote:
with a little PIC development board which came with a 16F690,

Post the manufacturer and name (or part number) of the board. Post a
link to the website for the board if you have it.

Finally, post the power supply voltage for your board. Is it +5v ?
RandyP



Joined: 15 Jun 2015
Posts: 16
Location: Dallas, TX

View user's profile Send private message Visit poster's website

PostPosted: Wed Jun 17, 2015 7:55 am     Reply with quote

Hi PCM Programmer,

Thank you for responding to my post. Here is the info you requested:

1) CCS PCM C Compiler, Version 4.050
2) The development board is the "Low Pin Count Demo Board" that came with the PICkit 2 package. Page 41 of the Low Count Demo Board User's Guide.

http://ww1.microchip.com/downloads/en/DeviceDoc/Low%20Pin%20Count%20User%20Guide%2051556a.pdf

3) The demo board is powered by 5V

Thanks again,
Randy
_________________
Randy Principe
Electrical Engineering Technician
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Wed Jun 17, 2015 10:35 am     Reply with quote

I have used that board for a number of little projects. You do have to pay attention to the fact that RA0 and RA3 are connected to other things on the board. Seems to me there was something else that bit me too, but I can't remember just what it was. Currently, I have one running my heater for the hummingbird feeder for when it gets below freezing here in the Seattle area (surprisingly, there are a number of hummers that hang around all winter!). You might want to look at the 18F14K22 (or 26k22) chip. Very reasonable with more memory etc. in them and very reasonably priced (Digikey has them for $2.48 ea for the 14k22 and $3.42 for the 26k22 in single piece pricing). Lots of FLASH etc. to work with in those.

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
RandyP



Joined: 15 Jun 2015
Posts: 16
Location: Dallas, TX

View user's profile Send private message Visit poster's website

PostPosted: Wed Jun 17, 2015 1:54 pm     Reply with quote

Thanks. I had forgot to mention I removed the pot that is attached to RA0. Have you ever used the 16F690 by chance? It doesn't make sense that the input() command is not working. I am betting the setup for the chip is not complete... I am going to dig a little more before giving up. About 15 minutes! Thanks again.
_________________
Randy Principe
Electrical Engineering Technician
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 17, 2015 2:54 pm     Reply with quote

I modified your program to make it easier for me to test. It works.
I tested it on the Microchip Low Pin Count board with a 16F690, CCS vs.
5.046 and with a Pickit 3, and MPLAB 8.92. I compiled it in Release mode
(not debug mode). The Pickit3 was attached to the board the whole time.

The Low Pin Count board has LEDs on pins C0 to C3, so I used some of
the other LEDs too, not just the one on pin C0.
Code:

#include <16F690.h>
#fuses INTRC_IO,NOWDT, NOMCLR
#use delay(clock=4M)

int pin;

//=========================
void main()

int i;

output_c(0);  // All leds off
delay_ms(2000);
 
pin = input(PIN_A3);        //Pin_A3 tied to 5V on pwb

output_high(PIN_C0);      //visual... works here
delay_ms(1000);     
output_low(PIN_C0);       
                         
output_bit(PIN_C1, pin);      // 'pin' should be 1 or high


if(pin)               
  {
   for(i=0; i < 5; i++)   // Blink the LED several times
      {
       output_high(PIN_C0);   
       delay_ms(500);
       output_low(PIN_C0);
       delay_ms(500);
      }
  }
else   
  {
   output_high(PIN_C2);       
  }   
               
while(TRUE);
}
RandyP



Joined: 15 Jun 2015
Posts: 16
Location: Dallas, TX

View user's profile Send private message Visit poster's website

PostPosted: Wed Jun 17, 2015 4:54 pm     Reply with quote

Man, I am impressed you would do that. I really appreciated it. I copied your code and programmed it into my 16F690 and still same problem, that tells me I need to go to later version of MPLAB and invest in PICKIT 3 and newer CCS. Something changed between then and now in either MPLAB, CCS, and I need not to use the old ICD2.
_________________
Randy Principe
Electrical Engineering Technician
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 17, 2015 5:32 pm     Reply with quote

I tested it with PCM vs. 4.050 and it also works. So it's not the compiler.
RandyP



Joined: 15 Jun 2015
Posts: 16
Location: Dallas, TX

View user's profile Send private message Visit poster's website

PostPosted: Thu Jun 18, 2015 8:57 am     Reply with quote

That's a big help as money is tight. Thanks.
_________________
Randy Principe
Electrical Engineering Technician
RandyP



Joined: 15 Jun 2015
Posts: 16
Location: Dallas, TX

View user's profile Send private message Visit poster's website

16F690 PortA as digital inputs
PostPosted: Tue Jun 23, 2015 10:17 pm     Reply with quote

Inching closer. Thanks for the tip about using a Pickit 3 instead of a 2, and upgrading to MPLAB 8.92. I immediately was able to use RA0...RA3 as digital inputs. Been working on RA4 and RA5. I learned several things affect those two, especially the oscillator mode. I am now using the HFINTOSC. The datasheet specifically says that mode leaves RA4 and RA5 as digital inputs. I have resorted to configuring the various registers with assembly using the #ASM and #ENDASM commands. Here is what I have but RA4 and RA5 are not acting as digital inputs. I started off using an example from the datasheet on page 47. Any suggestions? Sorry if I over-commented.
Code:

#asm
BCF      STATUS,RP0; //Change to Bank 0
BCF      STATUS,RP1; //   "   "  "   "
CLRF     PORTA;     //Init PORTA
CLRF     0x0B;      //Setup Interupt Ctrl Reg

BCF     0x103,RP0; //Change to Bank 2
BSF     0x103,RP1; //Change to Bank 2
MOVLW   0xFF;      //Mov 1111 1111 into W register
MOVWF   0x115;     //Disable PORTB pullups 
CLRF    ANSEL;     //Setup ANSEL Reg, PORTA = Digital I/O
CLRF    ANSELH;    //Setup ANSEL Reg, PORTB,C = Digital I/O
MOVLW   0x00;      //Mov 0000 0000 into W register
MOVWF   0x116;     //Disable PORTA Interupt On Change1

BSF     0x83,RP0;  //Change to Bank 1
BCF     0x83,RP1;  //Change to Bank 1
CLRF    ADCON0;    //Disable A/D Conversion
CLRF    0x8C;      //Setup Peripheral Interupt Enable Reg1
CLRF    0x8D;      //Setup Peripheral Interupt Enable Reg2
MOVLW   0x0F;      //Mov 0000 1111 into W register
MOVWF   0x8E;      //Setup Power Ctrl Reg
MOVLW   0xE7;      //Mov 1110 0111 into W register
MOVWF   0x8F;      //Internal Clock, HFINTOSC, - RA4&5 = I/0
MOVLW   0x00;      //Mov 0000 0000 into W register
MOVWF   0x96;      //Disable PORTA Interupt On Change1
MOVLW   0x37;      //Mov 0011 0111 into W register
MOVWF   0x95;      //Disable PORTA pullups 
MOVLW   0x99;      //Mov 1000 1000 into W register
MOVWF   0x81;      //Setup OPTION REG
MOVLW   0xFF;      //Mov 1111 1111 into W register
MOVWF   0x85;      //Set PORTA pins to input
MOVLW   0x00;      //Mov 0000 0000 into W register
MOVWF   0x86;      //Set PORTB pins to output
MOVLW   0x00;      //Mov 0000 0000 into W register
MOVWF   0x87;      //Set PORTC pins to output

BCF     0x03,RP0;  //Change to Bank 0
BCF     0x03,RP1;  //   "   "  "   "
#endasm

_________________
Randy Principe
Electrical Engineering Technician
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 24, 2015 11:15 am     Reply with quote

Quote:
MOVLW 0xE7; //Mov 1110 0111 into W register
MOVWF 0x8F; //Internal Clock, HFINTOSC, - RA4&5 = I/0

Not true. The i/o status of those pins is controlled by fuse settings,
either INTRC or INTRC_IO. Use the following line to configure those
pins as i/o:
Code:
#fuses INTRC_IO



Your ASM code is not necessary. Most of the things you are doing
are already handled by the hardware or the compiler:

1. On power-on reset, the PIC sets registers to their initial state.
See this table in the 16F690 data sheet. Look at the POR, BOR column:
Quote:
TABLE 2-1: PIC16F631/677/685/687/689/690 SPECIAL FUNCTION REGISTERS SUMMARY BANK 0


2. Start-up code is inserted by the compiler at the beginning of main().
This code initializes certain registers. You can see this code by looking at
the .LST file.

For the initializations that are not done by the two methods above, you
can use CCS functions to achieve them in most cases. In the remaining
cases, you can use #byte statements to define the register addresses
and then set the named registers to your init values in main(). Your ASM
code should not be used in a "true" CCS program.
RandyP



Joined: 15 Jun 2015
Posts: 16
Location: Dallas, TX

View user's profile Send private message Visit poster's website

PostPosted: Wed Jun 24, 2015 1:01 pm     Reply with quote

Yes, I see on page 38 I read the last line of the INTOSCCIO (which lets the OSC1 & OSC2 pins - RA4,RA5 available for I/O) I thought I read that under the next heading HFINTOSC. No wonder I could not get them to work. The reason for all the assembly was to try and find the register that was not letting me use RA4/5 as inputs. I will try your suggestions. Thanks.
_________________
Randy Principe
Electrical Engineering Technician
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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