;----------------------------------------------------------------------------------------; ;THIS PROGRAM CONTROL A FAN AND A HEATER DEPENDING ON THE REFERENCE INPUT AND THE PRESENT; ;ROOM TEMPERATURE AS READ BY THE ADC0804.TEMPERATURE IS DISPLAYED CONTINUOUSLY ON THE TWO; ;SEVEN SEGMENTS WHICH ARE SCANNED BY THIS CODE.NEW REFERENCE TEMPERATURE CAN BE ENTERED ; ;BY UP & DOWN PUSH BUTTONS. ; ;----------------------------------------------------------------------------------------; ;This code is written by Mubashar Yasin(Islamabad,Pakistan).It is freely distributable ; ;however please distribute it with my name and if you add this code to your website or ; ;some other publication then mention about me along with this code.I have tested this ; ;code to work properly even then there is no guarantee or warranty and i cannot be held ; ;responsible for any damage or loss due to this code.If you have any querries about this ; ;code please contact me at: ; ; ; ; kool_projects@yahoo.com ; ; mubasharpk09@hotmail.com ; ; ; ;or visit my website: ; ; ; ; http://www.geocities.com/kool_projects ; ;----------------------------------------------------------------------------------------; COUNT EQU -10000 DIGITAL EQU P1 WRITE EQU P2.0 INTR EQU P2.1 SELECT0 EQU P2.2 SELECT1 EQU P2.3 UP EQU P2.4 DOWN EQU P2.5 ENTER EQU P2.6 FAN EQU P3.0 HEATER EQU P3.1 ORG 0000H LJMP MAIN ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ADJUST: ; 149 cycles for 2 bytes, 77 cycles for 1 byte ;MOV r1,#0AFH ; 175d ;MOV r2,#91H ; 91AFH = 37295d ; Result: R7=3, R6=7, ..., R3=5 ; All 8 registers are used, and also A and B MOV R5,#0 MOV R6,#0 MOV R7,#0 MOV A,R1 MOV B,#10 DIV AB MOV R3,B ; Lower byte, in R1, is transformed into 2 decade digits, MOV R4,A ; it's OK that the higher one can be greater than 9 MOV A,R2 ; Higher byte is in R2 JZ SPRING ; Spring over if 0 MOV B,#10 DIV AB MOV R5,B ; Same as for lower byte MOV R6,A ; Value in R5 is 256 times higher than value standing in R3, R4. Mply R5 with 6, ; add to R3, mply R5 with 5, add to R4, mply R5 with 2 and replace itself in R5 MOV R0,#05 ; Point to R5 ACALL TRANSF ; Transform R5 to 3 lower positions INC R0 ; Repeat from R6, now all registers are 1 higher ACALL TRANSF ; Transform R6 to 3 higher positions SPRING: MOV R0,#03 ; Point to lowest digit ; Adjust to decimal, everything higher than 9 should be, as 1 tenth, added to higher. ; Starting from the lowest digit, divide with 10, keep the rest, and add the 1/10th to ; first higher place (eg. 145, leave 5 and add 14 to the next higher) ACALL DECADJ RET TRANSF: MOV A,@R0 MOV B,#6 MUL AB DEC R0 DEC R0 ADD A,@R0 MOV @R0,A INC R0 INC R0 MOV A,@R0 MOV B,#5 MUL AB DEC R0 ADD A,@R0 MOV @R0,A INC R0 MOV A,@R0 RL A ; Mply with 2 MOV @R0,A RET DECADJ: MOV A,@R0 DECLOP: MOV B,#10 DIV AB MOV @R0,B INC R0 ADD A,@R0 MOV @R0,A CJNE R0,#7,DECLOP RET ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;; LOOK_UP: ;;;;;;;;;;;; INC A MOVC A,@A+PC RET TABLE:DB 0x40,0x7C,0x12,0x18,0x2C,0x09,0x01,0x5C,0x00,0x08 ;COMMON ANODE DISPLAY ;;;;;;;;;;; DELAY: ;;;;;;;;;;; MOV TMOD,#01H MOV TH0,#HIGH COUNT MOV TL0,#LOW COUNT SETB TR0 RET ;;;;;;;;;;;; UP_READ: ;;;;;;;;;;;; JNB UP,$ ; WAIT FOR KEY RELEASE USING 2 INC R1 LCALL ADJUST LCALL REF_DISPLAY USING 0 RET ;;;;;;;;;;;; DOWN_READ: ;;;;;;;;;;;; JNB DOWN,$ USING 2 DEC R1 LCALL ADJUST LCALL REF_DISPLAY USING 0 RET ;;;;;;;;;;;; ENTER_READ: ;;;;;;;;;;;; JNB ENTER,$ USING 2 LCALL ADJUST LCALL REF_DISPLAY USING 0 RET ;;;;;;;;;;;; REF_DISPLAY: ;;;;;;;;;;;; MOV R0,#0x64 ZZZ: LCALL DELAY REPEAT2:MOV P0,#0xFF CLR SELECT1 SETB SELECT0 MOV P0,R3 ;display lower digit SETB P0.7 ;DOT TO SHOW IT IS REF MOV P0,#0xFF CLR SELECT0 SETB SELECT1 MOV P0,R4 ;display high digit SETB P0.7 ;DOT ACTIVE JNB TF0,REPEAT2 CLR SELECT1 CLR TF0 CLR TR0 DJNZ R0,ZZZ RET ;;;;;;;;;;;; DISPLAY: ;;;;;;;;;;;; MOV R0,#0xFF ZZ: LCALL DELAY REPEAT: MOV P0,#0xFF CLR SELECT1 SETB SELECT0 MOV P0,R3 ;display lower digit MOV P0,#0xFF CLR SELECT0 SETB SELECT1 MOV P0,R4 ;display high digit JNB TF0,REPEAT CLR SELECT1 CLR TF0 CLR TR0 JNB UP,UP_PRESSED ;READING THE INPUT KEYS(ACTIVE LOW) JNB DOWN,DOWN_PRESSED JNB ENTER,ENTER_PRESSED SJMP KK UP_PRESSED:LCALL UP_READ SJMP KK DOWN_PRESSED:LCALL DOWN_READ SJMP KK ENTER_PRESSED:LCALL ENTER_READ KK: DJNZ R0,ZZ RET ;;;;;;;;;;;;; MAIN: ;;;;;;;;;;;;; USING 2 MOV R1,#25 ;INITIALIZE REF USING 0 MOV R2,#0 ;initialize R2 AGAIN: CLR WRITE SETB WRITE ;toggle write(start conversion) JB INTR,$ ;wait for ADC interrupt MOV R1,DIGITAL ;read ADC LCALL ADJUST ;convert binary in R1 to bcd in R3 & R4 ;;;;;;; USING 2 MOV A,R1 USING 0 CLR C SUBB A,R1 JC FAN_ON CLR FAN SETB HEATER SJMP JJ FAN_ON: SETB FAN CLR HEATER JJ: ;;;;;;; MOV A,R3 LCALL LOOK_UP MOV R3,A MOV A,R4 LCALL LOOK_UP MOV R4,A LCALL DISPLAY SJMP AGAIN END