Вы находитесь на странице: 1из 7

# INCLUDE "8051EQU.INC" DQ CLK RST ; RESET .ORG AJMP .equ .equ .equ P3.5 P3.4 P3.

;include predefined constants ; ; Give names to pins to simplify code writing. This also makes it easy to change pin ; assignments later. ;

0H START

;reset routine ;locate routine at 00H ;jump to START ;place interrupt routines at appropriate ;memory locations ;external interrupt 0 ;timer 0 interrupt ;external interrupt 1 ;timer 1 interrupt ;serial port interrupt ;locate beginning of rest of program

; ; ;

; INTERRUPTS (not used) .ORG RETI .ORG RETI .ORG RETI .ORG RETI .ORG RETI .ORG 03H 0BH 13H 1BH 23H 25H

START: MOV ACALL INITIALIZE: SP INITIALIZE , #030H

Comment ;Set Stack Pointer to 30H ;Set up control registers ; set up control registers for serial port ; The value in TH1 determines the baud rate. ; The baud rate will either be the low rate or the high rate, ; depending on whether the first bit in PCON is 0 or 1 ; ; To change the baud rate, uncomment the line with the value of TH1 that you need ; and comment out the old line. Do the same for PCON. ; ;Set up FOR 28800 or 57600 baud rate ; Set up for 14400 or 28800 baud rate ;Set up for 9600 or 19200 baud rate ; ; set SMOD for regular baud rate ; set SMOD for double baud rate ; ;Mode = 8 bit UART ;Sets Timer1 to 8 bit auto reload ;Turns Timer1 on ; ; Start with CLK equal to 1 M:This instr makes 'CLK' on th 2051 an I/O pin ; Configure DS1620 ; Routine to Configure DS1620 ; Make 1620 reset go High to start transfer ; Send the "Write Config" command to 1620 ; This routine writes the value in A to the DS1620 ; Set Counter for 8 bits ; Start clock cycle ; Rotate A Right into Carry Bit(Lowest Bit in A goes to C) ; Move outgoing bit to DQ ; Rising Edge of Clock makes one clock cycle ; Dec R0 by 1. If resul is zero then jump to NEXTBITWRITE - loops back on itself 8 times - SMART :)

; ;

MOV MOV MOV MOV MOV MOV MOV MOV

TH1 TH1 TH1 PCON PCON SCON TMOD TCON CLK CONFIGURE RST A WRITE1620 R0 CLK A DQ CLK R0

, , , , , , , ,

#0FFH #0FEH #0FDH #00000000B #10000000B #01010000B #00100001B #01000000B

RET SETB ACALL CONFIGURE: SETB MOV ACALL WRITE1620: MOV NEXTBITWRITE: CLR RRC MOV SETB DJNZ , #08H , #0CH

, ,

C NEXTBITWRITE

RET MOV ACALL WRITE1620: MOV NEXTBITWRITE: CLR RRC MOV SETB DJNZ RET CLR RET ACALL ACALL ACALL ACALL ACALL ACALL ACALL ACALL ACALL ACALL LOOP: ACALL START_CONVERT: SETB MOV ACALL WRITE1620: MOV NEXTBITWRITE: CLR RRC MOV SETB DJNZ RET CLR RET ACALL DELAYS: MOV MOV LOOPB: INC ACALL DELAYMS: MOV LOOPA: INC MOV CJNE RET MOV JNZ DEC MOV JNZ RET ACALL READ_TEMPERATURE ; Get Temperature Reading A LOOPB R5 A LOOPB , R6 R7 A A , , R7 #0FFH ;increase R7 by one (R7 = R7 +1) ;move value in R7 to Accumlator (also known as A) ;compare A to FF hex (256). If not equal go to LOOPA ;return to the point that this routine was called from ;move value in R6 to A ;if A is not 0, go to LOOPB ;decrease R5 by one. (R5 = R5 -1) ;move value in R5 to A ;if A is not 0 then go to LOOPB. R7 , #00H R6 DELAYMS ;increase R6 by one (R6 = R6 +1) ;call the routine above. It will run and return to here. ;millisecond delay routine ;put value of 0 in register R7 R6 R5 , , #00H #004H DELAYS ;One second delay routine ;put 0 in register R6 (R6 = 0) ;put 5 in register R5 (R5 = 4) RST ; Make 1620 reset go Low to signal end of transfer CLK A DQ CLK R0 ; Start clock cycle ; Rotate A Right into Carry Bit(Lowest Bit in A goes to C) ; Move outgoing bit to DQ ; Rising Edge of Clock makes one clock cycle ; Dec R0 by 1. If resul is zero then jump to NEXTBITWRITE - loops back on itself 8 times - SMART :) R0 , #08H RST A WRITE1620 , #0EEH START_CONVERT ; Send command to Start temperature conversion ; Routine to Start Temperature Conversion on 1620 ; Make 1620 reset go High to start transfer ; Send the "START CONVERT" command to 1620 ; This routine writes the value in A to the DS1620 ; Set Counter for 8 bits DELAYMS DELAYMS DELAYMS DELAYMS DELAYMS DELAYMS DELAYMS DELAYMS DELAYMS DELAYMS ; wait 10 MS for Configuration to be Written. This is the 1st ms ; 2nd ms ;3rd ms ; 4th ms ;5th ms ; 6th ms ;7th ms ; 8th ms ; 9th ms ; 10th ms RST ; Make 1620 reset go Low to signal end of transfer CLK A DQ CLK R0 ; Start clock cycle ; Rotate A Right into Carry Bit(Lowest Bit in A goes to C) ; Move outgoing bit to DQ ; Rising Edge of Clock makes one clock cycle ; Dec R0 by 1. If resul is zero then jump to NEXTBITWRITE - loops back on itself 8 times - SMART :) R0 , #08H A WRITE1620 , #00001010H ; CPU = 1, 1Shot = 0, THF = 0, TLF = 0 ; Send the Configuration Byte ; This routine writes the value in A to the DS1620 ; Set Counter for 8 bits

, ,

C NEXTBITWRITE

, ,

C NEXTBITWRITE

LOOPA

R5

READ_TEMPERATURE: SETB MOV ACALL WRITE1620: MOV NEXTBITWRITE: CLR RRC MOV SETB DJNZ RET ACALL READ1620: MOV SETB NEXTBITREAD: CLR MOV SETB RRC DJNZ CLR RET MOV ACALL READ1620: MOV SETB NEXTBITREAD: CLR MOV SETB RRC DJNZ CLR RET MOV CLR RET MOV ACALL SEND: CLR MOV WAIT: JNB RET AJMP END LOOP TI , WAIT TI SBUF , A A SEND , R1 R2 RST , A CLK C CLK A R0 DQ , DQ R0 DQ , #08H R1 READ1620 , A CLK C CLK A R0 DQ , DQ R0 DQ , #08H READ1620 CLK A DQ CLK R0 R0 , #08H RST A WRITE1620 , #0AAH

; Routine to Read Temperature from 1620 ; Send the "Read Temperature" command ; This routine writes the value in A to the DS1620 ; Set Counter for 8 bits ; Start clock cycle ; Rotate A Right into Carry Bit(Lowest Bit in A goes to C) ; Move outgoing bit to DQ ; Rising Edge of Clock makes one clock cycle ; Dec R0 by 1. If resul is zero then jump to NEXTBITWRITE - loops back on itself 8 times - SMART :) ; Get first byte of temperature ; This routine reads a value from the DS1620 and puts it in A ; Set Counter for 8 bits ; Set DQ to 1 to enable it as an input pin. M:DQ on 2051=pin9 P3.5 ; Start clock cycle ; Move incoming bit to DQ ; Rising Edge of Clock makes one clock cycle ; Rotate A Right through Carry Bit(C goes to Highest Bit of A) ; M: Dec R0 by 1. and jump if result is not zero

, ,

C NEXTBITWRITE

NEXTBITREAD

; Store Byte in R1 ; Get second byte of temperature ; This routine reads a value from the DS1620 and puts it in A ; Set Counter for 8 bits ; Set DQ to 1 to enable it as an input pin. M:DQ on 2051=pin9 P3.5 ; Start clock cycle ; Move incoming bit to DQ ; Rising Edge of Clock makes one clock cycle ; Rotate A Right through Carry Bit(C goes to Highest Bit of A) ; M: Dec R0 by 1. and jump if result is not zero

NEXTBITREAD

; Store Byte in R2 ; End Transfer "READ_TEMPERATURE:"

; Send value to serial port ; This routine transmits the value in A through the serial port. ;Clear Transmit Flag ;Transmit Byte ;Wait for transmission to be completed.

Stack Pointer

= 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0 1 0 0 0 0 0 1 0 1 1 0 0 0 0 1 1 0 0 0 0 0 0 1 1 0 1 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1

Dec Hex 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 6 7 8 9 A B C D E F

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0 1 0 0 0 0 0 1 0 1 1 0 0 0 0 1 1 0 0 0 0 0 0 1 1 0 1 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1

INITIALIZE: ;set up control registers for serial port ; ; The value in TH1 determines the baud rate. ; The baud rate will either be the low rate or the high rate, ; depending on whether the first bit in PCON is 0 or 1 ; ; To change the baud rate, uncomment the line with the value of TH1 that you need ; and comment out the old line. Do the same for PCON. ; ; MOV TH1, #0FFH ;Set up FOR 28800 or 57600 baud rate ; MOV TH1, #0FEH ;Set up for 14400 or 28800 baud rate MOV TH1, #0FDH ;Set up for 9600 or 19200 baud rate ; MOV PCON, #00000000B ; set SMOD for regular baud rate ; MOV PCON, #10000000B ; set SMOD for double baud rate ; MOV SCON, #01010000B ;Mode = 8 bit UART MOV TMOD, #00100001B ;Sets Timer1 to 8 bit auto reload MOV TCON, #01000000B ;Turns Timer1 on RET ;

Вам также может понравиться