EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Replies / Hi,   void main() {  unsigned

Hi,   void main() {  unsigned

|

Microcontroller › 8051 › one wire communication › Hi,   void main() {  unsigned

August 3, 2011 at 6:30 am #6561
lucky
Participant

Hi,

 

 

 
void main()
 {
  unsigned char i,dat[5];
reset();
write_byte(0xCC); //skip rom command
write_byte(0x0F); //write scratchpad
write_byte(0x00);   //TA1 – data
  write_byte(0x00);   //TA2 – data
  write_byte(10);   //data to memory location 0x10
  write_byte(14); 
reset();
write_byte(0xCC);   //skip rom command
write_byte(0xAA); //read scratchpad command
for(i=0;i<5;i++)
{
dat=read_byte(); 
}
reset();
write_byte(0xCC); //skip rom command
write_byte(0x55); //copy scratchpad
write_byte(0x00);   //TA1 – data
  write_byte(0x00);   //TA2 – data
write_byte(0x01); //ending off set
ms_delay(5);
reset();
// while(1);
 }
 
void reset(void)
 {
  unsigned char presence;
write0();
  ms_delay(500);   //480
  write1();
  ms_delay(80); //70
  presence = read_bit();
  ms_delay(420);   //410
  write1(); //– not required
 }
 
void write_byte(unsigned char w_buff)
 {
unsigned char w_cnt = 0;
// P3=w_buff;
while(w_cnt<8)
{
// P2=w_buff;
if(w_buff & 0x01) //to send LSB first
{
  write1();
}
else
 {
  write0();
 }
w_buff = w_buff >> 1;
w_cnt++;
}
 }
 
unsigned char read_byte(void)
 {
unsigned char temp=0,r_cnt=0,r_buff;
while(r_cnt<8)
{
temp = read_bit();
if(temp)
{
 r_buff |= 1;
}
r_buff=r_buff << 1;
r_cnt++;
}
P3=r_buff;
return(r_buff); 
 }
 
void write0(void)
 {
ds=0;
ms_delay(70);  //actual delay 60us
    ds=1;
ms_delay(10);
 }
 
void write1(void)
 {
  ds=0;
ms_delay(10);  //actual delay 6us
ds=1;
ms_delay(65);  //actual delay 54us
 }
 
unsigned char read_bit(void)
 {
  unsigned char result;
ds=0;
ms_delay(10);   //actual delay 6us
ds=1;
ms_delay(19);   //actual dealay 11us
result=ds;
ms_delay(60);   //sctual delay 45us
return(result);
 }
 
this is my code for writing data into memory, coming to circuit iam using proteus..in that i was connected data pin of eeprom to port pin and i was connected a pullup to that wire…..
 
 

RSS feed: Recent Posts Recent Posts

  • Advice for an ESP32 Soil Tensiometer project with 5V sensors September 9, 2026
  • Marantz SR4500 – CS49400 DSP reverse-engineering / custom active crossover September 9, 2026
  • How does an air tag work? September 9, 2026
  • Cheap ways to link 5 Keithley units and 4 BNC units? September 8, 2026
  • Sony KV-29VL40 - 4 Blink error - IC001 Pin 17 high September 8, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 Arrowfly LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of Arrowfly
Privacy Policy | Advertising

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise