Вы находитесь на странице: 1из 5

Ds1307 Rtc Relgio De Tempo Real - Pic Arduino Avr - 1 Pea.

R$ 6
00

Eae! Gostaria de fazer um circuito com este CI, o DS1307, para enviar o horrio a um microcontrolador que ir fazer operaes dependendo da hora recebida. Por exemplo: Todos os dias, exceto sbado e domingo, liga 2 reles as 6 horas. S que eu no to entendendo como "pegar" este horrio com o PIC. Eu vou usar um 16F877A e uso o CCS compiler. Eu sei que o DS1307 manda os dados na forma serial, pelo que eu vi no datasheet. Mas que comando eu teria que usar para pegar esta informao? Eu vi um projeto, que usava um microcontrolador da Atmel onde ele no usava a porta de recepo serial para receper os dados, e sim um pino qualquer. Alguem sabe como eu poderia fazer com o PIC em C? Abrao! Obrigado!

Interfacing RTC DS1307 with PIC Microcontroller

DS1307 is one devices that used widely in micrcontroller applications. It provide Serial Real Time Clock is a lowpower, BCD clock/calendar plus 56 bytes of nonvolatile SRAM.Address and data are transferred serially via the 2wire bidirec bus.The clock/calendar provides seconds, minutes, hours, day, date, month, and year information. The end of the mon date is automatically adjusted for months with less than 31 days, including corrections for leap year.The clock operates either the 24hour or 12hour format with AM/PM indicator. The DS1307 has a builtin power sense circuit which detec power failures and automatically switches to the battery supply.

Figure 1. DS1307 PIN OUT

It 's importance to have some knownledge about I2C when we want to interface with DS1307because the DS1307 oper as a I2C slave device on the serial bus. Access is obtained by(see fig. 3)implementing a START condition and providing device identification code followed by a register address. Subsequent registers can be accessed sequentially until a STO condition is executed. The START and STOP conditions are generated using the low level drives, SEND_START and SEND_STOP found in the attached microcontroller code. Also the subroutines SEND_BYTE and READ_BYTE provide the wire handshaking required for writing and reading 8bit words to and from the DS1307.For more informatio about I2C phillips web site.

Figure 2. I2C BUS CONFIGURATION

Figure 3. DATA TRANSFER ON 2WIRE SERIAL BUS 2-wrie timimg interface(See Fig.3)

Start data transfer: A change in the state of the data line from high to low, while the clock line is high, defines a STA condition.

Stop data transfer: A change in the state of the data line from low to high, while the clock line is high, defines the ST condition.

Data valid: The state of the data line represents valid data when, after a START condition, the data line is stable for th duration of the high period of the clock signal. The data on the line must be changed during the low period of the clock signal. There is one clock pulse per bit of data. Each data transfer is initiated with a START condition and terminated wi STOP condition. The number of data bytes transferred between the START and the STOP conditions is not limited, and determined by the master device. The information is transferred bytewise and each receiver acknowledges with a nint

Acknowledge: Each receiving device, when addressed, is obliged to generate an acknowledge after the reception of ea byte. The master device must generate an extra clock pulse which is associated with this acknowledge bit. A device tha acknowledges must pull down the SDA line during the acknowledge clock pulse in such a way that the SDA line is stabl during the high period of the acknowledge related clock pulse. Of course, setup and hold times must be taken into acco A master must signal an end of data to the slave by not generating an acknowledge bit on the last byte that has been clocked out of the slave. In this case, the slave must leave the data line high to enable the master to generate the STO condition. Interfacing with PIC

There are two method to programming to interface I2C devices with PICMicro :Software I2C and Hardware I2C interface.But,here is only software I2C which programming with CCS. The DS1307 signal pin must pulled up with exter resistor about 10K to ensure logic level.

The software will reads all data from RTC then send to PC via RS232 interface with buad rate 9600,8,N,1. In main loop read and send data every 500 mS to refresh Hyper terminal program.

Figure 4.Connecting DS1307 with PIC for this example In this example I use Hyper terminal sotware to show all data received from DS1307 and you can use other terminal programs that you can find.

Source code (CCS)

Copyright(c) 2005-2010 sixca.com, All rights reserved. Best view @ 800X600, IE 6.0 up Terms Privacy www.mygreendot.com

http://www.sixca.com/micro/pic/ds1307/

u no consegui fazer funcionar aquele cdigo fonte ali. Ento fui atrs do meu... Descobri como capturar os dados de um DS1302. Foi s dar uma olhada no cdigo fonte dele, que tem la no CCS mesmo... Utilizei os comando de l para gravar os valores em umas variveis que criei. Por exemplo: para pegar o valor da hora, utilizo: hr = rm_bcd(read_ds1302(0x85)); hr uma varivel que criei. e o comando rm_bcd(read_ds1302(0x85)); est descrito no arquivo .C do DS1302 do CCS. Foi mais fcil do que eu imaginei conseguir estes valores... Ele me parece mais fcil de operar do que o DE1307. Agora vou descobrir como converter o valor da data, e como escrever novos valores. Pois vou fazer o seguinte, vou gravar um programa no PIC somente para arrumar a data e hora do DS. Ai depois tiro ele e deixo s na bateria e alimentao. no calculei ainda quando ir durar 2 pilhas de 1,5V duracell. Vou dar uma olhada nisto. Eu quero montar um controle dentro de casa, para acionar uns equipamentos. Eu vou usar um transmissor e um receptor no momento. Depois se for necessrio colocarei mais receptores. Tenho que estudar agora como eles funcionam, e se a transmisso de dados 100% garantida. Seno acho que vou ficar enviando sempre o mesmo byte durante o processo que quero realizar. Por ex.: quero ligar um rele quando envio o valor 8 na porta serial. Vou ficar enviando sempre o valor 8 enquanto quero que o rele fique ligado. Para garantir a transmisso. vou enviar 32 quando quero deslig-lo... Assim eu fico enviando 32 o resto do dia. No sei se o consumo de energia aumenta muito se eu ficar sempre enviando, ou no.

Amigo CeDahmer, ento voc sabe como funciona o I2C? Tente dar uma estudada no protocolo e saberas o que cada funo faz, no proprio datasheet do 1307 explica, e bem como funciona a comunicao e como fazer a leitura do chip: http://www.alldatasheet.com/datashee...IM/DS1307.html

Вам также может понравиться