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

fix tris i/o bits

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



Joined: 27 Jun 2006
Posts: 39

View user's profile Send private message

fix tris i/o bits
PostPosted: Wed Jul 05, 2006 2:07 pm     Reply with quote

Im sure this is a newb question, but i have not been able to find an answer by searching the reference manual or forums.

Im am trying to fix an0 and an1 on 16f88 as inputs. I am trying to use the rest of porta pins (2-7) as outputs or inputs. I need to be able to use the set_port_x() without affecting an0 and an1. I need output pins on porta to change simultaneously, as they are switching inputs on a toggled motor control driver.

Is there a command that will fix these the an0,1 ports and not affect them when using the set_port_x() function??

Thank you for your help!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 05, 2006 2:29 pm     Reply with quote

You could use the #use fixed_io() statement, and specify which
pins on Port A are to be used as outputs. All remaining pins on
Port A are then considered to be inputs by the compiler.

Code:

#include <16F88>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

#use fixed_io(A_outputs = PIN_A2, PIN_A3, PIN_A4)

//======================================
void main()
{
int8 status_0;
int8 status_1;


output_a(0x00);

delay_us(50);

output_a(0xFF);

status_0 = input(PIN_A0);

status_1 = input(PIN_A1);


while(1);
}


This answer assumes that all pins are digital i/o.

Also be aware that pin RA5 is an input-only pin on the 16F88.
fvnktion



Joined: 27 Jun 2006
Posts: 39

View user's profile Send private message

PostPosted: Wed Jul 05, 2006 3:04 pm     Reply with quote

Thanks for the reply.

I am not sure if this will be conflicting using the ADC, as they will be used as analog inputs rather than digital inputs?? Does the fix_io function take this into account?

essentially what i am trying to do is this:
#include <16F88>
#device ADC=10
#use delay(clock=8000000)
#fuses INTRC_IO,NOWDT,NOMCLR,NOPROTECT,NOCPD,NOBROWNOUT,NOLVP//INTRC_IO //nolvp for lcd
//#use fixed_io(a_outputs=PIN_A0, PIN_A1)


void main() {
long int Tvalue,tilt;
//setup adc values
setup_oscillator(OSC_8MHZ);//sets internal osc multiplier
SETUP_ADC_PORTS(sAN0 | VSS_VDD);
SETUP_ADC(ADC_CLOCK_DIV_32);




while(1){
//read adc value
Tvalue = READ_ADC(ADC_START_AND_READ);

//adc tilt value eval

if (Tvalue>1015)
tilt = 0b00000100; //Tiltdown
else if (Tvalue>991)
tilt = 0b00011000;//tiltup
else if (Tvalue>950)
tilt = 0b00001100; //0b07;//tiltLeft
else if (Tvalue>915)
tilt = 0b00010000; //0b0001111;tiltRight
else
tilt = 0; //0;

OUTPUT_A(tilt);
}


reads portan0, evaluates state, outputs on porta, not using pina0,pina1.

Is there an easier or better approach to using port a as input/output simultaneously with Analog inputs and the ADC??

Thank you for the help!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 05, 2006 4:34 pm     Reply with quote

You need to make the changes shown in bold below.
Quote:
#include <16F88>
#device adc=10
#use delay(clock=8000000)
#fuses INTRC_IO,NOWDT,NOMCLR,NOPROTECT,NOCPD,NOBROWNOUT,NOLVP

// Select pins on Port A which will be used for output only.
// All unspecified pins on Port A will be input-only pins.
#use fixed_io(A_outputs = PIN_A2, PIN_A3, PIN_A4)
// Note that on the 16F88, PIN_A5 is an input only pin.
// It can't ever be an output pin.

//===========================
void main()
{
long int Tvalue, tilt;

setup_oscillator(OSC_8MHZ);
setup_adc_ports(sAN0 | VSS_VDD);
setup_adc(ADC_CLOCK_DIV_16); // Use DIV_16 for 8 MHz

set_adc_channel(0); // Must select ADC channel 0

while(1)
{
Tvalue = read_adc(); // Default mode is to read ADC

if(Tvalue > 1015)
tilt = 0b00000100; // Tiltdown
else if(Tvalue > 991)
tilt = 0b00011000; // tiltup
else if (Tvalue > 950)
tilt = 0b00001100; //0b07;//tiltLeft
else if (Tvalue>915)
tilt = 0b00010000; //0b0001111;tiltRight
else
tilt = 0;

output_a(tilt);
}

}
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