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

📄 ledv2.asm

📁 pic系列单片机得控制程序 主要进行温度采集和转换控制
💻 ASM
字号:

	include <p16F877.inc>

;		2002-05-05
;端口定义
; PORTA	0	Battery Suppy Sense analog in (V=1/3Vbatt)
; PORTA	1	Temperature Sense analog in
; PORTA	2	Pad (spare)
; PORTA	3	
; PORTA	4	
;
; PORTB	0	User input button S1
; PORTB	1	
; PORTB	2	
; PORTB	3	RESERVED - Low Voltage Program
; PORTB	4	User input button S2
; PORTB	5	
; PORTB	6	RESERVED - Program Clk
; PORTB	7	RESERVED - Program Data
;
; PORTC 0	LED1 (Red)
; PORTC 1	LED2 (Yel)
; PORTC 2	LED3 (Grn)
; PORTC 3	LED4 (Red)
; PORTC 4	
; PORTC 5	
; PORTC 6	
; PORTC 7	

; PORTD 0	LCD Data DB4	
; PORTD 1	LCD Data DB5	
; PORTD 2	LCD Data DB6	
; PORTD 3	LCD Data DB7	
; PORTD 4	LCD Backlight (H=On)	
; PORTD 5	LCD Data E	
; PORTD 6	LCD Data R/W (L=Write)	
; PORTD 7	LCD Data RS	

; PORTE 0
; PORTE 1
; PORTE 2	

; Memory Declarations	
	cblock	0x20	; Start of general purpose memory

	; *** add variable names here ***
	RUNNING
	W_TEMP
	STATUS_TEMP
	PCLATH_TEMP
	LEDS
	COUNT
	MODE
	LEDS2
	endc

	ORG 0x000
Start:
	goto	Init	; Execute code

	ORG 0x004
Interrupt:
	goto	Init	; Ignore interrupts

Init:
	BANKSEL	TRISA
	movlw	b'11111111'
	movwf	TRISA	

	BANKSEL	TRISB
	movlw	b'11111111'	; All inputs including user buttons
	movwf	TRISB	

	BANKSEL	TRISC
	movlw	b'11110000'	; LED lines as outputs
	movwf	TRISC	

	BANKSEL	TRISD
	movlw	b'00000000'	; LCD lines all are outputs
	movwf	TRISD	

	BANKSEL	OPTION_REG	
	movlw	b'00000111'	; 0=PortB weak<7>,(Intedg<6>),(T0CS<5>),(T0SE<4>),(PSA<3>)256<210>
	movwf	OPTION_REG	 

	BANKSEL	0		; Normal bank again

	; *** put your code here ***
	
	;example:
	call 	LCD_Init
	movlw	TITLE2
	call	LCD_PrintString
	call	LCD_NewLine
	clrf	COUNT
	clrf	MODE
	movlw	.255
	movwf	RUNNING
	movlw	b'10001000'
	movwf	LEDS

Main:	
	; Turn on the LEDS one at a time.
	rlf 	LEDS,F
	movf 	LEDS,W
	movwf	PORTC	

	; Check Count
	call	CheckCOUNT

	; Check the Mode
	goto	CheckMode
	
	; Repeat.
	goto 	Main

CheckButton:
	;Check start/stop button
	btfss 	PORTB,4
	call 	Stop

	; Check for Clear button
	btfss 	PORTB,0
	call 	Reset
	return

CheckCOUNT:
	call Save
	
	; Must win 3 times to goto the next mode.
	movlw	.3

	; Subtract 3 from COUNT
	subwf	COUNT,F

	; Test for the zero flag
	btfsc	STATUS,Z

	; If the count is reached then goto the next mode.
	call	SetMode
	
	; Other wise return.
	call Restore
	return

SetMode:
	call	Restore
	incf	MODE,F
	return	
Restore:
	movf	PCLATH_TEMP,W
	movwf	PCLATH
	swapf	STATUS_TEMP,W
	movwf	STATUS
	swapf	W_TEMP,F
	swapf	W_TEMP,W
	return


Save:
	movwf	W_TEMP
	swapf	STATUS,W
	clrf	STATUS
	movwf	STATUS_TEMP
	movf	PCLATH,W
	movwf	PCLATH_TEMP
	clrf	PCLATH
	return

CheckMode:
	call	Save
	; Move 2 into w.
	movlw	.2

	; Subtract MODE from 2.
	subwf	MODE,W

	; Test for the zero flag.
	btfsc	STATUS,Z

	; If the MODE is 2 then go into Normal difficultly.
	goto	NormalMode

	; Check to see if we carried.
	btfsc	STATUS,C

	; If we carried then go into Hard difficultly.
	goto	HardMode

	; If we didnt then go into Easy difficultly.
	goto	EasyMode

EasyMode:
	
	call	Delay1sec
	call	Restore
	goto	Main

NormalMode:
	
	call	Delay100ms
	call	Delay100ms
	call	Delay100ms
	call	Delay100ms
	call	Restore
	goto	Main
HardMode:
	
	call	Delay100ms
	call	Delay100ms
	call	Restore
	goto	Main

Stop:
	; Stop Running.
	clrf 	RUNNING
	; See if we won or lost.
	call 	Check
	;clrf 	LEDS
	;movf 	LEDS,W
	;movwf 	PORTC
	return

Reset:
	; Start running.
	movlw	.255
	movwf	RUNNING
	; Get rid of won/lost msg.
	call 	LCD_NewLine
	movlw 	SPCE
	call	LCD_PrintString
	; Start LEDS again.
	movlw	b'10001000'
	movwf	LEDS
	movwf	PORTC
	goto	Main

Check:
	; Test for the green light on.
	btfss 	PORTC,2
	; If its off then you lost.
	goto 	Loose
	; If its on then you won.
	goto 	Win
	return

Win:
	; If we won keep track.
	incf	COUNT,F
	; Show winning msg.
	call	LCD_NewLine
	movlw 	WINN
	call	LCD_PrintString
	; Flash green led.
	movlw	b'00000100'	
	movwf	PORTC	
	call	Delay100ms	
	clrf	PORTC	
	call 	Delay100ms
	; Check for reset button.
	btfsc	PORTB,0
	goto	Win
	return
	
Loose:
	; You must win 3 times in A ROW to get to the next mode.
	clrf	COUNT
	; Show loosing msg.
	call	LCD_NewLine
	movlw 	LOSS
	call	LCD_PrintString
	; Flash both red leds.
	movlw	b'00001001'	
	movwf	PORTC	
	call	Delay100ms	
	clrf	PORTC	
	call 	Delay100ms
	; Check for reset button.
	btfsc	PORTB,0
	goto	Loose	
	return


#include "delays.asm"
#include "lcd.asm"

;-----------#LCD Messages--------------
	org 0x300
DPrintString:
	ADDWF	PCL, F
Ttop:				; Top of table

TMSG1	DT	"You Loose!",0
TMSG2	DT	"You Win!  ",0
TMSG3	DT	"Catch the Green:",0
TMSG4	DT	"XXXXXXXXXXXXXXXX",0
TMSG5	DT	"          ",0

LOSS	EQU	TMSG1 - Ttop
WINN	EQU	TMSG2 - Ttop
TITLE2	EQU	TMSG3 - Ttop
XXXX	EQU	TMSG4 - Ttop
SPCE	EQU	TMSG5 - Ttop


;END OF PROGRAM
	END

⌨️ 快捷键说明

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