This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Temp Meter

I am working on a design using the on-chip temperature sensor:
Displays the room temperature in a LCD
and lights an array of six led's blinking to
form a christmas tree.

Need assistance in C or assembler ...

Parents
  • ; MAIN PROGRAM CODE
    ;
    Temp_2 SEGMENT CODE ; declare CODE segment
    RSEG Temp_2 ; select CODE segment
    USING 0 ; using register bank 0
    Main:
    mov WDTCN, #0deh ; disable watchdog timer
    mov WDTCN, #0adh
    mov SP, #STACK-1 ; init stack pointer
    mov OSCXCN, #67h ; enable external crystal oscillator at 18.432MHz
    clr A ; wait at least 1ms
    djnz acc, $ ; wait 512us
    djnz acc, $ ; wait 512us
    osc_wait: ; poll for XTLVLD-->1
    mov a, OSCXCN
    jnb acc.7, osc_wait

    orl OSCICN, #08h ; select external oscillator as
    ; system clock source
    orl OSCXCN, #80h ; enable missing clock detector
    mov XBR2, #40h ; Enable crossbar and weak pull-ups
    orl PRT1CF, #40h ; enable P1.6 (LED on target board) as push-pull
    acall ADC0_Init ; initialize ADC0 and temp sensor
    acall Timer3_Init ; initialize Timer3
    acall Timer3_Start ; enable Timer3
    acall ADC0_Enable ; enable ADC
    setb EA ; enable global interrupts
    sjmp $ ; spin forever
    ; MAIN SUBROUTINES;
    ; INTERRUPT VECTORS
    ;
    ; ADC0_ISR
    ;
    ; ISR is activated on the completion of an ADC sample.
    ; When event occurs, the ADC value is copied to the holding variable TEMPCODE, and is
    ; compared with the code for 25 degrees C.
    ; If the temperature is above 25 degrees C, the LED is turned on.
    ; If the temperature is below 25 degrees C, the LED is turned off.
    ; There is no correction for self-heating.
    ;
    ADC0_ISR:
    push PSW ; preserve registers
    push acc
    clr ADCINT ; clear ADC0 interrupt flag
    mov TEMPCODE, ADC0H ; copy MSB of ADC0 result into
    ; TEMPCODE
    mov TEMPCODE+1, ADC0L ; copy LSB of ADC result into
    ; TEMPCODE

    ; compare TEMPCODE with value expected for 25 degrees C
    ; if (TEMPCODE - ROOMDEG) < 0, then turn LED off, otherwise, turn it on.
    ; calculate TEMPCODE - ROOMREG and store in TEMPCODE (16-bit subtract)

    clr C
    mov a, TEMPCODE+1 ; subtract LSBs
    subb a, #LOW(ROOMCODE)
    mov TEMPCODE+1, a ; store new LSB
    mov a, TEMPCODE ; subtract MSBs (and carry)
    subb a, #HIGH(ROOMCODE)
    mov TEMPCODE,a ; store new MSB
    setb LED ; turn LED on.
    jnc ADC0_ISR_END ; exit if subtract result was positive,
    clr LED ; otherwise, turn LED off then exit
    ADC0_ISR_END:
    pop acc
    pop PSW

    reti

    ;

Reply
  • ; MAIN PROGRAM CODE
    ;
    Temp_2 SEGMENT CODE ; declare CODE segment
    RSEG Temp_2 ; select CODE segment
    USING 0 ; using register bank 0
    Main:
    mov WDTCN, #0deh ; disable watchdog timer
    mov WDTCN, #0adh
    mov SP, #STACK-1 ; init stack pointer
    mov OSCXCN, #67h ; enable external crystal oscillator at 18.432MHz
    clr A ; wait at least 1ms
    djnz acc, $ ; wait 512us
    djnz acc, $ ; wait 512us
    osc_wait: ; poll for XTLVLD-->1
    mov a, OSCXCN
    jnb acc.7, osc_wait

    orl OSCICN, #08h ; select external oscillator as
    ; system clock source
    orl OSCXCN, #80h ; enable missing clock detector
    mov XBR2, #40h ; Enable crossbar and weak pull-ups
    orl PRT1CF, #40h ; enable P1.6 (LED on target board) as push-pull
    acall ADC0_Init ; initialize ADC0 and temp sensor
    acall Timer3_Init ; initialize Timer3
    acall Timer3_Start ; enable Timer3
    acall ADC0_Enable ; enable ADC
    setb EA ; enable global interrupts
    sjmp $ ; spin forever
    ; MAIN SUBROUTINES;
    ; INTERRUPT VECTORS
    ;
    ; ADC0_ISR
    ;
    ; ISR is activated on the completion of an ADC sample.
    ; When event occurs, the ADC value is copied to the holding variable TEMPCODE, and is
    ; compared with the code for 25 degrees C.
    ; If the temperature is above 25 degrees C, the LED is turned on.
    ; If the temperature is below 25 degrees C, the LED is turned off.
    ; There is no correction for self-heating.
    ;
    ADC0_ISR:
    push PSW ; preserve registers
    push acc
    clr ADCINT ; clear ADC0 interrupt flag
    mov TEMPCODE, ADC0H ; copy MSB of ADC0 result into
    ; TEMPCODE
    mov TEMPCODE+1, ADC0L ; copy LSB of ADC result into
    ; TEMPCODE

    ; compare TEMPCODE with value expected for 25 degrees C
    ; if (TEMPCODE - ROOMDEG) < 0, then turn LED off, otherwise, turn it on.
    ; calculate TEMPCODE - ROOMREG and store in TEMPCODE (16-bit subtract)

    clr C
    mov a, TEMPCODE+1 ; subtract LSBs
    subb a, #LOW(ROOMCODE)
    mov TEMPCODE+1, a ; store new LSB
    mov a, TEMPCODE ; subtract MSBs (and carry)
    subb a, #HIGH(ROOMCODE)
    mov TEMPCODE,a ; store new MSB
    setb LED ; turn LED on.
    jnc ADC0_ISR_END ; exit if subtract result was positive,
    clr LED ; otherwise, turn LED off then exit
    ADC0_ISR_END:
    pop acc
    pop PSW

    reti

    ;

Children
No data