Total members 11663 |It is currently Sat Sep 23, 2017 2:52 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





TEMPERATURE AND HEAT CONTROL , switch motor on and off based on that, such as controlling the fan,
Code:

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
,;TEST FOR SET POINT
BTFSC STATUS
,;
GOTO MOTOR_ON ;IF HIGH TEMPMoToR oN
GOTO MOTOR_OFF 
;ELSE MOTOR OFF

MOTOR_ON
BSF PORTE
,;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
,;MAKE BIT 5 oUTPUT
CLRF TRISE 
;SET PORT E TO OUTPUT
BSF TRISA
,;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
,;GET CURRENT RESULT VALUE
IORWF MASK
,;SET NEXT MSB
MOVWF PORTD 
;AND OUTPUT
CALL DELAY 
;ALLDW TIME TO SETTLE
BTFSS PORTA
,COMP ;TEST COMP OUTPUT
CALL SETBIT 
;IF SETCALL SETBIT
BTFSC PORTA
,COMP ;TEST COMP BIT
CALL CLEARBIT 
;ELSE CLEAR BIT
BCF STATUS
,;CLEAR CARRY FLAG
RRF MASK 
;SET NEXT MSB
MOVLW 1 
;SET DECREMENT
SUBWF COUNTER 
;AND DECREMENT
BTFSS STATUS
,;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
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
,;-RE5TORE W
RETURN
END





Author:
Mastermind
User avatar Posts: 2707
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : TEMPERATURE AND HEAT CONTROL Assembly
 Control Directives usage PIC assembly     -  
 Motor DC Speed Control by switching ON and OFF Assembly     -  
 Infra Read Sensor to Control DC motor Assembly     -  
 temperature transformer between different types     -  
 PIC Assembly For Loop Example     -  
 macro usage PIC assembly     -  
 multiply two numbers in PIC assembly     -  
 MULTIPLEXING Seven SEGMENT DECODER Assembly     -  
 Elements of Assembly Language Instruction     -  
 playfair cipher assembly code     -  



cron






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team