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 support@ccsinfo.com

#byte & C.

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



Joined: 08 Sep 2003
Posts: 21

View user's profile Send private message

#byte & C.
PostPosted: Tue Jun 24, 2003 5:58 am     Reply with quote

With the preprocessor directive #byte is possible R/W directly a PIC register.
How is possible to use this directive ?
As example there is :

#BYTE timer0 = 0x01
timer0 = 128;

Whot is the number 0x01 ?
Do you have some real example ?

Thank you....
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515513
R.J.Hamlett
Guest







Re: #byte & C.
PostPosted: Tue Jun 24, 2003 7:50 am     Reply with quote

:=With the preprocessor directive #byte is possible R/W directly a PIC register.
:=How is possible to use this directive ?
:=As example there is :
:=
:=#BYTE timer0 = 0x01
:=timer0 = 128;
:=
:=Whot is the number 0x01 ?
:=Do you have some real example ?
:=
:=Thank you....

With what you have written, '128', would be put into the register at address 1.
The actual meaning of this, would depend on the chip used, and for this, read the chip's data sheet.
A classic example in the past, would be to allow the AD trigger operation to be seperated from the read operation (this is now supported in the current compiler). Before this support was added, typical routines would be (addresses for a 16F87x)
#bit ADON=0x1F.2
#bit ADEN=0x1F.0
#BYTE ADCON0 = 0x1F
#BYTE ADCON1 = 0x9F
#BYTE ADRESL = 0x9E
#BYTE ADRESH = 0x1E

Then to read the AD:
value=make16(adresh,adresl);

While to trigger the AD:
ADEN=1;
ADON=1;

And to wait if it has not finished:

while (ADON) ;

Another 'classic', would be for EEPROM I/O, on the 18Fxx2, which now works, but in the past, required 'homebrew' routines for relaibility:
#byte EEADR = 0xFA9
#byte EECON1 = 0xFA6
#byte EECON2 = 0xFA7
#byte EEDATA = 0xFA8
#byte INTREG = 0xFA1
#bit GIE = 0xFF2.7
#byte INTCON = 0xFF2

int rd_eeprom(int address)
{
int temp;
int intflag;
//Send required address to chip
EEADR=address;
BIT_CLEAR(EECON1,7);
BIT_CLEAR(EECON1,6);
//save interrupt status
intflag=GIE;
//ensure interrupts are disabled
INTOFF;
//trigger read
BIT_SET(EECON1,0);
//get data
temp=EEDATA;
//re-enable interrupts if required
if (intflag) INTON;
return(temp);
}

void wrt_eeprom(int address,int value)
{
int intflag;
EEADR=address;
EEDATA=value;
BIT_CLEAR(EECON1,7);
BIT_CLEAR(EECON1,6);
BIT_SET(EECON1,2);
intflag=GIE;
INTOFF;
//send 'safety' marker to start write operation
EECON2=0x55;
EECON2=0xAA;
BIT_SET(EECON1,1);
//re-enable interrupts if required
if (intflag) INTON;
//Wait for operation to complete
while (!BIT_TEST(INTREG,4));
BIT_CLEAR(INTREG,4);
}

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