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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
09/27/09 02:50
Read: times


 
#169187 - Re: pseudo code
Responding to: ???'s previous message
Hi Erik. I know it's too much to ask you again to write pieces of codes from the charts you have suggested. But it's great help if you can do for me.

I have tried some of these, but could not get it works. May be I did make it over complicated:

RECEIVE:
char Com_getchar (void)
{	
 if (Com_rbuflen () == 0)		//If the receive buffer is empty, return an error value.
   return (-1);
 else if (Com_rbuflen () >= RBUF_SIZE)	//If the receive buffer is overflow, return an error value.
 {
	r_in = 0;	r_out = 0;				//Reset and clear the receive buffer
	return (-1);
 }
 //Return the byte pointed by r_out in rbuf, then update the pointer r_out  
 return (rbuf [(r_out++) & (RBUF_SIZE - 1)]);	
}
 


Thanks,
Ralf

TRANSMIT:

//Note: There should be a short delay after a packet transmission to avoid the transmit buffer overflow
// The short delay should be inserted after the buffer is close to be full 
char Com_putchar(unsigned char c)	//For use with the serial interrupt enabled, i.e., ES = 1; 
{
	//If the buffer is full, return an error value.
	if (Com_tbuflen () >= TBUF_SIZE)
	  return (-1);
	
	//Add the data to the transmit buffer. If the transmit interrupt is disabled, then enable it.
	tbuf [t_in & (TBUF_SIZE - 1)] = c;
	t_in++;

	return (0);
}

unsigned char Com_tbuflen (void)
{
	if (t_in - t_out >= 0)
    	return (t_in - t_out);
	else 
		return (t_in - t_out + 256);
}

 



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