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 Recent Posts

  • Sump pit water alarm - Kicad 9 July 18, 2025
  • Pic18f25q10 osccon1 settings swordfish basic July 17, 2025
  • Anyone jumped from Easyeda std to Easyeda pro? July 17, 2025
  • turbo jet fan - feedback appreciated. July 17, 2025
  • More fun with ws2812 this time XC8 and CLC July 17, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media 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 WTWH Media
Privacy Policy | Advertising | About Us

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