webtemp.pwp


//
// PicoWeb Project File for WebLED
//

#define BANNER "\r\nPicoWeb WebLED\r\n"
#define EEPROM_IP                /* use file "ip" for IP address */
#define ENABLE_WATCHDOG          /* use Atmel watchdog timer hardware */
#define DEBUGGER                 /* include debugger firmware */
#define SERIAL_BAUD_DIVISOR 25   /* 19200 baud @ 8 MHz */

#define DS1621_BASE_ADDR 0x9E    /* ext. DS1621 digital thermometer */
#define I2C_PORT1_PRESENT        /* enable I2C code for DS1621 */

// HTML and images
webtemp.htm           // ii00  (default Web page)
body.htm              // ii01
thermo.htm            // ii02
title.htm             // ii03
scale.htm             // ii04
setpt.htm             // ii05

bruce.jpg
dave_3.jpg
empty.gif
finger4.gif
flame1a.gif
flame2.gif
ice4.gif
ice5.gif
scale.gif
steve.jpg
trans3.jpg
vbar_bot.gif
vbar_red.gif
vbar_tic.gif
vbar_top.gif
vbar_wht.gif

// CGI routines
temperature.cgi       // iu00
temp_top.cgi          // iu01
temp_bottom.cgi       // iu02
set_point.cgi         // iu03
setpoint_finger.cgi   // iu04

//
// included application-specific pcode and/or AVR assembly language follows
//
#avr_reset
;--------------------------------------------------------------------------
; this code is executed each time microcontroller is reset
;--------------------------------------------------------------------------
;
; start DS1621 temperature conversion
;
    ldi     yl,0xEE
    rcall   ds1621_write
    sbi     ddrd,LED_BIT

.eseg
eeprom_setpt:   .dw 70      ; default temperature setpoint
.cseg

#avr_slow
;--------------------------------------------------------------------------
; this code is executed each trip through "slow idle" loop (~1 sec period)
;--------------------------------------------------------------------------
;
        rcall check_heater    ; check heater (set LED as required)

#avr_fast
;--------------------------------------------------------------------------
; this code is executed each trip through "fast idle" loop
;--------------------------------------------------------------------------
;

#avr_asm
;--------------------------------------------------------------------------
; application-specific CGI pcode and AVR assembly routines go here
;--------------------------------------------------------------------------
;

;+
; **-temperature-show the temperature in decimal.
;-
.eseg
temperature:
    pcall tempf_buf
    pcall update_heater
    pjump decconv                       ; convert to decimal ascii

;+
; **-decconv-decimal converter.
;
; inputs:
;   buf = word to convert
;
; outputs:
;   result printed (with pputc)
;
; caveats:
;   MUST be called with pcall!!
;-
#define DIG_BUF buf+6
#define DIG_PTR buf+4
#define DEC_REM buf+2
#define DEC_VAL buf

.cseg
decconv:    .dw pmovwi,DIG_PTR,DIG_BUF         ; pcode_routine
    pbitwi DEC_VAL,0x8000               ; check the sign
    pjumpeq decconv1                    ; positive - start conversion
    pnegw DEC_VAL                       ; negate it
    pputc '-'
decconv1:
    pdiv DEC_VAL,[DEC_VAL],10               ; get next one
    paddwi DEC_REM,'0'                  ; convert digit for display
    pmovbi [DIG_PTR],[byte DEC_REM]            ; save digit
    paddwi DIG_PTR,1                    ; bump past digit just stored
    psubwi DEC_VAL,0                    ; test remaining value
    pjumpne decconv1                     ; if more to convert
decconv2:
    psubwi DIG_PTR,1                    ; point to next one
    pputcb [byte DIG_PTR]               ; show it
    pcmpwi DIG_PTR,DIG_BUF              ; check if just did last one
    pjumpne decconv2                     ; nope - do next one
    pret

;+
; **-temp_top-output image height for lower themometer (white)
;-
.eseg
temp_top:
    pcall tempf_buf
    pcall compute_top
    pjump decconv
    pret

compute_top:
    pmovwi buf+2,130
    psubwi buf+2,[buf]
    pshnw buf+2,1
    pmovwi buf,[buf+2]
    pret

;+
; **-temp_bottom-output image height for lower themometer (red)
;-
.eseg
temp_bottom:
    pcall tempf_buf
    pshnw buf,1
    pjump decconv
    pret

;+
; **-set_point-set heater set point from GET command line
;-
.eseg
set_point:
    pr2s buf,[data_addr],16         ; GET /iiNN?s=xx  <-- we want xx
    pcmpbi buf+9,'?'                ; 01234567890123
    pjumpne not_setting_setpoint
    pclrw buf
    pclrw buf+2
    pmovbi buf,[byte buf+12]
    psubwi buf,'0'
    pmul buf,[buf],10               ; do first digit
    pmovbi buf+2,[buf+13]
    psubwi buf+2,'0'
    paddwi buf,[buf+2]
    pwreebi eeprom_setpt,[byte buf]
not_setting_setpoint:
    pcall get_setpoint
    pjump decconv

;+
; **-get_setpoint-get set point byte from EEPROM
;-
.eseg
get_setpoint:
    pcall update_heater
    pclrw buf
    pee2s buf,eeprom_setpt,1   ; get set point byte from EEPROM
    pret

;+
; **-update_heater-
;-
#define CUR_TEMP buf
#define CUR_SETP buf+14
update_heater:
    pclrw CUR_SETP
    pee2s CUR_SETP,eeprom_setpt,1    ; get setpoint
    pcall tempf_buf                 ; get temperature (into buf)
    pcmpwi CUR_TEMP,[CUR_SETP]      ; check temp against setpoint
    pjumplo heater_on
    pmovbi PORTD+0x20,1<<LED_BIT
    pret
heater_on:
    pmovbi PORTD+0x20,0
    pret

;+
; **-tempf_buf-read current temp (deg-C) into buf
;-
tempf_buf:
    pclrw buf
    pread_temp buf                      ; get temp
    pmovwi buf+4,0x80                  ; set up for sign test
    pandwi buf+4,[buf]                  ; check the sign
    pjumpeq temp_positive                ; it is positive
    pmovbi buf+1,0xff                  ; extend the sign
    pnegw buf                           ; negate
temp_positive:
    pmul buf,[buf],9                    ; C*9
    pdiv buf,[buf],5                    ; /5
    pandwi buf+4,0x80                   ; test original sign
    pjumpeq temp_norenegate              ; positive
    pnegw buf
temp_norenegate:
    paddwi buf,32                       ; +32 - buf now has temp (F)
    pret

;+
; **-setpoint_finger-output HTML image height to position "finger"
;-
setpoint_finger:
    pcall get_setpoint
    pcall compute_top
    psubwi buf,3
    pjump decconv
    pret

;+
; **-check_heater-set LED according to current temp and set point
;-
.cseg
;
;   MUST BE in program memory (.cseg) because we call from idle loop!!!!
;
check_heater:
    rcall pcode
    pee2s buf,511,1  ; is external pcode loaded?
    pandwi buf,0xff
    pjumpne no_update_heater      ; no...exit
    pcall update_heater           ; yes...update heater state
no_update_heater:
    .dw 0           ; exit pcode
    ret

.cseg
#include "muldiv.asm"


Back