$include (C8051F410.inc) CSEG at 0000h jmp main org 0100h Main: anl PCA0MD, #0BFh ; switch the watchdog timer off mov PCA0MD, #000h mov ADC0MX, #00Eh ; select ADC input mov ADC0CN, #084h ; setup the ADC mov REF0CN, #00Bh ; setup voltage reference used by the ADC mov P1MDIN, #0BFh ; set the analog input mov XBR1, #040h ; enable the crossbar ret again: clr AD0INT ; clear A/D conversion ready flag setb AD0BUSY ; start conversion jnb AD0INT, $ ; wait for end of conversion mov a, ADC0H ; use 8-bit conversion result mov b,#103 ; set b to 103 mul ab ; multiply the conversion result by 103 (and divide by 256, so the result is in b! mov a,#77 ; clr c subb a,b ; a = 77-103*conversion result, temperature in C degrees call D2BCD ; convert to 2 digit BCD number (a <- first digit, b <- second digit call BCD7S ; convert the first digit to 7 segment data and put on the display clr P1.3 ; set the display to show the first digit call Delay ; let is light for a while mov a,b ; move the second digit to a call BCD7S ; convert to 7 segment data and put on the display setb P1.3 ; set the display to show the second digit call Delay ; let is light for a while jmp again ; repeat forever BCD7S: push acc ; save the accumulator mov dptr,#Table ; load the conversion table address movc a,@a+dptr ; load the proper value from the table cpl a ; use negative logic mov P2,a ; switch on the 7 segment LEDs pop acc ; restore the accumulator ret D2BCD: ; convert to BCD mov b,#10 div ab ; divide by 10, a<-first digit, b<-second digit ret Delay: ; wait for a short time push acc ; save the accumulator clr a ; a=0 djnz acc,$ ; repeat 256 times pop acc ; restore the accumulator ret Table: ; this table holds the binary 7 segment conversion codes db 03Fh, 006h, 05Bh, 04Fh, 066h, 06Dh, 07Dh, 007h, 07Fh, 06Fh end