int main(void) { int * p; unsigned char buffer[16]= {1,2,3,4,5,6,7,8,9,0}; SystemInit(); //设置系统时钟为72M KeyInit(); //按键管脚初始化 LED_GPIO_Config();//LED管脚初始化 lcd_gpio_config(); CAN_GPIO_Config();//CAN管脚初始化 CAN_NVIC_Configuration(); //CAN中断初始化 CAN_INIT();//CA初始化N模块 // p = (int*)0x8001600; // *p = 0xaaaa; lcd_init(); sw_i2c_init(); lcd_clear(0x00); write_32byte(X_1,Y_1,2); write_32byte(X_2,Y_1,2); write_32byte(X_3,Y_1,2); write_32byte(X_4,Y_1,2); sw_i2c_read(0,1,buffer,16); while(1) { GetKey(); //检测是否有按键按下 } }
/*---------------------------------------------------------------------------*/ INT8U RTC_RandomRead(INT8U Address) // Description: // Random Read Operation. Data is read from the RTC. The RTC // address is defined with the parameter Address. { INT8U data_in; #if (defined I2C_SW && I2C_SW == 1) CRITICAL_SECTION_START(); sw_i2c_start(); // Send start signal sw_i2c_write(DS1307Address); // Send identifer I2C address (10100000b) delay_time(I2C_DELAY); sw_i2c_write((INT8U) Address); // Send address to EEPROM delay_time(I2C_DELAY); sw_i2c_start(); // Send I2C Start Transfer sw_i2c_write(DS1307Address | 1); // Send identifer I2C address (10100001b) delay_time(I2C_DELAY); data_in = sw_i2c_read(0); // Read byte sw_i2c_stop(); // Send I2C Stop Transfer CRITICAL_SECTION_END(); #else IIC_transmite(DS1307Address, Address, NULL); IIC_recebe(DS1307Address, &data_in); #endif return data_in; }
/*---------------------------------------------------------------------------*/ u08 EEPROM_RandomRead(u16 Address) // Description: // Random Read Operation. Data is read from the EEPROM. The EEPROM // address is defined with the parameter Address. { char data_in; #if (defined I2C_SW && I2C_SW == 1) sw_i2c_start(); // Send start signal sw_i2c_write(EEPROMAddress);// Send identifer I2C address (10100000b) delay_time(I2C_DELAY); sw_i2c_write((unsigned char) (high_byte(Address)));// Send address to EEPROM delay_time(I2C_DELAY); sw_i2c_write((unsigned char) Address);// Send address to EEPROM delay_time(I2C_DELAY); sw_i2c_start();// Send I2C Start Transfer sw_i2c_write(EEPROMAddress + 1);// Send identifer I2C address (10100001b) delay_time(I2C_DELAY); data_in = sw_i2c_read(0);// Read byte sw_i2c_stop(); // Send I2C Stop Transfer #else /* Dummy write: Transmite NULL depois gera um sinal de start repeated */ IIC_transmite(EEPROMAddress, Address, NULL); IIC_recebe(EEPROMAddress, &data_in); #endif return data_in; }
/*---------------------------------------------------------------------------*/ INT8U RTC_CurrentAddressRead(void) // Description: // Current Address Read Operation. Data is read from the RTC. The current // address from the RTC is used. { INT8U data_in; #if (defined I2C_SW && I2C_SW == 1) CRITICAL_SECTION_START(); sw_i2c_start(); // Send I2C Start Transfer sw_i2c_write(DS1307Address | 1); // Send identifer I2C address (10100001b) data_in = sw_i2c_read(0); // Read byte sw_i2c_stop(); // Send I2C Stop Transfer CRITICAL_SECTION_END(); #else IIC_recebe(DS1307Address, &data_in); #endif return data_in; }
/*---------------------------------------------------------------------------*/ u08 EEPROM_CurrentAddressRead(void) // Description: // Current Address Read Operation. Data is read from the EEPROM. The current // address from the EEPROM is used. { u08 data_in; #if (defined I2C_SW && I2C_SW == 1) sw_i2c_start(); // Send start signal sw_i2c_write(EEPROMAddress);// Send identifer I2C address (10100000b) sw_i2c_start(); // Send I2C Start Transfer sw_i2c_write(EEPROMAddress + 1);// Send identifer I2C address (10100001b) data_in = sw_i2c_read(0);// Read byte sw_i2c_stop(); // Send I2C Stop Transfer #else IIC_recebe(EEPROMAddress, &data_in); #endif return data_in; }