rtr pic

download rtr pic

of 5

Transcript of rtr pic

  • 8/4/2019 rtr pic

    1/5

    Ds1307 Rtc Relgio De Tempo Real - PicArduino Avr- 1 Pea.

    R$ 600

    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!

  • 8/4/2019 rtr pic

    2/5

    Interfacing RTC DS1307 with PIC Microcontroller

    DS1307 is one devices that used widely in micrcontroller applications. It provide Serial Real Time Clock is a lowBCD clock/calendar plus 56 bytes of nonvolatile SRAM.Address and data are transferred serially via the 2wirebus.The clock/calendar provides seconds, minutes, hours, day, date, month, and year information. The end of date is automatically adjusted for months with less than 31 days, including corrections for leap year.The clock either the 24hour or 12hour format with AM/PM indicator. The DS1307 has a builtin power sense circuit whpower 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 DS1as a I2C slave device on the serial bus. Access is obtained by(see fig. 3)implementing a START condition and pdevice identification code followed by a register address. Subsequent registers can be accessed sequentially uncondition is executed. The START and STOP conditions are generated using the low level drives, SEND_START SEND_STOP found in the attached microcontroller code. Also the subroutines SEND_BYTE and READ_BYTE prowire handshaking required for writing and reading 8bit words to and from the DS1307.For more informatio abphillips web site.

    Figure 2. I2C BUS CONFIGURATION

  • 8/4/2019 rtr pic

    3/5

    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, defincondition.

    Stop data transfer: A change in the state of the data line from low to high, while the clock line is high, define

    condition.

    Data valid: The state of the data line represents valid data when, after a START condition, the data line is staduration of the high period of the clock signal. The data on the line must be changed during the low period of tsignal. There is one clock pulse per bit of data. Each data transfer is initiated with a START condition and termSTOP condition. The number of data bytes transferred between the START and the STOP conditions is not limitdetermined by the master device. The information is transferred bytewise and each receiver acknowledges wAcknowledge: Each receiving device, when addressed, is obliged to generate an acknowledge after the recepbyte. The master device must generate an extra clock pulse which is associated with this acknowledge bit. A dacknowledges must pull down the SDA line during the acknowledge clock pulse in such a way that the SDA lineduring the high period of the acknowledge related clock pulse. Of course, setup and hold times must be taken A master must signal an end of data to the slave by not generating an acknowledge bit on the last byte that hclocked out of the slave. In this case, the slave must leave the data line high to enable the master to generate

    condition.

    Interfacing with PIC

    There are two method to programming to interface I2C devices with PICMicro :Software I2C and Hardware I2Cinterface.But,here is only software I2C which programming with CCS. The DS1307 signal pin must pulled up wresistor 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 mread and send data every 500 mS to refresh Hyper terminal program.

  • 8/4/2019 rtr pic

    4/5

    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 teprograms 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/

    http://www.sixca.com/micro/pic/ds1307/download.php?f=ds1307.ziphttp://www.sixca.com/tos_en.htmlhttp://www.mygreendotcom.info/http://www.sixca.com/micro/pic/ds1307/http://www.sixca.com/micro/pic/ds1307/http://www.mygreendotcom.info/http://www.sixca.com/tos_en.htmlhttp://www.sixca.com/tos_en.htmlhttp://www.sixca.com/micro/pic/ds1307/download.php?f=ds1307.zip
  • 8/4/2019 rtr pic

    5/5

    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

    noarquivo.C do DS1302 do CCS.

    Foi maisfcildo 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

    http://www.sixca.com/micro/pic/ds1307/http://www.sixca.com/micro/pic/ds1307/http://www.sixca.com/micro/pic/ds1307/http://www.sixca.com/micro/pic/ds1307/http://www.sixca.com/micro/pic/ds1307/http://www.sixca.com/micro/pic/ds1307/http://www.sixca.com/micro/pic/ds1307/http://www.sixca.com/micro/pic/ds1307/http://www.sixca.com/micro/pic/ds1307/http://www.sixca.com/micro/pic/ds1307/http://www.sixca.com/micro/pic/ds1307/http://forum.clubedohardware.com.br/http://forum.clubedohardware.com.br/http://forum.clubedohardware.com.br/http://forum.clubedohardware.com.br/http://forum.clubedohardware.com.br/http://forum.clubedohardware.com.br/http://www.alldatasheet.com/datasheet-pdf/pdf/254791/MAXIM/DS1307.htmlhttp://www.alldatasheet.com/datasheet-pdf/pdf/254791/MAXIM/DS1307.htmlhttp://www.alldatasheet.com/datasheet-pdf/pdf/254791/MAXIM/DS1307.htmlhttp://forum.clubedohardware.com.br/http://forum.clubedohardware.com.br/