1-wire bus assembler

Publisher:幸福家庭Latest update time:2013-01-07 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

;**************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

Reference address:1-wire bus assembler

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

1-Wire Bus Technology and Its Applications
1 Introduction At present, the commonly used serial buses for data transmission between microcomputers and peripherals are mainly I2C bus, SPI bus and SCI bus. Among them, I2C bus communicates in synchronous serial 2-wire mode (one clock line, one data line), SPI bus communicates in synchronous seri
[Industrial Control]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号