DESENVOLVIDO PELA PHILIPS SEMICONDUCTOR. COMO CARACTERSTICAS PRINCIPAIS SO: INTERFACE I2C FUNO DE CLOCK E CALENDRIO REGISTRADORES ENDEREAVEIS (HH,MM...) 240 BYTES DE RAM, ALM DOS CITADOS ACIMA CRISTAL DE 32768Hz FORMATO DE HORA: 24 OU 12 INCREMENTO DE ENDEREO AUTOMTICO ALARME PROGRAMVEL, COM INTERRUPO ENDEREO DO ESCREVO (LEITURA) A1 ENDEREO DO ESCRAVO (ESCRITA) A0
void main() { Soft_I2C_Config(&PORTD, 4,3); // Initialize full master mode Soft_I2C_Start(); // Issue start signal Soft_I2C_Write(0xA0); // Address PCF8583 Soft_I2C_Write(0); // Start from word at address 0 (config word) Soft_I2C_Write(0x80); // Write 0x80 to config. (pause counter...) Soft_I2C_Write(0); // Write 0 to cents word Soft_I2C_Write(0); // Write 0 to seconds word Soft_I2C_Write(0x30); // Write 0x30 to minutes word Soft_I2C_Write(0x11); // Write 0x11 to hours word Soft_I2C_Write(0x30); // Write 0x24 to year/date word Soft_I2C_Write(0x08); // Write 0x08 to weekday/month Soft_I2C_Stop(); // Issue stop signal Soft_I2C_Start(); // Issue start signal Soft_I2C_Write(0xA0); // Address PCF8530 Soft_I2C_Write(0); // Start from word at address 0 Soft_I2C_Write(0); // Write 0 to config word (enable counting) Soft_I2C_Stop(); // Issue stop signal
unsigned char txt[6]; //utilizada para conversao de binario para txt para ser impresso
short hora_atual; short minuto_atual; short segundo_atual;
void Escreve_Memoria(unsigned int endereco, unsigned char dado); unsigned char Le_Memoria(unsigned int endereco);
//Passa como parametro as hora em binario (decimal) e entao converte para BCD //para acertar a hora... void acerta_hora(short hora, short minuto, short segundo) { short hora_bcd; short minuto_bcd; short segundo_bcd;
//Passa como parametro tres variaveis que receberao a hora //A hora lida em bcd e deve novamente ser transformada em Binario para o usurio void le_hora(short *hora, short *minuto, short *segundo) { short hora_binario; short minuto_binario; short segundo_binario;
void Escreve_Memoria(unsigned int endereco, unsigned char dado){ I2C1_Start(); // issue I2C start signal I2C1_Wr(0xD0); // send byte via I2C (device address + W) I2C1_Wr(endereco); // send byte (address of EEPROM location) I2C1_Wr(dado); // send data (data to be written) I2C1_Stop(); delay_ms(16); }
unsigned char Le_Memoria(unsigned int endereco){ unsigned char dado_lido;
I2C1_Start(); // issue I2C start signal I2C1_Wr(0xD0); // send byte via I2C (device address + W) I2C1_Wr(endereco); // send byte (address of EEPROM location) I2C1_Repeated_Start(); // issue I2C signal repeated start I2C1_Wr(0xD1); // send byte (device address + R) dado_lido = I2C1_Rd(0u); // Read the data (NO acknowledge) I2C1_Stop(); return(dado_lido); }
void main(){ I2C1_Init(100000); // initialize I2C communication Delay_ms(100); // Wait for UART module to stabilize UART1_Init(9600); // Initialize UART module at 9600 bps Delay_ms(100); // Wait for UART module to stabilize
UART1_Write_Text("Start"); //Acerta hora para 11:11:11