I want to write/read a integer/ long integer on a I2C device, but all the routines I have supports only character(single byte) writing/ reading from I2C device. Can anyone help me?
use a union union LCD_noname_104 { unsigned char y8[2]; unsigned int y16; } LCD_select_font_y; for sending bytes: I2C_send = LCD_select_font_y.y8[0]; I2C_send = LCD_select_font_y.y8[1]; for using the int: LCD_select_font_y.y16 = 1234; breaking up an int costs more bytes code geert starre
"use a union" This non-portable but usually fast. See: http://www.keil.com/forum/docs/thread3210.asp
The Keil compiled does not execute shift 8, it is 'smart'enough to realize that shift 8 means 'grab the other byte'. Thus shift 8 is fast and simple. Erik
"The Keil compiled does not execute shift 8, it is 'smart'enough to realize that shift 8 means 'grab the other byte'. Thus shift 8 is fast and simple." Yes; that's why I said, "Shifting is portable but may be slow; The others are non-portable, but likely to be fast." (now with added emphasis). Portability is definite; performance depends on the implementation - and which is the most important depends upon the requirements of the application!