school

thing1's amazing school repo
Log | Files | Refs | Submodules | README

final.asm (1328B)


      1 start: 
      2 init: 
      3 	clrf    PORTA          	; make sure port A output latches are 
      4 				; low 
      5 	clrf 	PORTB
      6 	bsf     STATUS, RP0    	; select memory bank 1 
      7 
      8 	movlw 	b'11111111'    	; set port A data direction to inputs 
      9 	movwf   TRISA         
     10 	movlw   b'00000000'    	; set port B data direction to outputs 
     11 	movwf   TRISB          
     12 	bcf     STATUS,RP0     	; select memory bank 0 
     13 
     14 	rawtemp EQU B6
     15 	countdown EQU B7
     16 
     17 	goto    main 
     18 
     19 beep:				; a for loop that beeps a buzzer and 
     20 				; turns on a led then sets a led on if 
     21 				; nothing is done
     22 	movlw 	5
     23 	movwf	countdown
     24 
     25 loop1:
     26 	bcf 	PORTB, 3 	; turn off the status
     27 	bsf	PORTB, 0	; put a RED LED on PORTB:0
     28 	bsf	PORTB, 1	; put a BUZZER on PORTB:1
     29 	call 	wait1000ms
     30 	clrf	PORTB
     31 	call	wait1000ms
     32 
     33 	decfsz	countdown, F	; the main part of the loop
     34 	goto	loop1	
     35 	
     36 	bsf	PORTB, 2	; put an AMBER LED on PORTB:2
     37 
     38 	return
     39 
     40 main: 				; reads the temprature
     41 	bsf  	PORTB,3		; put a GREEN LED for status on PORTB:3
     42 
     43 	call 	readadc1 	; put a THERMISTOR on PORTA:1
     44 	movf	B1, W
     45 	movwf	rawtemp
     46 				
     47 	call	readadc0	; put a POT on PORTA:0	
     48 	movf	B0, W
     49 
     50 	subwf	rawtemp, w	; subtract the from the threshold value
     51 	btfss	STATUS, 0 	; if higher than desired temp
     52 	call 	beep	 	
     53 
     54 	clrf 	STATUS		; clears the status flag, which might have a carry bit set
     55 
     56 	goto 	main
     57 
     58 	END		       	; ends the program