Einly
Joined: 10 Sep 2003 Posts: 60
|
Ring buffer |
Posted: Wed Oct 22, 2003 7:29 pm |
|
|
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 |
|