18
图示 18. 典型 程序 为 读 hctl-2032 和 atmel avr
设置 portb.4 'en1=1
重置 portb.5 'en2=0
重置 portb.6 '选择 x-axis
结果_新 = 0
结果_old_x = 0
结果_old_y = 0
做
设置 portb.0 '使不能运转 oe
waitms 25
重置 portb.1 'sel1=0 (msb)
设置 portb.3 'sel2=1 (msb)
重置 portb.0 '使能 oe
gosub 得到_hi '得到 msb
设置 portb.1 'sel1=1 (2nd 字节)
设置 portb.3 'sel2=1 (2nd 字节)
gosub 得到_2nd '得到 2nd 字节
重置 portb.1 'sel1=0 (3rd 字节)
重置 portb.3 'sel2=0 (3rd 字节)
gosub 得到_3rd '得到 3rd 字节
设置 portb.1 'sel1=1 (lsb)
重置 portb.3 'sel2=0 (lsb)
gosub 得到_lo '得到 lsb
设置 portb.0 '使不能运转 oe
waitms 25
mult = 1
温度 = 结果_lo * mult 'assign lsb
结果 = 温度
mult = mult * 256
温度 = 结果_3rd * mult'assign 3rd 字节
结果 = 结果 + 温度
mult = mult * 256
温度 = 结果_2nd * mult'assign 2nd 字节
结果 = 结果 + 温度
mult = mult * 256
温度 = 结果_hi * mult 'assign msb
结果 = 结果 + 温度
'
'结果 = 32-位 计数 数据
'
.
.
循环
得到_hi:
hi_old = pina '得到 电流 数据
hi_新 = pina '得到 2nd 数据
如果 hi_新 = hi_old 然后
结果_hi = hi_新 '得到 稳固的 数据
返回
Else
goto 得到_hi
终止 如果