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

Global Variable vrs Local function variable

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







Global Variable vrs Local function variable
PostPosted: Tue Jun 17, 2003 7:55 pm     Reply with quote

Hello Im trying to figure out why the compiler barfs on the code
below if I use byte BUFFER [2]; in the actual read_shiftregister
function as opposed to using it globally as shown. Im using ver 3.112 of the compiler

Any insight would be helpful.

Thanx Steve.

#include <16f84.h>
#use fast_io(A)

#define ENABLE PIN_A1
#define CLOCK PIN_A2
#define DATA_IN PIN_A3
#define Loop while (1)

byte BUFFER [2]; // Global Variable

void read_shiftregister(){

int16 count;

output_high(CLOCK);
output_low(ENABLE);
output_high(ENABLE);

for(count=1; count<=16; ++count) {

shift_left(BUFFER, 2 ,input (DATA_IN));

output_low(CLOCK);

output_high(CLOCK);
}

output_low(ENABLE);

}

void main(){
set_tris_a(0b00100);

loop;

read_shiftregister();

}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515341
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: Global Variable vrs Local function variable
PostPosted: Wed Jun 18, 2003 8:04 am     Reply with quote

Try something like this.

This code is for the ADC2402

/*-------------------------------------------------------------------
Read ADC
-------------------------------------------------------------------*/
OUTPUT_LOW(PIN_A3); //ADC CS low to verify reading is ready
if (!input(PIN_A2)) //ADC SDO low = sample ready
{
ADCreading = 0;
OUTPUT_HIGH(PIN_A1);
OUTPUT_LOW(PIN_A1);
Channel = input(PIN_A2); // read input channel
OUTPUT_HIGH(PIN_A1);
OUTPUT_LOW(PIN_A1);
OUTPUT_HIGH(PIN_A1);
OUTPUT_LOW(PIN_A1);
for (x= 1; x<= 24; x++)
{
OUTPUT_HIGH(PIN_A1);
OUTPUT_LOW(PIN_A1);
shift_left(&ADCreading,4,input(PIN_A2));
}
OUTPUT_HIGH(PIN_A3);
if (Channel) ADCreading1= ADCreading;
else ADCreading0 = ADCreading;
}
OUTPUT_HIGH(PIN_A3); //ADC CS high to begin new reading



___________________________
This message was ported from CCS's old forum
Original Post ID: 144515353
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