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 CCS Technical Support

Ring buffer

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



Joined: 10 Sep 2003
Posts: 60

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger ICQ Number

Ring buffer
PostPosted: Wed Oct 22, 2003 7:29 pm     Reply with quote

Dear all,

I wish to read 64 long int (16 bits) from ADS7807, in the same time transfer the previous packet (64 long int) to the computer using serial communication. I am using PIC16f876 between the ADS7807 & the computer.

Below is a program that is run successfully to convert a single ADC reading.

#include <16f876.h>
#fuses hs,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)

#byte PORTA=5
#byte PORTB=6
#byte PORTC=7

#define RC PIN_B7
#define CS PIN_B6
#define SCLK PIN_B5
#define SDATA PIN_B1
#define BUSY PIN_B0

void init_adc();
void convert();
void read();
void display_results();

int i;

union split
{
long int whole;
byte b[2];
};

union split value;

void main()
{

set_tris_b(0x07);
set_tris_c(0);

init_adc();

do
{
}while(input(PIN_B2)==0);

output_high(PIN_B3);
delay_ms(2000);
output_low(PIN_B3);
delay_ms(2000);

convert();

read();
output_high(SCLK);
delay_us(2);
output_low(SCLK);
delay_us(2);
output_high(SCLK);
delay_us(2);
output_low(SCLK);
delay_us(1);
output_high(CS);
delay_us(1);
output_high(SCLK);
delay_us(2);
output_low(SCLK);

display_results();
}

void init_adc()
{
output_high(CS);
output_high(RC);
output_low(SCLK);
}

void convert()
{
output_high(SCLK);
delay_us(2);
output_low(SCLK);
output_low(RC);
delay_us(1);
output_low(CS);
delay_us(1);
output_high(CS);
delay_us(1);
output_high(RC);

do
{
}while(input(BUSY)==0);
}

void read()
{
output_low(CS);
delay_us(1);

for(i=0;i<16;i++)
{
output_high(SCLK);
delay_us(2);
output_low(SCLK);
shift_left(&value.whole,2,input(SDATA));
delay_us(2);
}
}

void display_results()
{
output_high(PIN_C7);
delay_ms(1000);
output_low(PIN_C7);
delay_ms(1000);
portc=value.b[1];
delay_ms(2000);
portc=value.b[0];
delay_ms(2000);
}

May I know how to achieve this:

I wish to use two packet buffers. I take readings and transfer them directly to the buffer that is not being transmitted. As soon as a buffer is full I flag it for transmition and begin filling the other buffer with data. I end up transmitting packets as soon as I have enough data to make a complete packet.

From the previous post, I was suggested with these line:

If(USART_Transmit_Buffer_Empty && Buffer1Sending)
{ PutC(Buffer1[y]);
y++;
if(y==End_of_Packet) Buffer1Sending=0;
}

May I know what does USART_Transmit_Buffer_Empty & Buffer1Sending mean? Is it hardware USART?

Thanks a lot

Einly
_________________
Einly
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 22, 2003 7:49 pm     Reply with quote

If you define the variables in the following way, it should work:


int1 Buffer1Sending = 0;

#bit USART_Transmit_Buffer_Empty = 0x0C.4
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