📄 read_7022b.txt
字号:
$include (c8051f330.inc)
cs bit p0.3
sig bit p0.6
org 0000h
ljmp start
org 0100h
start:anl PCA0MD, #NOT(040h)
acall init_device
loop: acall delay
acall ryxz
sjmp $
ryxz: mov a,#0dh ;A相电压
mov r0,#30h
lcall spi_read
mov a,#0eh ;B相电压
mov r0,#33h
lcall spi_read
mov a,#0fh ;C相电压
mov r0,#36h
lcall spi_read
mov a,#10h ;A相电流
mov r0,#39h
lcall spi_read
mov a,#11h ;B相电流
mov r0,#3ch
lcall spi_read
mov a,#12h ;C相电流
mov r0,#3fh
lcall spi_read
mov a,#01h ;A相有功功率
mov r0,#42h
lcall spi_read
mov a,#02h ;B相有功功率
mov r0,#45h
lcall spi_read
mov a,#03h ;C相有功功率
mov r0,#48h
lcall spi_read
mov a,#04h ;合相有功功率
mov r0,#4bh
lcall spi_read
mov a,#05h ;A相无功功率
mov r0,#4eh
lcall spi_read
mov a,#06h ;B相无功功率
mov r0,#51h
lcall spi_read
mov a,#07h ;C相无功功率
mov r0,#54h
lcall spi_read
mov a,#08h ;合相无功功率
mov r0,#57h
lcall spi_read
mov a,#14h ;A相功率因数
mov r0,#5ah
lcall spi_read
mov a,#15h ;B相功率因数
mov r0,#5dh
lcall spi_read
mov a,#16h ;C相功率因数
mov r0,#60h
lcall spi_read
mov a,#17h ;合相功率因数
mov r0,#63h
lcall spi_read
mov a,#1ch ;线频率
mov r0,#66h
lcall spi_read
mov a,#18h ;A相电流与电压的相角
mov r0,#69h
lcall spi_read
mov a,#19h ;B相电流与电压的相角
mov r0,#6ch
lcall spi_read
mov a,#1ah ;C相电流与电压的相角
mov r0,#6fh
lcall spi_read
mov a,#3dh ;功率方向
mov r0,#72h
lcall spi_read
ret
spi_read:
anl spi0cn,#0fbh
jnb txbmt,$
mov spi0dat,a
jnb spif,$
clr spif
jnb txbmt,$
mov spi0dat,#00h
jnb spif,$
clr spif
mov @r0,spi0dat
inc r0
jnb txbmt,$
mov spi0dat,#00h
jnb spif,$
clr spif
mov @r0,spi0dat
inc r0
jnb txbmt,$
mov spi0dat,#00h
jnb spif,$
clr spif
mov @r0,spi0dat
orl spi0cn,#04h
ret
delay:mov r3, #1fh
delay0:mov r4, #00h
delay1:mov r7,#00h
djnz r7,$
djnz r4,delay1
djnz r3, delay0
ret
SPI_Init:
mov SPI0CFG, #060h
mov SPI0CN, #00dh
mov SPI0CKR, #01Fh
ret
Port_IO_Init:
; P0.0 - SCK (SPI0), Open-Drain, Digital
; P0.1 - MISO (SPI0), Open-Drain, Digital
; P0.2 - MOSI (SPI0), Open-Drain, Digital
; P0.3 - NSS (SPI0), Open-Drain, Digital
; P0.4 - SDA (SMBus), Open-Drain, Digital
; P0.5 - SCL (SMBus), Open-Drain, Digital
; P0.6 - Unassigned, Open-Drain, Digital
mov P0MDOUT, #00dh
mov XBR0, #006h
mov XBR1, #040h
ret
Oscillator_Init:
mov OSCICN, #082h
ret
Init_Device:
lcall SPI_Init
lcall Port_IO_Init
lcall Oscillator_Init
ret
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -