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 help with i/o

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



Joined: 14 Jan 2008
Posts: 5

View user's profile Send private message

Need help with i/o
PostPosted: Tue Jan 15, 2008 11:49 am     Reply with quote

I just started C programing and am trying to input from portc and then
output to portb but it's not looping,

Please help

#include "C:\test\main.h"

void main()
{

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);

// TODO: USER CODE!!

set_tris_a(0xff); // set porta as inputs
set_tris_b(0x00); // set portb as outputs
set_tris_c(0xff); // set portc as inputs
output_b(0x00); // clear portb


{
input_c(); //
output_b(input_c()); //
}

}


Last edited by agompert on Tue Jan 15, 2008 12:38 pm; edited 5 times in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jan 15, 2008 12:00 pm     Reply with quote

Please use a title for topic that describes the problem, such as
Quote:
"Need help with i/o ports."

Don't just say "Need help".
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Jan 15, 2008 12:17 pm     Reply with quote

The code is not 'looping' because there is no loop command.

You have the following loop commands in C:
- while
- for
- do / while
An explanation of these commands is out of the scope of this forum, any C book or online course will handle that.

The tris setting commands are not needed as the compiler will handle this for you on every call to input or output data to a port.

The main part of your code could then look like:
Code:
int8 port_value;

while (TRUE)
{
  port_value = input_c();
  output_b( port_value );
}
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