功能是从国半的LM74传感器中读取数据,并转化成比较友好的格式(-123℃, +030℃).
需要的朋友只要根据实际情况修改一下数据缓冲区和数据转换算法,同时要注意必须依照
晶振的主频率调整nop的个数,以正确模拟总线时钟。
;################################################; Designed by CaoHai 10-23-2002 in SDUWHB ;; Updated by CaoHai 12-12-2002 in SDUWHB ;; Upgraded by CaoHai 22-12-2002 in SDUWHB ;; Upgraded by CaoHai 05-05-2003 in SDUWHB ;;################################################;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;标号定义data_len equ 0ch ;温度数据长度data_buf equ 50h ;温度数据缓冲区;虚拟引脚定义(For SPI BUS)vcs equ p1.0 ;片选线vio equ p1.1 ;数据线vsc equ p1.2 ;时钟线;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;================================================;模块GetData ;参数:无参数 ;功能:用spi总线从LM74温度传感器读取温度数据 ;返回:无GetData: clr ea clr vcs setb vio mov r1,#08h clr vsc ;读符号位 nop nop nop setb vsc nop nop nop mov f0,vioread_bite: ;读数据 clr vsc nop nop nop setb vsc nop nop nop mov c,vio rlc a djnz r1,read_bite setb vcs ;转换数据 mov data_buf+1,#2bh ;'+' jnb f0,fill_data dec a cpl a mov data_buf+1,#2bh ;'-'fill_data: mov data_buf+2,#30h mov data_buf+3,#30h mov data_buf+4,#30h mov data_buf+5,#0a1h ;℃-l mov data_buf+6,#0e6h ;℃-h mov data_buf+7,#3bh ;; mov data_buf+8,#20h ; mov data_buf+9,#30h ; mov data_buf+10,#30h ; mov data_buf+11,#31h ; mov data_buf+12,#7ch ;| mov r0,#data_buf+4pide_data: mov b,#0ah p ab mov r1,a mov a,b add a,#30h mov @r0,a dec r0 mov a,r1 jnz pide_data mov data_buf,#data_len setb ea ret