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

📄 f74 adc.asm

📁 PIC16F74 AD 功能实现 详细程序 可直接应用
💻 ASM
字号:
;**********************************************************************
;   This file is the code for a remote thermostat unit.               *
;	The thermostat uses an off-chip temperature sensing IC.  The  *                                                      
;   temperature is read via the A/D converter, calculated, then sent  *
;   across the serial bus at 2400 baud through a 433 MHz transmitter  *
;   to the receiver.						      *						  
;								      *								  
;**********************************************************************
;                                                                     *
;    Filename:	    Xmitter.asm                                       *
;    Date:          29 April 2003                                     *
;    File Version:  1.0                                               *
;                                                                     *
;    Author:        G Andrew Hunt                                     *
;    Company:       Cal Poly                                          *
;                                                                     * 
;                                                                     *
;**********************************************************************
;                                                                     *
;    Files required:                                                  *
;                                                                     *
;                                                                     *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Notes:   modified May 23, 2003 AH                                *
;                                                                     *
;                                                                     *
;                                                                     *
;                                                                     *
;**********************************************************************


	list		p=16f74		; list directive to define processor
	#include	<p16f74.inc>	; processor specific variable definitions
	errorlevel  -302              ; suppress message 302 from list file
;HS Oscillator, all others off
	__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_OFF & _HS_OSC



;***** VARIABLE DEFINITIONS
w_temp		EQU	0x20		; variable used for context saving
w_temp1		EQU	0xA0		; reserve bank1 equivalent of w_temp 
status_temp	EQU	0x21		; variable used for context saving
pclath_temp	EQU	0x22		; variable used for context saving
DELAY       EQU	0x23        ; Used in DELAYxxx routines
X_DELAY     EQU	0x24        ; Used in X_DELAYxxx routines
			



;**********************************************************************
	ORG     0x000             ; processor reset vector

	clrf    PCLATH            ; ensure page bits are cleared
  	goto    setup             ; go to setup routines


	ORG     0x004             ; interrupt vector location

setup
	;setup the A/D converter
	bcf		STATUS, RP0			; select bank 0	
	movlw	0x01				; turn on A/D converter, channel 0, FOSC/2
	movwf	ADCON0				; move into ADCON0 register
	bsf		STATUS, RP0			; select bank 1	
	movlw	0x05				; select RA3 for Vref and others as digital I/O
	movwf	ADCON1

	;wait a few seconds for the Receiver to initialize
	call	delay
	call	delay
	call	delay
	call	delay
	call	delay

	; setup port C for RxTx
	bcf		STATUS, RP0			; select bank 0
	clrf	PORTC				; clear Port C
	movlw	0x40				; bit6 high initially for Tx
	movwf	PORTC
	bsf		STATUS, RP0			; select bank 1
	movlw	0x80				; bit 7 input, bit 6 output
	movwf	TRISC				; 
	

	;setup the UART Serial for 2400 baud transmission
	bsf		STATUS, RP0			; select bank 1
	movlw	0x24				; asynch mode, 9 bit, HS baud, Xmit enabled
	iorwf	TXSTA
	bcf		STATUS, RP0			; select bank 0
	movlw	0x0D0				; 9 bit continuous receive, serial port enabled
	iorwf	RCSTA
	bsf		STATUS, RP0			; select bank 1
	movlw	0x19				;set baud rate to 2400 bps (25 decimal)
	movwf	SPBRG

	goto	main	

main

;Start A/D Converter
	bcf		STATUS, RP0			; select bank 0
	movlw	0x04				; turn on A/D Conversion
	iorwf	ADCON0	
	
	;wait for conversion to complete
adwait
	btfss	ADCON0, GO			; if GO is set, skip goto send
	goto	send				; if GO is clear, goto send
	goto	adwait				

send
	movf	ADRES, w			; store result into w
	movwf	TXREG				; write result to Transmit register
	bsf		STATUS, RP0			; select bank 1
swait	
	btfsc	TXSTA, TRMT			; if TSR is empty (TRMT=1), start over
	goto	hangon
	goto	swait
	
hangon
     call delay
    	call	delay
     goto main	

;**********************************************************************
	;Delay subroutine (1/2 second) at 250 KHz OSC/4
	;Courtesy of:
	;http://home.iae.nl/users/pouweha/lcd/lcd2.shtml#PIC_lcd_init

delay
	movlw	0xFA		;delays W*500ms
	goto	X_DELAY500

DELAY500
    MOVLW   D'166'              ; +1        1 cycle
    MOVWF   DELAY               ; +2        1 cycle
DELAY500_LOOP
    DECFSZ  DELAY, F            ; step1     1 cycle
    GOTO    DELAY500_LOOP       ; step2     2 cycles
DELAY500_END
    RETURN                      ; +3        2 cycles


X_DELAY500
    MOVWF   X_DELAY             ; +1        1 cycle
X_DELAY500_LOOP
    CALL    DELAY500            ; step1   
    DECFSZ  X_DELAY, F          ; step2     1 cycle
    GOTO    X_DELAY500_LOOP     ; step3     2 cycles
X_DELAY500_END
    RETURN                      ; +2        2 cycles
;**********************************************************************

	END                       ; directive 'end of program'


⌨️ 快捷键说明

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