⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.asm

📁 8051 ASM source code for MLX90614 tempture sensor
💻 ASM
字号:
;**********************************************************************************************
;							BASIC INFORMATION ABOUT THIS PROGRAM
;**********************************************************************************************
;File name:		main.asm
;Data:			Nov/2007
;Version:		02.00
;Company:		Melexis-Bulgaria(www.melexis.com)
;Description:	Simple IR temperature reader with MLX90614 and PIC10 MCU
;				Data is read through SMBus and is sending by a software UART
;Author:		Dimo Petkov, dpv@melexis.com
;**********************************************************************************************
;						DEFINE MCU TYPE AND INCLUDE HEADER FILES
;**********************************************************************************************

;Undefine if PIC10F202 is used
;#define PIC10F202

;Undefine if SLEEP function is used
;#define SLEEPON

			ifndef  PIC10F202
					LIST 		p=10F206
					#include	<p10F206.inc>
			else
					LIST 		p=10F202
					#include	<p10F202.inc>
			endif	
;**********************************************************************************************
;							CONFIGURATION BITS
;**********************************************************************************************
	
	ifdef	SLEEPON
			__CONFIG _WDT_ON & _MCLRE_OFF
	else
			__CONFIG _WDT_OFF & _MCLRE_OFF	
	endif
;**********************************************************************************************
;						    GPRs AND CONSTANTs DEFINITIONS
;**********************************************************************************************
		
		CBLOCK	0x08
		 Nack_Counter
		 WDTcounter
		 TX_buffer
		 TX_temp
		 Bit_counter
		 flagreg0
		 RX_buffer
		 counterL
		 counterH
		 counterU
		 SlaveAddress
		 command
		 DataL
		 DataH
		 PecReg
		 tx_0
		 tx_1
		 digit1
		 digit2
		ENDC
		
;constants
#define TBUF		d'2'	; Define delays(see SMBusSubr.asm)
#define	BAUDRATE	d'2'	; 57600@Fosc=4MHz
#define SLEEP_		0xFF	; Define SLEEP command
#define PECconst	0xF3	; Define PEC constant
#define WDTCOUNT    d'22'	; Approximately 1min time out 

;SMBus control signals
#define _SCL    GPIO,1
#define _SDA    GPIO,0		

;Flag register definitions
#define bit_out		flagreg0,0
#define bit_in		flagreg0,1
#define Sleep_flag	flagreg0,2
;
#define  RAM_Access    0x00	; Define the MLX90614 command RAM_Accsess
#define  Ta		 	   0x06 ; Define Ta  address in RAM
#define  To1	   	   0x07	; Define To1 address in RAM
#define  To2		   0x08	; Define To2 address in RAM 
#define  SA    		   0x00	; Define SMBus device address

;**********************************************************************************************
;											MACROS
;**********************************************************************************************
LoadNACKcounter MACRO
	  			MOVLW	D'0'
	  			MOVWF	Nack_Counter 			
	  			ENDM
;----------------------------------------------------------------------------------------------	
_SDA_HIGH		macro
				MOVLW	B'00001001'
				TRIS	6				; _SDA(GP0)-input,GP1,GP2 -outputs			
				endm
;----------------------------------------------------------------------------------------------
_SCL_HIGH		macro
				BSF		_SCL			; Set _SCL line
				endm
;----------------------------------------------------------------------------------------------
_SDA_LOW		macro
				BCF		_SDA			; Clear _SDA bit
				MOVLW	B'00001000'
				TRIS	6				; _SDA(GP0)-output,GP1,GP2 -outputs
				endm
;----------------------------------------------------------------------------------------------
_SCL_LOW		macro
				BCF		_SCL			; Clear _SCL line
				endm
;----------------------------------------------------------------------------------------------
EnterSleepMode  macro
				local	restart
				local   end_transmition
				local	start
				
restart
				DECFSZ	Nack_Counter,F		; If((Nack_Counter-1) == 0) stop transmition
				GOTO	start				; Else start transmition
				GOTO	end_transmition
start		
				CALL	STOP_bit			; Stop SMBus comunication
				CALL	START_bit			; Start SMBus comunication
				
				MOVF	SlaveAddress,W		;
				CALL	TX_byte				; Send Slave address(Bit R/-W no meaning)
				
				ANDLW	0x01				; W & 0x01 -> W
				BTFSS	STATUS,Z			; If Slave acknowledge,continue 
				GOTO	restart				; Else restart communication 

				MOVLW	SLEEP_				;
				CALL	TX_byte				; Send Command
				
				ANDLW	0x01				; W & 0x01 -> W
				BTFSS	STATUS,Z			; If Slave acknowledge,continue 
				GOTO	restart				; else restart communication
				
				BSF		Sleep_flag
				MOVLW	PECconst			;
				CALL	TX_byte				; Send PEC
				BSF		Sleep_flag
				
				ANDLW	0x01				; W & 0x01 -> W
				BTFSS	STATUS,Z			; If Slave acknowledge,continue 
				GOTO	restart				; Else restart communication
end_transmition	
				CALL	STOP_bit			; Stop SMBus comunication
				_SCL_LOW					; Clear _SCL line
				endm
;----------------------------------------------------------------------------------------------
ExitSleepMode	macro
	
				_SCL_HIGH						; Set _SCL line
				NOP								;|
				NOP								; > Wait 3us
				NOP								;|
				_SDA_LOW						; Clear _SDA line 
				CALL	delay_30ms				; Wait 30ms
				CALL	delay_30ms				; Wait 30ms
				CALL	delay_30ms				; Wait 30ms
				_SDA_HIGH					    ; Set _SDA line
	
				endm
;----------------------------------------------------------------------------------------------
DummyCommand macro
			 CALL	START_bit				; Start SMBus comunication
			 MOVF	SlaveAddress,W			; SlaveAddress -> W
			 CALL	TX_byte					; Send Slave address(Bit R/-W no meaning)
			 CALL	STOP_bit				; Stop SMBus comunication
			 endm
;----------------------------------------------------------------------------------------------
MemRead	macro	
		local	restart
		local   end_transmition
		local	start
restart
		DECFSZ	Nack_Counter,F		; If((Nack_Counter-1) == 0) stop transmition
		GOTO	start				; Else start transmition
		GOTO	end_transmition		;
start		
		CALL	STOP_bit			; Stop SMBus comunication
		CALL	START_bit			; Start SMBus comunication
	
		MOVF	SlaveAddress,W		; Send Slave address(Bit R/-W no meaning)
		CALL	TX_byte				;

		ANDLW	0x01				; W & 0x01 -> W
		BTFSS	STATUS,Z			; If Slave acknowledge,continue 
		GOTO	restart				; Else restart communication 

		MOVF	command,W			; Send Command
		CALL	TX_byte				;
		
		ANDLW	0x01				; W & 0x01 -> W
		BTFSS	STATUS,Z			; If Slave acknowledge,continue 
		GOTO	restart				; else restart communication 
		
		CALL	START_bit			; Send Repeated START bit
		
		MOVF	SlaveAddress,W		; Send Slave address again(Bit R/-W no meaning)
		CALL	TX_byte				;
		
		ANDLW	0x01				; W & 0x01 -> W
		BTFSS	STATUS,Z			; If Slave acknowledge,continue 
		GOTO	restart				; Else restart communication 
		
		BCF		bit_out				; Master must send acknowledge after this received byte
		CALL	RX_byte				; Receive low data byte
		MOVF	RX_buffer,W			;
		MOVWF	DataL				; Save it in DataL
		
		BCF		bit_out				; Master must send acknowledge after this received byte
		CALL	RX_byte				; Receive high data byte
		MOVF	RX_buffer,W			;
		MOVWF	DataH				; Save it in DataH
		
		BSF		bit_out				; Master mustn't send acknowledge after this received byte
		CALL	RX_byte				; Receive PEC byte
		MOVF	RX_buffer,W			;
		MOVWF	PecReg				; Save it in PecReg
end_transmition		
		CALL	STOP_bit			; Stop SMBus comunication
	
		endm
					
;**********************************************************************************************
;							   	BEGINNING OF THE PROGRAM
;**********************************************************************************************

			ORG	 	0x0000
			MOVWF	OSCCAL	 	;Load OSCCAL with the calibration value
			GOTO	main
							
;**********************************************************************************************
;									SUBROUTINES 		
;**********************************************************************************************
#include "Init.asm"
#include "SMBusSubr.asm"
#include "delay.asm"
#include "uart.asm"
#include "hex2asc.asm"
#include "SendRequest.asm"


;************************************************************************************************************
;			                     MAIN PROGRAM
;************************************************************************************************************
;Name:     	main
;Function: 	Read Ta ,To1 and To2 consequently by a MLX90614 module
;Input:
;Output:
;Comments:	
;			If is defined SLEEPON data is read during one minute approximately (TWDT * WDTCOUNT).
;			TWDT = 2.3s - WDT time-out period (Prescaler 1:128 is used)
;			WDTCOUNT 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -