Thu May 23, 2013 1:13 am
1ist p = 16f877
include <p16f877.inc>
BANK0 macro
bcf STATUS,RP0
bcf STATUS, RP1
endm
BANK1 macro
bsf STATUS,RP0
bcf STATUS,RP1
endm
BANK2 macro
bcf STATUS,RP0
bsf STATUS,RP1
endm
BANK3 macro
bsf STATUS,RP0
bsf STATUS,RP1
endm
OFF EQU 0 ;MOTOR OFF
COMP EQU 4
SET_PT EQU 0x90 ;TEMP SET POINT
COUNTER EQU 0x20
RESULT EQU 0x21
MASK EQU 0x22
DELAY_TIME EQU 0x23
DELAY_LO EQU 0x24
DELAY_HI EQU 0x25
DELAY_VHI EQU 0x26
TEMP EQU 0x27
;************
ORG 0
NOP
GOTO START
;****************
;MAIN ROUTINE
ORG 0x20
START CALL INITP ;INITIALISE PORT
MOVLW 0xFF ;SET MOToR OFF & HEATRT ON
MOVWF PORTE ;AND oUTPUT
MOVWF PORTA
AGAIN CALL SAR_ADC ; READ TEMP vIA ADC
MOVLW SET_PT ;GET SET POINT
SUBWF RESULT,W ;TEST FOR SET POINT
BTFSC STATUS,C ;
GOTO MOTOR_ON ;IF HIGH TEMP, MoToR oN
GOTO MOTOR_OFF ;ELSE MOTOR OFF
MOTOR_ON
BSF PORTE,0 ;SET MOToR CW
MOVLW 0 ;SET MoToR CW
MOVWF PORTA ;AND oUTPUT
GOTO AGAIN
MOTOR_OFF
MOVLW 0xFF ;SET MOToR OFF
MOVWF PORTA
MOVWF PORTE
CALL OFF_DELAY ;ALLoW aETTLING TIME
GOTO AGAIN ;DO FOR EvER
;*************OFF DELAY ROQTIN
OFF_DELAY
MOVLW 0XE0
MOVWF DELAY_LO
MOVLW 0XA1
MOVWF DELAY_HI
MOVLW 0xFF
MOVWF DELAY_VHI
BIG
OUTER
INNER
INCFSZ DELAY_LO,1
GOTO INNER
INCFSZ DELAY_HI, 1
GOTO OUTER
INCFSZ DELAY_VHI
GOTO INNER
RETURN
; ***PoRT INITIALISATIoN
INITP BANK1 ;SET To BANK 1
MOVLW 06 ;MAKE PORT A DIGITAL
MOVWF ADCON1
BCF TRISA,5 ;MAKE BIT 5 oUTPUT
CLRF TRISE ;SET PORT E TO OUTPUT
BSF TRISA,4 ;AND BIT A4 TO INPUT
CLRF TRISD
BANK0
RETURN
;SAR ROUIINE
SAR_ADC MOVLW 8 ;CoUNTER = 0
MOVWF COUNTER
MOVLW 0x80 ;SET MASK
MOVWF MASK
MOVWF RESULT ;SET INIT RESULT
NEXT MOVF RESULT,W ;GET CURRENT RESULT VALUE
IORWF MASK,W ;SET NEXT MSB
MOVWF PORTD ;AND OUTPUT
CALL DELAY ;ALLDW TIME TO SETTLE
BTFSS PORTA,COMP ;TEST COMP OUTPUT
CALL SETBIT ;IF SET, CALL SETBIT
BTFSC PORTA,COMP ;TEST COMP BIT
CALL CLEARBIT ;ELSE CLEAR BIT
BCF STATUS,C ;CLEAR CARRY FLAG
RRF MASK ;SET NEXT MSB
MOVLW 1 ;SET DECREMENT
SUBWF COUNTER ;AND DECREMENT
BTFSS STATUS,Z ;TEST FOR LAST BIT
GOTO NEXT ;AND Do NEXT BIT IF NOT
RETURN
; SET CURRENT BIT
SETBIT MOVWF RESULT ;STORE RESULT
REIURN
; CLEAR BIT
CLEARBIT
COMF MASK, W ; GET CURRENT MASK AND INvERT
ANDWF RESULT ;AND DLEAR CURRENT
RETURN
;******
; DELAY ROUTIN
DELAY MOVWF TEMP ;SAVE W
MOVLW 0x80 ;SET DELAy TIME
MOVWF DELAY_TIME
WAIT INCFSZ DELAY_TIME ;COtJNT DOWN
GOTO WAIT
MOVF TEMP,W ;-RE5TORE W
RETURN
END
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.