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

Trying to read Port B and Write to Port D

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







Trying to read Port B and Write to Port D
PostPosted: Tue Nov 26, 2002 1:41 pm     Reply with quote

I am using PIC16F877 for my project and I am simply trying to read 8-bit data from port B. I have a dip switch connected to the pins corresponding to Port B, which provides the 8bit data.

Then I assinged these 8bits to port D. I have eight LED's connected to the pins corresponding to Port D.

void main(void)
{
int value=0;
int value_ascii=0;
// init_mem();
delay_ms(1000);
while(1)
{
value = input_b();//is it correct to read port B this way?
value_ascii = (value-48);
printf("\%d ", value_ascii);
output_d(value); //is it correct to write to port D?
}
}


First of all, I am getting "Funtion not defined error" referring to my input_b(); line
Is there some header file or anything like such that i should be including in order for the complier to recognize input_b();
Is my methodology correct? any suggestions will be helpful
Thank you
kamal
___________________________
This message was ported from CCS's old forum
Original Post ID: 9457
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: Trying to read Port B and Write to Port D
PostPosted: Tue Nov 26, 2002 2:09 pm     Reply with quote

:=I am using PIC16F877 for my project and I am simply trying to read 8-bit data from port B. I have a dip switch connected to the pins corresponding to Port B, which provides the 8bit data.

I assume the Dip switches are connected to ground (or to
ground through a 1K resistor). Do you have pull-up resistors
on the Port B pins ? If not, you should enable the Port B
pullups with the CCS function "port_b_pullups(TRUE)".


:=Then I assinged these 8bits to port D. I have eight LED's connected to the pins corresponding to Port D.

Do you have resistors in series with each LED ?
You can use 220 ohms.

:=
:=void main(void)
:={
:= int value=0;
:= int value_ascii=0;
:=// init_mem();
:= delay_ms(1000);
:= while(1)
:= {
:= value = input_b();//is it correct to read port B this way?
:= value_ascii = (value-48);
In the line above, you're removing ASCII bias by subtracting
48 from the value (Assuming that "value" is in ASCII format).
So why do you call the result variable "value_ascii" ?
I would call it "value_binary" instead.

:= printf("\%d ", value_ascii);

:= output_d(value); //is it correct to write to port D?
:= }
:=}
:=
:=
:=First of all, I am getting "Funtion not defined error" referring to my input_b(); line

What version of the compiler do you have ? It compiles OK
with PCM vs. 3.110.

:=Is there some header file or anything like such that i should be including in order for the complier to recognize input_b();
:=Is my methodology correct? any suggestions will be helpful
:=Thank you
:=kamal
___________________________
This message was ported from CCS's old forum
Original Post ID: 9458
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