| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| Frozen01 
 
 
 Joined: 23 Apr 2009
 Posts: 32
 
 
 
			    
 
 | 
			
				| getting individual bits out of a variable |  
				|  Posted: Wed May 27, 2020 10:09 am |   |  
				| 
 |  
				| Here is what I need to do.... 
 I read the serial stream (UART1)...  I then want to pass to a function that I "bitbang" out to an oddball serial like device that does not fit the standard RS232 format.
 
 Reading the port is not a problem, but I can't place my finger on how to extract out the bit pattern that I need to send.  Input data is standard RS232 framed data.
 
 Last edited by Frozen01 on Wed May 27, 2020 10:48 am; edited 1 time in total
 |  | 
	
		|  | 
	
		| temtronic 
 
 
 Joined: 01 Jul 2010
 Posts: 9588
 Location: Greensville,Ontario
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Wed May 27, 2020 10:28 am |   |  
				| 
 |  
				| Quick comment.. CCS has a 'bit test' function you can use ! Check the manual for the correct syntax, but a simple 'loop' from 0 to 7, or 7 to 0, will 'extract' the bit from the byte, then you can do 'whatever' to send to the other device.
 0 to 7 will get lsb to msb, 7 to 0 gets high bit first...
 
 There may be an example in the code library, it's been used to send '1' or '0' to an LCD to 'show' the binary equal to a byte.
 
 jay
 |  | 
	
		|  | 
	
		| Frozen01 
 
 
 Joined: 23 Apr 2009
 Posts: 32
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Wed May 27, 2020 11:40 am |   |  
				| 
 |  
				| I got something working, ended up just using a for loop... |  | 
	
		|  | 
	
		| bkamen 
 
 
 Joined: 07 Jan 2004
 Posts: 1617
 Location: Central Illinois, USA
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Sun May 31, 2020 10:37 am |   |  
				| 
 |  
				| Right... 
 With a loop, you can either use the bit_tes()  function and/or roll the bits using >> or << operators.
 _________________
 Dazed and confused? I don't think so. Just "plain lost" will do.  :D
 |  | 
	
		|  | 
	
		|  |