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

bcd output to rs232

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



Joined: 04 Mar 2009
Posts: 19

View user's profile Send private message

bcd output to rs232
PostPosted: Sat Mar 07, 2009 4:47 am     Reply with quote

hi there,
im a bit stuck on how to get four digital inputs from a bcd counter on to the rs232, and display them in decimal.

i was wondering to to combine all the four input to get one decimal output.

im using a pic16f788a, the inputs are connected to B0, B1, B2, and B3. the ouput to the RS232 is E0, E1.

this is the code i have been tring but, it just diplay the same numbers on the hyperterminal
Code:

#include <16F877A.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=2400,xmit=PIN_E0,rcv=PIN_E1)
int bcd1;
int bcd2;
int bcd3;
int bcd4;
int count;

void main()
{

bcd1= input(PIN_B0);
bcd2= input(PIN_B1);
bcd3= input(PIN_B2);
bcd4= input(PIN_B3);

count= bcd1 + bcd2 + bcd3 + bcd4;

while(1)
  {

printf("counter = %d",count);

   delay_ms(100);
  }

}

i no im missing something out i cant figure what, if someone can help i would be greatful


thanks in advance

piire!
Ttelmah
Guest







PostPosted: Sat Mar 07, 2009 5:17 am     Reply with quote

If these are four 'bits' representing a BCD number, then the they can only represent a number from 0-9. Is this all the counter does?. If not, then you need to rethink how the interface actually works.
If this is all it does, then you need:

count= bcd1 + (bcd2*2) + (bcd3*4) + (bcd4*8);

However much simpler, to just do:

count=input_b() & 0xF;

Best Wishes
Sydney



Joined: 13 Feb 2009
Posts: 71

View user's profile Send private message

PostPosted: Sat Mar 07, 2009 5:22 am     Reply with quote

Code:
count= bcd1 + bcd2*2 + bcd3*4 + bcd4*8;


Would be the easiest way to fix your problem. There are more efficient ways to do it.

Code:
count=input_b() & 0x0f //mask of upper bits


Beware the 2nd method will make the upper bit of portb inputs, unless you are using #use fast_io
Sydney



Joined: 13 Feb 2009
Posts: 71

View user's profile Send private message

PostPosted: Sat Mar 07, 2009 5:24 am     Reply with quote

Wink
piire



Joined: 04 Mar 2009
Posts: 19

View user's profile Send private message

PostPosted: Sat Mar 07, 2009 6:31 am     Reply with quote

Thanks for the help i will give it a try!

What i have is: a circuit which has a switch a bcd and a few gates and two seven segment displays. When i press the switch the number on the display increases. So what i have done is taken the output of the bcd and put them into the input port b, so that i can also get the reading on the computer as well. The maximum number is 99. Is it better to connect the 7 segment displays to the pic and have a switch on another digital port and just write a program that display the number on the displays and computer?

If anyone has an example i would be grateful.

thanks
piire
Sydney



Joined: 13 Feb 2009
Posts: 71

View user's profile Send private message

PostPosted: Sat Mar 07, 2009 10:21 am     Reply with quote

Well given it can be done with just the main components, 7 segments, switch, and pic, and very little else(a couple of transistors for the digit sinks), the hardware will be much simpler, but obviously the software will be a little more involved, but still pretty simple, presumably you will multiplex the displays so will need 9/10 I/O depending if you need the DP and 1 I/O for the switch.
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