<?xml version="1.0" encoding="utf-8" ?>
				<!-- generator="e107" -->
				<!-- content type="Forum / topic" -->
				<rdf:RDF xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
				<channel rdf:about="http://www.8051projects.net/">
				<title>8051 Microcontroller Projects AVR PIC Projects Tutorials Ebooks Libraries codes : Forum / topic</title>
				<link>http://www.8051projects.net/</link>
				<description>Learn to make simple microcontroller projects, pic, 8051, avr and arm projects. download 8051 projects, tutorials, libraries, sample codes. join the microcontroller discussion forum and ask doubts regarding electronics. the best source for 8051 over internet.</description>
				<dc:language>en-gb</dc:language>
				<dc:date>2009-01-07T22:09:49-08:00</dc:date>
				<dc:creator>contact@nospam.com</dc:creator>
				<admin:generatorAgent rdf:resource="http://e107.org" />
				<admin:errorReportsTo rdf:resource="mailto:contact@nospam.com" />
				<sy:updatePeriod>hourly</sy:updatePeriod>
				<sy:updateFrequency>1</sy:updateFrequency>
				<sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase>
				<items>
				<rdf:Seq>
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t6697.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t6697.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t6697.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t6697.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t6697.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t6697.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t6697.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t6697.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t6697.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t6697.html" />
				</rdf:Seq>
				</items>
				</channel>
						<item rdf:about="http://www.8051projects.net/forum-t6697.html">
						<title>how to join the low byte nd high byte</title>
						<link>http://www.8051projects.net/forum-t6697.html</link>
						<dc:date>2009-01-07T22:09:49-08:00</dc:date>
						<dc:creator></dc:creator>
						<dc:subject></dc:subject>
						<description>im using vb program in reading the data send by my pic16f877 and im getting results alternately.. is it because of the low byt and high byte that is being write in my usart? please help???CODE:unsigned int adc_val;<br />unsigned char low_byte,hi_byte;<br />void main&#40;&#41;<br />&#123;<br />USART_Init&#40;9600&#41;;<br />ADCON0 = 0;<br />ADCON0.ADON = 1;<br />TRISA = 0xFF;<br />TRISB = 0; &nbsp;<br />PORTB = 0;<br /><br />while &#40;1&#41;<br />&#123;<br />&nbsp; ADCON0.GO = 1<br />adc_val = ADC_Read&#40;0&#41;;<br />low_byte = adc_val;<br />hi_byte = adc_val >> 8;<br />USART_Write&#40;low_byte&#41;;<br />USART_Write&#40;hi_byte&#41;;<br />low_byte =USART_Read&#40;&#41;;<br />high_byte =USART_Read&#40;&#41;<br />if&#40;adc_val==511&#41; //if ADC value read in is 511 <br />&#123;PORTB = 0xFF;&#125; //display some LED's on PORTB<br />....<br />....<br />.<br />&#125;<br />&#125;for my vb prog:CODE:Private Sub CmdExit_Click&#40;&#41;<br />&nbsp; &nbsp; If MSComm1.PortOpen = True Then<br />&nbsp; &nbsp; MSComm1.PortOpen = False<br />&nbsp; &nbsp; End If<br />&nbsp; &nbsp; &nbsp; &nbsp; End<br />End Sub<br />Private Sub Form_Load&#40;&#41;<br />&nbsp; &nbsp; MSComm1.InputLen = 0<br />&nbsp; &nbsp; MSComm1.CommPort = 2<br />&nbsp; &nbsp; MSComm1.Settings = "9600,N,8,1"<br />End Sub<br />Private Sub Timer1_Timer&#40;&#41;<br />&nbsp; &nbsp; Dim BytesToRead As Integer<br />&nbsp; &nbsp; Dim sData As Variant<br />&nbsp; &nbsp; MSComm1.PortOpen = True<br />&nbsp; &nbsp; BytesToRead = 1<br />&nbsp; &nbsp; Do<br />&nbsp; &nbsp; &nbsp; &nbsp; DoEvents<br />&nbsp; &nbsp; &nbsp; &nbsp; Loop Until MSComm1.InBufferCount = BytesToRead<br />&nbsp; &nbsp; &nbsp; &nbsp; sData= MSComm1.Input<br />&nbsp; &nbsp; &nbsp; &nbsp; Text1.Text = &#40;&#40;&#40;Asc&#40;sData&#41; * 0.00489&#41; &nbsp;&amp; " Volts DC"<br />&nbsp; &nbsp; &nbsp; &nbsp; MSComm1.PortOpen = False<br />End Subhow am i going to read the low and high byte since im only using sData as input</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t6697.html">
						<title>Re: how to join the low byte nd high byte</title>
						<link>http://www.8051projects.net/forum-t6697.html</link>
						<dc:date>2009-01-07T22:09:49-08:00</dc:date>
						<dc:creator>Ajay</dc:creator>
						<dc:subject></dc:subject>
						<description>in C you can combine something like this..CODE:<br />int combined;<br />char adcHI, adcLOW;<br /><br />combined = adcHI;<br />combined = &#40;combined &lt;&lt; 8&#41; | adcLOW;<br />//now combined is 16-bit value.<br />&nbsp;</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t6697.html">
						<title>Re: how to join the low byte nd high byte</title>
						<link>http://www.8051projects.net/forum-t6697.html</link>
						<dc:date>2009-01-07T22:09:49-08:00</dc:date>
						<dc:creator>norms</dc:creator>
						<dc:subject></dc:subject>
						<description>thanks ajay... does this dont mess up with the readings ill be getting in my vb program? ill be using this code as thisunsigned int adc_val;int combined char adcHI, adcLOW;;void main(){USART_Init(9600);ADCON0 = 0;ADCON0.ADON = 1;TRISA = 0xFF;TRISB = 0;  PORTB = 0;while (1){  ADCON0.GO = 1adc_val = ADC_Read(0);adcLOW = adc_val;adcHigh= adc_val >> 8;combined = adcHI;combined = (combined &lt;&lt;8) | adcLOWUSART_Write(combined)combined = USART_Read();do i need to delete the low_byte and high_byte thing?</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t6697.html">
						<title>Re: how to join the low byte nd high byte</title>
						<link>http://www.8051projects.net/forum-t6697.html</link>
						<dc:date>2009-01-07T22:09:49-08:00</dc:date>
						<dc:creator>sashijoseph</dc:creator>
						<dc:subject></dc:subject>
						<description>Hi.....First of all you need to understand what you are doing.Let me explain.....You are reading the adc value and storing it in adc_val which is an int type ie 2-bytes.When you send data to the PC through the PIC's USART,you can send only 1 byte at a time.Therefore you cannot send adc_val through the USART at once(since it's 2-bytes).So what you do is split the adc_val into two separate bytes ie. hi_byte and low_byte.Now send one byte first(say lo_byte) through USART,then the next(hi_byte).Now in your VB program you receive these 2 bytes and then recombine them into the original integer  adc_val,using the logic depicted above by Ajay(you have to do this in your VB program and not PIC).. low_byte =USART_Read();high_byte =USART_Read() In your PIC program what is this for? Can you explain?</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t6697.html">
						<title>Re: how to join the low byte nd high byte</title>
						<link>http://www.8051projects.net/forum-t6697.html</link>
						<dc:date>2009-01-07T22:09:49-08:00</dc:date>
						<dc:creator>Ajay</dc:creator>
						<dc:subject></dc:subject>
						<description>You cannot send variable combine to UART directly, coz its a 16-bit variable and UART is capable of sending 8-bit.in your first post you are doing right.. i means sending first byte and then second byte. Now you need to do the combining thing in VB.. you can do it something like thisCODE:Dim Value As Integer = &#40;CInt&#40;FirstByte&#41; &lt;&lt; 8&#41; Or SecondByte<br />&nbsp;</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t6697.html">
						<title>Re: how to join the low byte nd high byte</title>
						<link>http://www.8051projects.net/forum-t6697.html</link>
						<dc:date>2009-01-07T22:09:49-08:00</dc:date>
						<dc:creator>norms</dc:creator>
						<dc:subject></dc:subject>
						<description>ah ok.thanks...  can u give me some info on how i am going to combine this? i've tried but not that succesfull.</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t6697.html">
						<title>Re: how to join the low byte nd high byte</title>
						<link>http://www.8051projects.net/forum-t6697.html</link>
						<dc:date>2009-01-07T22:09:49-08:00</dc:date>
						<dc:creator>norms</dc:creator>
						<dc:subject></dc:subject>
						<description>where i am going to insert the code uve given? this is my code:CODE:Private Sub CmdExit_Click&#40;&#41;<br />&nbsp; &nbsp; If MSComm1.PortOpen = True Then<br />&nbsp; &nbsp; MSComm1.PortOpen = False<br />&nbsp; &nbsp; End If<br />&nbsp; &nbsp; &nbsp; &nbsp; End<br />End Sub<br />Private Sub Form_Load&#40;&#41;<br />&nbsp; &nbsp; MSComm1.InputLen = 0<br />&nbsp; &nbsp; MSComm1.CommPort = 2<br />&nbsp; &nbsp; MSComm1.Settings = "9600,N,8,1"<br />End Sub<br />Private Sub Timer1_Timer&#40;&#41;<br />&nbsp; &nbsp; Dim BytesToRead As Integer<br />&nbsp; &nbsp; Dim sData as Variant<br />&nbsp; &nbsp; MSComm1.PortOpen = True<br />&nbsp; &nbsp; BytesToRead = 1<br />&nbsp; &nbsp; Do<br />&nbsp; &nbsp; &nbsp; &nbsp; DoEvents<br />&nbsp; &nbsp; &nbsp; &nbsp; Loop Until MSComm1.InBufferCount = BytesToRead<br />&nbsp; &nbsp; &nbsp; &nbsp; sData= MSComm1.Input<br />&nbsp; &nbsp; &nbsp; &nbsp; Text1.Text = &#40;&#40;&#40;Asc&#40;sData&#41; * 0.00489&#41; &nbsp;&amp; " Volts DC"<br />&nbsp; &nbsp; &nbsp; &nbsp; MSComm1.PortOpen = False<br />End Sub<br />&nbsp;</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t6697.html">
						<title>Re: how to join the low byte nd high byte</title>
						<link>http://www.8051projects.net/forum-t6697.html</link>
						<dc:date>2009-01-07T22:09:49-08:00</dc:date>
						<dc:creator>Ajay</dc:creator>
						<dc:subject></dc:subject>
						<description>i donno much about VB coding and stuff.. only thing i can tell you is.. you need to read two bytes as sent by controller.Lets say you are sending high byte first and then low byte..so you need to read them separately one by one.. and store them in two variables and then combine both of them as mentioned above.e.g.CODE:<br />FirstByte= MSComm1.Input<br />SecondByte = MSComm1.Input<br /><br />Combined = &#40;CInt&#40;FirstByte&#41; &lt;&lt; 8&#41; Or SecondByte<br />&nbsp;</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t6697.html">
						<title>Re: how to join the low byte nd high byte</title>
						<link>http://www.8051projects.net/forum-t6697.html</link>
						<dc:date>2009-01-07T22:09:49-08:00</dc:date>
						<dc:creator>norms</dc:creator>
						<dc:subject></dc:subject>
						<description>Ajay, thank you very much for the help, i've tried using ur code but when im in the Combine = (CInt(FirstByte)&lt;&lt;8) Or Secondbyte the "&lt;&lt;" gives an error, i can only use one &lt;, isn't it a c code "&lt;&lt;"? ...  and when i tried checking the value send by the microcontroller the reading was at 255 and changes to 239, is there something wrong with my code?</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t6697.html">
						<title>Re: how to join the low byte nd high byte</title>
						<link>http://www.8051projects.net/forum-t6697.html</link>
						<dc:date>2009-01-07T22:09:49-08:00</dc:date>
						<dc:creator>sashijoseph</dc:creator>
						<dc:subject></dc:subject>
						<description>Try this.....Combined = CInt(Firstbyte * (2^8)) OR Secondbyte</description>
						</item>
				</rdf:RDF>