Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
09/29/09 04:19
Read: times


 
#169240 - Is that OK to use printf to send data to PC like this?
Responding to: ???'s previous message
Thank you all for the advices. I'll try and hope having success with that.

On the other hand, I have done some doggy code over night just to see it can get me out of trouble. Please let me know should you see any problem with it.

void serial_init(void)
{						//Configure UART
  T3CON = 0x83;         			//configure timer 3...ADuC848
  T3FD  = 0x12;          			//...for 9600 baud
  SCON  = 0x52;
}

void serial_read(void)
{									//Configure UART
	unsigned char c,c1,c2;		
	unsigned int i;		

//Protocol: if received "S1+cr", return MCU's status. If status is 2 then PC will ask for result
//          if received "Vn+cr" (n=1 to 9), return "n" channel ADC result

	while (RI)
	{
		c = SBUF;
		if(c==0x053 || c==0x056) //If S or V entered, store as 1st character
		{
			c1=c;
			c=0;
		}
		else
			if(c!=0x0d)   //if not the 3rd character as "cr"
				c2=c; //then  store as 2nd character

  	 	RI = 0;
		if(c1==0x053 && c2==0x031 && c==0x0d) //If received "S1+cr"
		{
			printf("%ur", MCU_Status);		
			i=0;
		}
		else
		if(c1==0x056 && c==0x0d) //If received "V(1-9)+cr"	
		{
			if(c2==0x031)                      //if received V1+cr
				printf("%ur", Head1_ADC); //send ADC result of channel 1
			else
			if(c2==0x032)
				printf("%ur", Head2_ADC);				
			else
			if(c2==0x033)
				printf("%ur", Head3_ADC);				
			else
			if(c2==0x034)
				printf("%ur", Head4_ADC);				
			else
			if(c2==0x035)
				printf("%ur", Head5_ADC);				
			else
			if(c2==0x036)
				printf("%ur", Head6_ADC);				
			else
			if(c2==0x037)
				printf("%ur", Head7_ADC);				
			else
			if(c2==0x038)
				printf("%ur", Head8_ADC);				
			else
			if(c2==0x039)
			{
				printf("%ur", Head9_ADC);	
				CONDVOL_Time_Flag=0;	//reset timer flag				
			}
		}
	}
}

 

Thanks,
Ralf


List of 38 messages in thread
TopicAuthorDate
RS232: Sending data to PC from 8051 MCU - Please help!            01/01/70 00:00      
   What problems have you encountered?            01/01/70 00:00      
      Re: What problems have you encountered?            01/01/70 00:00      
         Q: How can I eat a whole whale?            01/01/70 00:00      
         There are examples and serial I/O tutorial information            01/01/70 00:00      
            Re: There are examples and serial I/O tutorial information            01/01/70 00:00      
               If you're using Keil            01/01/70 00:00      
               I have only seen some in assembly            01/01/70 00:00      
                  Re: RS232 discussion on Keil & 8052 website            01/01/70 00:00      
                     Hello, World!            01/01/70 00:00      
                        Re: Hello, World!            01/01/70 00:00      
                           why on earth?            01/01/70 00:00      
                           As Erik says            01/01/70 00:00      
                              Re: As Erik says            01/01/70 00:00      
                                 Just extend single-char routine            01/01/70 00:00      
                                 pseudo code            01/01/70 00:00      
                                    bufgfers            01/01/70 00:00      
                                    Re: circular bufgfers            01/01/70 00:00      
                                    Re: pseudo code            01/01/70 00:00      
                                       what is this            01/01/70 00:00      
                                          Used size            01/01/70 00:00      
                                          Can you give me any simple code, please?            01/01/70 00:00      
                                             first            01/01/70 00:00      
                                                RE: first            01/01/70 00:00      
                                                   why not directly to where you anyhow need to be eventually            01/01/70 00:00      
                                 INTSIO?            01/01/70 00:00      
   A note on using printf            01/01/70 00:00      
      How to set BAUD rate to 19200, timer 3 for ADuCxxx?            01/01/70 00:00      
      Is that OK to use printf to send data to PC like this?            01/01/70 00:00      
         Are you listening to anything that's been said here?            01/01/70 00:00      
            Re: Are you listening to anything that's been said here?            01/01/70 00:00      
               ADC read function just stop working            01/01/70 00:00      
               far better efficient and organise            01/01/70 00:00      
                  Thanks            01/01/70 00:00      
                     The trouble I have is I am running out of time            01/01/70 00:00      
                        This is what happens when you do somebody's work for them            01/01/70 00:00      
                           Re: This is what happens when you do somebody's work for the            01/01/70 00:00      
                              Then use the resources available to you!            01/01/70 00:00      

Back to Subject List