用MAXQ3210构建1-Wire温度记录仪
时间:09-13
来源:互联网
点击:
节省功耗
由于本应用每分钟仅记录一次温度数据,而读取DS1822数据并将其存储到EEPROM中仅需几秒钟。多数时间应用都在等待一分钟的延时结束。根据应用的要求,不需更改太多代码即可将温度记录间隔拉长,比如到五分钟、十分钟或三十分钟。为了减少等待期间对电池的消耗,应尽可能降低功耗。
MAXQ3210所能提供的最低功耗模式为待机模式。该模式下,程序停止运行,高频晶振停止工作,电流降到微安量级。由于没有其它器件还在工作,我们需要将MAXQ3210从待机模式周期性的唤醒来测量温度。
这一要求可通过MAXQ3210的唤醒时钟实现。这一时钟依靠在待机模式仍然工作的内部8kHz低电流环形振荡器运行,能以最长两分钟的可编程间隔唤醒微控制器。这种定时唤醒对于我们的应用非常理想,在应用中可将“闹钟”设为一分钟,微控制器工作结束后接着进入待机模式以节省功耗,然后等待被唤醒再次采集数据。
;; Start the wakeup timer for 60 seconds.
move CKCN.6, #1 ; Select ring oscillator mode
waitRing:
move C, CKCN.5
jump NC, waitRing ; Wait for RGMD="1" (running from ring)
move WUT, #30000 ; 1/8kHz * 30000 * 16 = 60 seconds
move WUTC, #0101b ; Start the wakeup timer (running from ring)
move IV, #wakeUpInt ; Set interrupt handler for wakeup interrupt
move IMR.0, #1 ; Enable interrupts from module 0
move IC.0, #1 ; Globally enable interrupts
move PD0.7, #0 ; Turn off output mode for LED pin
move PO0.7, #1 ; Return to default state (weak pullup)
move CKCN.4, #1 ; Go into Stop mode, wait for wakeup int
nop
jump mainLoop ; Back for another round
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
wakeUpInt:
move PD0.7, #1 ; Turn on output mode for LED port pin
move PO0.7, #0 ; Light the LED
move CKCN.6, #1 ; Select ring oscillator mode
wakeUp_ring:
move C, CKCN.5
jump NC, wakeUp_ring ; Wait for RGMD="1" (running from ring)
move LC[0], #4000
djnz LC[0], $
move PO0.7, #1 ; LED off
move LC[0], #4000
djnz LC[0], $
move WUTC, #0 ; Clear wakeup timer flag
move CKCN.6, #0 ; Select crystal mode
wakeUp_xtal:
move C, CKCN.5
jump C, wakeUp_xtal ; Wait for RGMD="0" (running from crystal)
move GRL, #'W'
call TxCharBB
move GRL, #'U'
call TxCharBB
move GRL, #0Dh
call TxCharBB
move GRL, #0Ah
call TxCha
rBB
reti
上传温度记录数据
每次上电复位后,应用程序向主机系统发送温度记录数据。数据通过10位异步串行接口以9600bps的速率发送(1位开始位,8位数据位,1位停止位)。MAXQ3210不带硬件UART串口,需要使用一个端口引脚模拟实现。由于本应用只需发送,不需接收,所以实现起来比较简单。
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Function : TxCharBB
;; Description : Transmits a 10-bit serial character (bit-banged)
;; over P0.0.
;; Inputs : GRL - Character to send
;; Outputs : None
;; Destroys : PSF, AP, APC, A[0], LC[0], LC
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
TxCharBB:
move APC, #080h ; Standard mode, select A[0] as Acc
move Acc, GRL
move PO0.0, #0 ; START bit low
move LC[0], #BITLOOP
djnz LC[0], $
move LC, #8 ; 8 bits
TxCharBB_bitLoop:
rrc ; Get the next bit
jump C, TxCharBB_one
TxCharBB_zero:
move PO0.0, #0
sjump TxCharBB_next
TxCharBB_one:
move PO0.0, #1
TxCharBB_next:
move LC[0], #BITLOOP
djnz LC[0], $
djnz LC, TxCharBB_bitLoop
move PO0.0, #1 ; STOP bit high
move LC[0], #BITLOOP
djnz LC[0], $
move LC[0], #BITLOOP
djnz LC[0], $
ret
要把温度数据从带符号的2进制、8位摄氏度数值转换成容易识别的ASCII码、华氏度数值,还需要增加较多代码,但这些代码简单易懂。使用BCD (二进制编码的十进制)运算规则执行二进制到十进制的转换,同时完成摄氏度到华氏度的转换。
move GR, @DP[0] ; Get the current entry
move Acc, GRH ; Check the high byte
jump Z, endOutput ; If it's zero we're done
move A[15], GRL ; Save the low byte (temp value)
move A, #0 ; Hundreds = 0
move A, #0 ; Tens = 0
move A, #0 ; Ones = 0
move A, #0 ; Tenths = 0
move A, #0 ; Add 01.8 per degree C
move A, #1
move A, #8
move Acc, A[15] ; s6543210
jump S, tempNegC
tempPosC:
move GRL, #'+'
jump Z, tempPrint
move LC[0], Acc
tempPosC_loop:
call AddBCD
djnz LC[0], tempPosC_loop
move A, #3
move A, #2
move A, #0 ; Add 32.0
call AddBCD
jump tempPrint
tempNegC:
move GRL, #'-'
neg
jump Z, tempPrint ; Negative zero
jump S, tempPrint ; -128 is outside the sensor range anyhow
move LC[0], Acc
tempNegC_loop:
call AddBCD
djnz LC[0], tempNegC_loop
move A, #3
move A, #2
move A, #0 ; Subtract 32.0
call SubBCD
jump NC, tempPrint
move GRL, #'+' ; Back to
positive again
jump tempPrint
tempPrint:
call TxCharBB ; Print plus/minus sign
call TxTempBB ; Print temperature value + newline
call IncDP0_EE ; Move to the next entry
由于MAXQ3210的端口输出采用5V电平,在与PC的COM串口连接之前必须使用外部器件(如MAX233ACWP)对输出进行电平转换。完成这一转换后,可以使用任何标准终端仿真程序接收应用输出的数据。
RST
DS1822 Detected : 22A9CC15000000E5
+ 57.2
+ 57.2
+ 57.2
+ 57.2
+ 57.2
+ 57.2
+ 57.2
+ 57.2
+ 57.2
+ 59.0
+ 62.6
+ 69.8
+ 59.0
+ 55.4
+ 55.4
+ 55.4
+ 55.4
+ 55.4
+ 55.4
+ 55.4
+ 57.2
+ 55.4
+ 55.4
+ 57.2
+ 57.2
+ 57.2
+ 57.2
+ 57.2
+ 57.2
由于本应用每分钟仅记录一次温度数据,而读取DS1822数据并将其存储到EEPROM中仅需几秒钟。多数时间应用都在等待一分钟的延时结束。根据应用的要求,不需更改太多代码即可将温度记录间隔拉长,比如到五分钟、十分钟或三十分钟。为了减少等待期间对电池的消耗,应尽可能降低功耗。
MAXQ3210所能提供的最低功耗模式为待机模式。该模式下,程序停止运行,高频晶振停止工作,电流降到微安量级。由于没有其它器件还在工作,我们需要将MAXQ3210从待机模式周期性的唤醒来测量温度。
这一要求可通过MAXQ3210的唤醒时钟实现。这一时钟依靠在待机模式仍然工作的内部8kHz低电流环形振荡器运行,能以最长两分钟的可编程间隔唤醒微控制器。这种定时唤醒对于我们的应用非常理想,在应用中可将“闹钟”设为一分钟,微控制器工作结束后接着进入待机模式以节省功耗,然后等待被唤醒再次采集数据。
;; Start the wakeup timer for 60 seconds.
move CKCN.6, #1 ; Select ring oscillator mode
waitRing:
move C, CKCN.5
jump NC, waitRing ; Wait for RGMD="1" (running from ring)
move WUT, #30000 ; 1/8kHz * 30000 * 16 = 60 seconds
move WUTC, #0101b ; Start the wakeup timer (running from ring)
move IV, #wakeUpInt ; Set interrupt handler for wakeup interrupt
move IMR.0, #1 ; Enable interrupts from module 0
move IC.0, #1 ; Globally enable interrupts
move PD0.7, #0 ; Turn off output mode for LED pin
move PO0.7, #1 ; Return to default state (weak pullup)
move CKCN.4, #1 ; Go into Stop mode, wait for wakeup int
nop
jump mainLoop ; Back for another round
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
wakeUpInt:
move PD0.7, #1 ; Turn on output mode for LED port pin
move PO0.7, #0 ; Light the LED
move CKCN.6, #1 ; Select ring oscillator mode
wakeUp_ring:
move C, CKCN.5
jump NC, wakeUp_ring ; Wait for RGMD="1" (running from ring)
move LC[0], #4000
djnz LC[0], $
move PO0.7, #1 ; LED off
move LC[0], #4000
djnz LC[0], $
move WUTC, #0 ; Clear wakeup timer flag
move CKCN.6, #0 ; Select crystal mode
wakeUp_xtal:
move C, CKCN.5
jump C, wakeUp_xtal ; Wait for RGMD="0" (running from crystal)
move GRL, #'W'
call TxCharBB
move GRL, #'U'
call TxCharBB
move GRL, #0Dh
call TxCharBB
move GRL, #0Ah
call TxCha
rBB
reti
上传温度记录数据
每次上电复位后,应用程序向主机系统发送温度记录数据。数据通过10位异步串行接口以9600bps的速率发送(1位开始位,8位数据位,1位停止位)。MAXQ3210不带硬件UART串口,需要使用一个端口引脚模拟实现。由于本应用只需发送,不需接收,所以实现起来比较简单。
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Function : TxCharBB
;; Description : Transmits a 10-bit serial character (bit-banged)
;; over P0.0.
;; Inputs : GRL - Character to send
;; Outputs : None
;; Destroys : PSF, AP, APC, A[0], LC[0], LC
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
TxCharBB:
move APC, #080h ; Standard mode, select A[0] as Acc
move Acc, GRL
move PO0.0, #0 ; START bit low
move LC[0], #BITLOOP
djnz LC[0], $
move LC, #8 ; 8 bits
TxCharBB_bitLoop:
rrc ; Get the next bit
jump C, TxCharBB_one
TxCharBB_zero:
move PO0.0, #0
sjump TxCharBB_next
TxCharBB_one:
move PO0.0, #1
TxCharBB_next:
move LC[0], #BITLOOP
djnz LC[0], $
djnz LC, TxCharBB_bitLoop
move PO0.0, #1 ; STOP bit high
move LC[0], #BITLOOP
djnz LC[0], $
move LC[0], #BITLOOP
djnz LC[0], $
ret
要把温度数据从带符号的2进制、8位摄氏度数值转换成容易识别的ASCII码、华氏度数值,还需要增加较多代码,但这些代码简单易懂。使用BCD (二进制编码的十进制)运算规则执行二进制到十进制的转换,同时完成摄氏度到华氏度的转换。
move GR, @DP[0] ; Get the current entry
move Acc, GRH ; Check the high byte
jump Z, endOutput ; If it's zero we're done
move A[15], GRL ; Save the low byte (temp value)
move A, #0 ; Hundreds = 0
move A, #0 ; Tens = 0
move A, #0 ; Ones = 0
move A, #0 ; Tenths = 0
move A, #0 ; Add 01.8 per degree C
move A, #1
move A, #8
move Acc, A[15] ; s6543210
jump S, tempNegC
tempPosC:
move GRL, #'+'
jump Z, tempPrint
move LC[0], Acc
tempPosC_loop:
call AddBCD
djnz LC[0], tempPosC_loop
move A, #3
move A, #2
move A, #0 ; Add 32.0
call AddBCD
jump tempPrint
tempNegC:
move GRL, #'-'
neg
jump Z, tempPrint ; Negative zero
jump S, tempPrint ; -128 is outside the sensor range anyhow
move LC[0], Acc
tempNegC_loop:
call AddBCD
djnz LC[0], tempNegC_loop
move A, #3
move A, #2
move A, #0 ; Subtract 32.0
call SubBCD
jump NC, tempPrint
move GRL, #'+' ; Back to
positive again
jump tempPrint
tempPrint:
call TxCharBB ; Print plus/minus sign
call TxTempBB ; Print temperature value + newline
call IncDP0_EE ; Move to the next entry
由于MAXQ3210的端口输出采用5V电平,在与PC的COM串口连接之前必须使用外部器件(如MAX233ACWP)对输出进行电平转换。完成这一转换后,可以使用任何标准终端仿真程序接收应用输出的数据。
RST
DS1822 Detected : 22A9CC15000000E5
+ 57.2
+ 57.2
+ 57.2
+ 57.2
+ 57.2
+ 57.2
+ 57.2
+ 57.2
+ 57.2
+ 59.0
+ 62.6
+ 69.8
+ 59.0
+ 55.4
+ 55.4
+ 55.4
+ 55.4
+ 55.4
+ 55.4
+ 55.4
+ 57.2
+ 55.4
+ 55.4
+ 57.2
+ 57.2
+ 57.2
+ 57.2
+ 57.2
+ 57.2
传感器 总线 温度传感器 电路 电流 振荡器 电阻 Maxim LED 仿真 相关文章:
- 多核及虚拟化技术在工业和安全领域的应用(05-23)
- 基于ARM核的AT75C220及其在指纹识别系统中的应用(05-24)
- 基于音频信号的轴承故障诊断方法(03-17)
- 采用信号调理IC驱动应变片电桥传感器(05-26)
- 基于nRF2401智能无线火灾监控系统设计(04-01)
- 家居安防无线监控报警系统(04-02)
