微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 温度LTC1392 with PIC16C84单片机

温度LTC1392 with PIC16C84单片机

时间:03-08 来源:互联网 点击:

The DAT_HI variable consists of the hgighest two bits and DAT_LO of the low eight bits.

In the program, the raw measurement data is then displayed on a serial LCD. However, it is important to note that this data might be saved in a serial EEPROM for later retrieval and downloading to a PC.

Unlike the program for the Basic Stamp, this program does not include any calculations on the raw data. Another discussion offers that in many instances, calculation is not necessary nor necessarily desireable. But, if it is thoughts are offered on how the calculations may be done with simple byte by byte multiplcation, two byte add and subtracts and BCD conversion routines. These are implemented in other discussions.

One point of interest is the use of a two byte shift in the RX_DATA_10 routine which fetches the 10-bit result from the LTC1392.

DAT_HI and DAT_LO are both initialized to zero and the following loop is executed ten times.

BTFSS PORTB, RX_D
BCF STATUS, C ; set CY to either a 0 or 1
BTFSC PORTB, RX_D
BSF STATUS, C
RLF DAT_L, F ; do a two byte left shift
RLF DAT_H, F

Note that the carry bit is either set to a zero or one, depending on the state of the RX_D input bit. This is then left shifted into DAT_LO. Note that the most significant bit of DAT_LO is now in the carry bit. This is then left shifted into DAT_HI, such that it is now the least significant bit in DAT_HI.


; LTC1392.ASM
;
; 16C84 LTC1392
;
; PORTB.3 (term 9) --RX_D------------ D_OUT (term 2)
; PORTB.2 (term 8) ---TX_D-----------> D_IN (term 1)
; PORTB.1 (term 7) ---CLK------------> CLK (term 3)
; PORTB.0 (term 6) ---C_S------------> C_S (term 4)
;
; copyright, Towanda Malone, Morgan State Univ, August 5, '97

LIST p=16c84
#include c:\mplab\p16c84.inc>
__CONFIG 11h

CONSTANT RX_D = 3 ; bits defined on PortB
CONSTANT TX_D = 2
CONSTANT CLK = 1
CONSTANT C_S = 0

CONSTANT DATA_BUFF = 18H

CONSTANT BASE_VAR = 0CH

MODE EQU BASE_VAR+0 ; mode = 0, 1, 2, or 3

TEMP EQU BASE_VAR+1 ; scratchpad
NUM EQU BASE_VAR+2 ; index

DELAY_LOOP EQU BASE_VAR+3 ; timing

DAT_H EQU BASE_VAR+4 ; 10-bit quantity fetched from ltc1392
DAT_L EQU BASE_VAR+5

ORG 000H

CLRF PORTB
BSF STATUS, RP0
BSF TRISB, RX_D ; input
BCF TRISB, TX_D ; TX_D, CLK and C_S are outputs
BCF TRISB, CLK
BCF TRISB, C_S
BCF STATUS, RP0

MAIN:
MOVLW DATA_BUFF ; pointer to beginning of data_buff
MOVWF FSR

MOVLW .0
MOVWF MODE

MAIN_1: CALL MAKE_MEAS ; make a measurment

MOVF DAT_H, W ; and save two bytes in data_buff
MOVWF INDF

INCF FSR, F
MOVF DAT_L, W
MOVWF INDF
INCF FSR, F

INCF MODE, F ; go through mode 0. 1, 2, 3
MOVLW .4
SUBWF MODE, W
BTFSS STATUS, Z
GOTO MAIN_1

CALL DISPLAY ; display content of data_buff
MAIN_2:
GOTO MAIN_2


MAKE_MEAS: ; performs a measurment in specified mode
; result is returned in DAT_HI and DAT_LO
CALL C_SEL_HI
CALL CLK_HI
CALL C_SEL_LO ; bring /CS low
CALL TX_DATA_4 ; send 4-bit command
CALL RX_DATA_10 ; fetch 10-bit result
CALL C_SEL_HI
RETURN

DISPLAY: ; display content of data_buff on serial LCD
CALL LCD_CLR

MOVLW DATA_BUFF ; initialize pointer to data_buff
MOVWF FSR

MOVLW .4
MOVWF NUM

DISPLAY_1:
MOVF INDF, W ; fetch byte and display on serial LCD
CALL LCD_VAL
INCF FSR, F
MOVF INDF, W
CALL LCD_VAL
INCF FSR, F

MOVLW " " ; separate with a space
CALL LCD_CHAR

DECFSZ NUM, F
GOTO DISPLAY_1
RETURN

TX_DATA_4: ; send 4-bit command to ltc1392
BCF STATUS, C
RLF MODE, W ; 09H | (mode 1)
IORLW 09H

MOVWF TEMP ; save to scratch pad

MOVLW .4 ; 4 bits
MOVWF NUM

TX_DATA_4_1:
BTFSS TEMP, 3 ; most significant bit first
BCF PORTB, TX_D ; set up TX_D
BTFSC TEMP, 3
BSF PORTB, TX_D

CALL CLK_LO ; and then negative going clock pulse
CALL CLK_HI

RLF TEMP, F ; next bit to bit 3 position

DECFSZ NUM, F
GOTO TX_DATA_4_1
RETURN

RX_DATA_10: ; f

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top