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

uVision2

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



Joined: 15 Mar 2015
Posts: 3

View user's profile Send private message

uVision2
PostPosted: Sun Mar 15, 2015 11:53 am     Reply with quote

Hi there.

Does any good soul can translate this code to me?

Code:

#define BK_DATA_HIGH()   P02=1;
#define BK_DATA_LOW()   P02=0;
#define BK_DATA_READ()  P02
#define SDADIROUT()     P0DIR &= ~(1<<2);P0PU |= (1<<2)
#define SDADIRIN()      P0DIR |= (1<<2);P0PU |= (1<<2)
#define SCLDIROUT()     P0DIR &= ~(1<<3);P0PU |= (1<<3)
#define BK_CLK_HIGH()   P03=1;
#define BK_CLK_LOW()    P03=0;


This comes from uVision2 compiler, and I already download the demo compiler and all, but no clue about this could mean. I trying to interface one BK-1080 from PIC16F688, but really got trouble on the I2C.

So I downloaded this example from the BK-1080 manufactor, explaing the I2c comunication, but have no Idea of how to translate this code to CCS, the rest of code I can gess.

Regards.
jeremiah



Joined: 20 Jul 2010
Posts: 1321

View user's profile Send private message

PostPosted: Sun Mar 15, 2015 1:49 pm     Reply with quote

if you are gonna work with CCS, you are better off not trying to port the uVision code directly. Think of the I2C functionality in terms of actions: initializing, reading the port, writing the port, start/stop for communication.

Then look at the compiler manual (or help if in the IDE) for:
#USE I2C
i2c_start
i2c_stop
i2c_write
i2c_read
Manoel_Filho



Joined: 15 Mar 2015
Posts: 3

View user's profile Send private message

PostPosted: Sun Mar 15, 2015 2:10 pm     Reply with quote

Ok Jeremiah. Thank you! I know the I2C procedures, no issue about this. The main problem is that this device BK-1080, is a little bit weird. The device ID have 16 bits with ACK. The initial address bit is also 16 bits with ACK afte the 16th bit, but for the rest, you can split the registers in 2x8bits with an ACK between them. Thats why I was trying to understand what the manufactor did on this software. So if you or any one else can help me I appreciate that.

Regards
Ttelmah



Joined: 11 Mar 2010
Posts: 19326

View user's profile Send private message

PostPosted: Sun Mar 15, 2015 2:31 pm     Reply with quote

The code means nothing, without knowing the chip it is used on, and how the hardware is wired.
However some parts can be worked out:

#define BK_DATA_HIGH() P02=1;

Sets something called P02 to 1.
Possibly Port 0, bit 2?.

The next line is the same to set the same thing low.

Then:

#define SDADIROUT() P0DIR &= ~(1<<2);

Turns off bit 2, in the 'P0' direction register (equivalent to TRIS?)

Takes 1
Shifts it twice to give 00000100
Inverts this to give 11111011
&'s this with the direction register (so if this is TRIS, sets bit 2 to an output)

Then:

P0PU |= (1<<2)

Possible something like a port 0 'pull up' register?. Again would need to know the hardware. This sets bit 2 in this register.

Without knowing the chip involved though, these are all going to be guesses.

The CCS _software_ I2C implementation can do an ACK after bit 16. The PIC hardware can't.

However you are misreading the data sheet. The chip requires an ACK after every byte sent (standard I2C). It takes an 8bit device address (0x80), followed by a seven bit register address and the R/W bit. This is fractionally different from standard, where the device address is normally 7bits, with the R/W bit then added, but the standard I2C hardware will handle this OK.
Several of the registers are 16bit, but each is transferred a byte at a time.
Manoel_Filho



Joined: 15 Mar 2015
Posts: 3

View user's profile Send private message

PostPosted: Sun Mar 15, 2015 6:38 pm     Reply with quote

You are completely right.

I can perfect communicate with the chip, no problem.

Thank you,

regards.
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