;**************1-wire bus interface programming**************************
;File: 1-wire.asm
;Function: 1-wire bus interface program
;Device: AT90S2313, DS1821
;Clock: 4.0MHz
;********************************************
;Process name: w1_init
;Function: Initialize 1_wire bus
;Entry parameter: None
;Exit parameter: R30 1: Device response 0: No device response
;Affected resources: R24, R25
;***************1-wire bus assembly programming***************************
w1_init:
clr R30
cbi w1_port, w1_bit ;Output clear
sbi w1_portd, w1_bit ;Set as output, set the bus to low level
ldi R24, 0xE0 ;Delay 480us
ldi R25, 0x01
d1:
sbiw R24, 0x01
brne d1
cbi w1_portd, w1_bit ;Set as input, release the bus
ldi R24, 0x5D ;Delay 70us
d2:
dec R24
brne d2
sbis w1_pin, w1_bit ;The bus is high, no device responds
inc R30 ;The bus is low, there is a device responding, set output R30=1
ldi R24, 0xC2 ;Delay 450us, wait for the reset cycle to complete
ldi R25, 0x01
d3:
sbiw R24, 0x01
brne d3
ret
;****************1-wire bus assembly programming****************************
;Process name: w1_write
;Function: write one byte of data
;Entry parameter: R23
;Exit parameter: none
;Affected resources: R22, R24, R25
;********************1-wire bus assembly programming****************************
w1_write:
ldi R22, 0x08 ;Set counter
write_next:
rcall w1_write_bit ;Write one bit
ror R23 ;Move the data bit to be written into the lowest bit
dec R22
brne write_next ;8 bits are not finished, continue to the next bit
ret
;********************************************
;Procedure name: w1_read
;Function: read a byte of data
;Entry parameter: none
;Exit parameter: R30 The read 8-bit data is stored in R30
;Affected resources: R22, R24, R25
;********************************************
w1_read:
ldi R22, 0x08 ;Set counter
read_next:
rcall w1_read_bit ;Read a bit from the bus
dec R22
brne read_next ;8 bits are not finished, continue to read the next bit
ret
;***************1-wire bus assembly programming******************************
;Procedure name: w1_write_bit
;Function: write a bit of data
;Entry parameter: R23.0
;Exit parameter: none
;Affected resources: R24
;********************************************
w1_write_bit:
sbi w1_portd, w1_bit ;Set to output, set the bus to 0
ldi R24, 0x11
d4:
dec R24 ;Delay 12us
brne d4
sbrc R23, 0 ;To output 0, skip the next line and keep the bus at 0
cbi w1_portd, w1_bit ;Set to input, release the bus, output 1
ldi R24, 0x64
d5:
dec R24 ; delay 75us
brne d5
cbi w1_portd, w1_bit ; writing is completed, set as input, release the bus
ldi R24, 0x03 ; delay 2us
d6:
dec R24
brne d6
ret
;********************************************
; procedure name: w1_read_bit
; function: read one bit of data
; input parameter: none
; output parameter: the 1-bit data read by R30 is stored in the highest bit of R30, and the original data in R30 is shifted right by 1 bit
; affected resources: C, R24
;********************************************
w1_read_bit:
sbi w1_portd, w1_bit ; output 0, pull the bus low
ldi R24, 0x03 ; delay 2us
d7:
dec R24
brne d7
cbi w1_portd, w1_bit ;Set as input, release bus
ldi R24, 0x0F ;Delay 10us
d8:
dec R24
brne d8
clc
sbic w1_pin, w1_bit ;Bus is low, skip the next line, C remains at 0
sec ;Bus is high, C is set to 1
ror R30 ;C moves into the highest bit of R30
ldi R24, 0x6B ;Delay 80us, wait for the cycle to end
d9:
dec R24
brne d9
ret
;****************1-wire bus assembly programming****************************
;This is the end
Previous article:Assembly language multi-byte BCD code addition and subtraction
Next article:SPI bus driver (C language source program)
Recommended ReadingLatest update time:2024-11-16 14:53
- Popular Resources
- Popular amplifiers
- CVPR 2023 Paper Summary: Explainable AI for CV
- ICCV2023 paper summary: motion estimation, matching and tracking
- STC8 series MCU development guide: analysis and application of processors, programming and operating systems
- Compilation system perspective: Graphical explanation of the working mechanism and implementation principle of the GCC compiler
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Today at 10:00 AM, live broadcast with prizes: [Nichicon's new power storage device to open up the IoT society]
- [Serial] [Starlight Lightning STM32F407 Development Board] Chapter 12 RTC Experiment
- Develop smart lights based on Gizwits Cloud platform and ESP8266
- Wheeled robots can tackle new challenges and capabilities
- GD32VF103V_EVAL ADC collects DAC data
- 51 MCU calls the delay function in the for loop
- Bicycle computer based on GD32E231C8T6
- This week's highlights
- STM device I2C drives 0.96 OLED display
- How to choose between different chips in TI's Sub-1GHz product line?