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

Read Hex as bit stream and send through a single pin.

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



Joined: 05 Nov 2007
Posts: 28
Location: Denmark

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

Read Hex as bit stream and send through a single pin.
PostPosted: Mon Jun 09, 2008 10:57 am     Reply with quote

Ok. Here's the problem that I just can't seem to solve:

I've got a HEX, example 0x6F.

0x6F = 01101111 in binary.

I want to read the hex and toggle a pin high and low according to the binary pattern.

The output on the pin, as for 0x6F should be like:

output_low(pin_b3);
delay_ms(1);
output_high(pin_b3);
delay_ms(1);
output_high(pin_b3);
delay_ms(1);
output_low(pin_b3);
delay_ms(1);
output_high(pin_b3);
delay_ms(1);
output_high(pin_b3);
delay_ms(1);
output_high(pin_b3);
delay_ms(1);
output_high(pin_b3);


-following the bit-pattern In other words, I'm imagining the code to look like this:

int8 Hexdata;
Hexdata = 0x6F;

while ('Reading binary stream from Hexdata'){

if('current binary number is 1'){
output_high(pin_b3);
}else{
output_low(pin_b3);
}

delay_ms(1);

}



How the heck do I do that? I'm not a total novice, but I feel so dumb, having tried to solve this problem for days.

I'll mail you a postcard, if you're the first to come up with a solution that I can understand! Very Happy
ckielstra



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

View user's profile Send private message

PostPosted: Mon Jun 09, 2008 11:51 am     Reply with quote

You say you are reading the data from a serial bit stream and you want to send it through a single pin. Sending data through a single pin is often referred to as serial communication. Now what I don't understand is that you are capable of reading the serial data but you don't know how to transmit serial data?

Your pseudo code is crude but should do the job. So what is the exact part you don't understand?

Sending data out of a serial pin is a very common job, most PIC processors even have specialized hardware for this: SPI, I2C and UART.
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Mon Jun 09, 2008 12:55 pm     Reply with quote

Code:
int8 Hexdata = 0x6f;
int8 count;

for (count = 0; count < 8; count++)
{
   if (Hexdata & 0x01)
      output_high(pin_b3)
   else
      output_low(pin_b3);
   Hexdata >>= 1;
   delay_ms(1)
}

_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
crystallattice
Guest







PostPosted: Mon Jun 09, 2008 1:20 pm     Reply with quote

or you could use the shift functions like the shift_left for example
davidbue



Joined: 05 Nov 2007
Posts: 28
Location: Denmark

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

Solved the problem.
PostPosted: Mon Jun 09, 2008 2:05 pm     Reply with quote

Hi everybody!

I solved the problem myself using the following:
Code:

int8 c;
c = 0x6F;

for (currentbit = 0; currentbit < 8; currentbit++){
               
               
     if(  bit_test(c,currentbit)  ){  //If this bit is 1
           output_high(pin_b5);
       }else{
           output_low(pin_b5);
       }
 delay_ms(1);
               
}


The postcard goes to asmallri as he was the first with a similar solution. Please send me a PM with the address to which you want your postcard with a scenic view of the capital of Denmark. Very Happy

/David
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