Sari la conținut
ELFORUM - Forumul electronistilor

DS1990 - Ibutton


Vizitator excelsior

Postări Recomandate

Vizitator excelsior

Buna,am nevoie de putin ajutor: as dori sa stiu cum se citeste si se scrie in memoria unui pic (de ex;16f628) o cheie tip IButton. Un exemplu in C mi-ar fi de mare ajutor. Multumesc anticipat.

Link spre comentariu
  • Răspunsuri 2
  • Creat
  • Ultimul Răspuns

Top autori în acest subiect

  • fratello

    1

Zile populare

Top autori în acest subiect

Exemplu in PicBasicPro :

'************************************************* ***************'* How to write and then read back from an iButton EEPROM *'* DS1973 or the equivalent 1-wire device, the DS2433 EEPROM. *'* : All Rights Reserved *'************************************************* ***************@ device hs_OSC, wdt_on, pwrt_on, protect_offDEFINE OSC 20iButton var PortD.2 'Connected iButton on 16F877 at this port.RESULT VAR BYTE[19] 'Byte array to put string of characters into.IN VAR BYTE 'Byte to collect the 1 byte you want to read.Taddr var byte[2] 'Target address 2 bytes (TA1 & TA2)ES var byte 'Ending offset data status (E/S)IN=0RESULT=0'(Just connect your serout to to the serial communicator @ 19200)START:'------------------------------------------------'WRITE TO EEPROM'------------------------------------------------OWOUT ibutton,1,[$CC,$0F,$00,$00] 'Write to scratchpadOWOUT IBUTTON,0,["Testing this EEPROM",10,13] 'Write a few characters or values into EEPROMOWout IBUTTON,1,[$CC,$AA] 'get ready to read scratchpadowin ibutton,0,[Taddr[0],Taddr[1],ES] 'read back the scratchpad to get the Authorisation codeowout ibutton,1,[$CC,$55] 'Write back the contents of the target address & E/S register'to allow copy scratchpad to take place.owout ibutton,0,[Taddr[0],Taddr[1],ES] 'Enter Authorisation code as TA1,TA2,E/SPAUSE 25 'Give EEPROM time to write'-----------------------------------------------'READ STRING OF BYTES FROM EEPROM'-----------------------------------------------OWOUT ibutton,1,[$CC,$F0,$00,$00] 'Read scratchpadOWIN IBUTTON,0,[STR RESULT\7] 'PAUSE 1 'Not really nessesarySEROUT2 PORTD.7,16416,[RESULT],10,13] 'You should get the full string you put in.'------------------------------------------------'READ 1 BYTE FROM SPECIFIC ADDRESS'------------------------------------------------OWOUT ibutton,1,[$CC,$F0,$010,$00] 'Read from address $10, first byte of'target address is the Least Significant.OWIN IBUTTON,0,[IN]SEROUT2 PORTD.7,16416,[IN] 'You should get the letter "T"END
si in C ...

#include <touch.c>void main() {BYTE buffer[8];BYTE i;printf("\r\nWaiting for a touch device...\r\n");while (TRUE) {while(!touch_present()) ;delay_ms(200);if(touch_present()) {touch_write_byte(0x33);for(i=0;i<8;++i)buffer[i]=touch_read_byte();}}}//you need to use this lib/////////////////////////////////////////////////////////////////////////////// Dallas Touch Driver //////// //////// present = touch_present() Issues a reset and returns TRUE //////// if the touch device is there. //////// //////// data = touch_read_BYTE() Reads one BYTE from a touch device. //////// //////// ok = touch_write_BYTE(data) Writes one BYTE to a touch device //////// and returns TRUE if all went OK. //////// A FALSE indicates a collision with //////// another device. //////// /////////////////////////////////////////////////////////////////////////////////// Derivative programs created using this software in object code //////// form are not restricted in any way. ///////////////////////////////////////////////////////////////////////////////#ifndef TOUCH_PIN#define TOUCH_PIN PIN_B0#if defined(__PCH__)#bit TOUCH_PIN_BIT = 0xF8A.0#else#bit TOUCH_PIN_BIT = 6.0#endif#endifBYTE touch_read_byte() {BYTE i,data;for(i=1;i<=8;++i) {output_low(TOUCH_PIN);delay_us(14);output_float(TOUCH_PIN);delay_us(5);shift_right(&data,1,input(TOUCH_PIN));delay_us(100);}return(data);}BYTE touch_write_byte(BYTE data) {BYTE i;for(i=1;i<=8;++i) {output_low(TOUCH_PIN);delay_us(10);if(shift_right(&data,1,0)) {output_high(TOUCH_PIN);delay_us(10);if(!TOUCH_PIN_BIT)return(0);} else {output_low(TOUCH_PIN);delay_us(10);if(TOUCH_PIN_BIT)return(0);}delay_us(50);output_high(TOUCH_PIN);delay_us(50);}return(TRUE);}BYTE touch_present() {BOOLEAN present;output_low(TOUCH_PIN);delay_us(500);output_float(TOUCH_PIN);delay_us(5);if(!input(TOUCH_PIN))return(FALSE);delay_us(65);present=!input(TOUCH_PIN);delay_us(240);if(present)return(TRUE);elsereturn(FALSE);}
Sper sa te ajute ! Succes !
Link spre comentariu

Creează un cont sau autentifică-te pentru a adăuga comentariu

Trebuie să fi un membru pentru a putea lăsa un comentariu.

Creează un cont

Înregistrează-te pentru un nou cont în comunitatea nostră. Este simplu!

Înregistrează un nou cont

Autentificare

Ai deja un cont? Autentifică-te aici.

Autentifică-te acum



×
×
  • Creează nouă...

Informații Importante

Am plasat cookie-uri pe dispozitivul tău pentru a îmbunătății navigarea pe acest site. Poți modifica setările cookie, altfel considerăm că ești de acord să continui.Termeni de Utilizare si Ghidări