📄 p18demo.asm
字号:
movwf TXREG ; carriage return
btfss TXSTA,TRMT ; wait for data TX
bra $-2
btfss select ; exit volt measurement ??
bra menu_buz ; YES
bra volts_again ; NO, do conversion again
;--------------------- BUZZER --------------------------------------
buzzer
btfss select ; wait for RB0 release
bra $-2
movlw 0x80 ; start at these PWM values
movwf PR2 ; initialize PWM period
movlw 0x80
movwf CCPR1L ; initialize PWM duty cycle
call LCDLine_1
movlw .176 ; send "Prd.=128 DC=128" to LCD
movwf ptr_pos
call stan_char_1
call LCDLine_2
movlw .128 ; send "RA4= -> RB0 = ++" to LCD
movwf ptr_pos
call stan_char_2
movlw 0x0F ; turn buzzer on
movwf CCP1CON
pr2_again
btfsc select ; increment PR2 ???
bra pr2_out ; NO
call delay_100ms ; YES
call delay_100ms
incf PR2,F ; increment PR2
pr2_out
movlw 0x85 ; move cursor into position
movwf temp_wr
call i_write
pol1
btfss scroll ; goto increment CCPR1L
bra inc_dc
btfsc select ; wait for RB0 press
bra pol1
movf PR2,W ; send PR2 register to conversion
call bin_bcd
movf MSD,W ; send high digit
movwf temp_wr
call d_write
movf MsD,W ; send middle digit
movwf temp_wr
call d_write
movf LSD,W ; send low digit
movwf temp_wr
call d_write
bra pr2_again
;------------------------
; adjust Duty Cycle
inc_dc
btfss scroll ; wait for button release
bra $-2
inc_ccpr1l
btfsc select ; increment CCPR1L ???
goto ccpr1l_out ; NO
call delay_100ms ; YES
call delay_100ms
incf CCPR1L,F ; increment CCPR1L
ccpr1l_out
movlw 0x8C ; move cursor into position
movwf temp_wr
call i_write
col1
btfss scroll ; exit?
bra pwm_out
btfsc select ; wait for RB0 press
bra col1
movf CCPR1L,W ; send PR2 register to conversion
call bin_bcd
movf MSD,W ; send high digit
movwf temp_wr
call d_write
movf MsD,W ; send middle digit
movwf temp_wr
call d_write
movf LSD,W ; send low digit
movwf temp_wr
call d_write
bra inc_ccpr1l
pwm_out
movlw 0
movwf CCP1CON ; turn buzzer off
bra menu_temp
;---------------------- Temperature --------------------------------
temp
; This code if for the TC74A5-5.0VAT temperature sensor
; 1st. Check if temperature is ready to be read in config reg.
; 2nd. If ready, retireve temperatute in hex.
; If not ready, check config register again.
bsf TRISC,3 ; initialize MSSP module
bsf TRISC,4
movlw B'00101000'
movwf SSPCON1
bsf SSPSTAT,SMP
movlw .5
movwf SSPADD
bcf PIR1,TMR1IF
clrf TMR1H ; load Timer1 for 2 sec overflow
clrf TMR1L
get_temp
movlw 0x01 ; config register command byte
movwf cmd_byte
temp_now
bsf SSPSTAT,6 ; SMBUS spec for TC74
bsf SSPCON2,SEN ; write to TC74
btfsc SSPCON2,SEN
bra $-2
movlw B'10011010' ; send TC74 ADDRESS (write)
movwf SSPBUF
ssprw
btfsc SSPCON2,ACKSTAT ; ack?
bra $-2
movf cmd_byte,W ; send COMMAND byte (config)
movwf SSPBUF
ssprw
btfsc SSPCON2,ACKSTAT ; ack?
bra $-2
bsf SSPCON2,RSEN ; send repeated start
btfsc SSPCON2,RSEN
bra $-2
movlw B'10011011' ; send TC74 ADDRESS (read)
movwf SSPBUF
ssprw ; module idle?
btfsc SSPCON2,ACKSTAT ; ack?
bra $-2
bsf SSPCON2,RCEN ; enable receive mode
btfsc SSPCON2,RCEN
bra $-2
movf SSPBUF,W ; retrieve config reg or temp reg
bsf SSPCON2,ACKDT ; send NOT-ACK
bsf SSPCON2,ACKEN
btfsc SSPCON2,ACKEN
bra $-2
bsf SSPCON2,PEN ; stop
btfsc SSPCON2,PEN
bra $-2
btfss cmd_byte,0 ; config command OR temp command
bra convert_temp ; get temperature ready for display
andlw 0x40 ; is temp ready ??
sublw 0x40
btfss STATUS,Z
bra get_temp
movlw 0x00 ; temp is ready for reading
movwf cmd_byte ; send temp register command
bra temp_now
convert_temp
movwf temperature
call bin_bcd ; get temp ready for LCD
call LCDLine_1
movlw A'T' ; send "Temp=" to LCD
movwf temp_wr
call d_write
movlw A'e'
movwf temp_wr
call d_write
movlw A'm'
movwf temp_wr
call d_write
movlw A'p'
movwf temp_wr
call d_write
movlw 0x20 ; space
movwf temp_wr
call d_write
movlw A'='
movwf temp_wr
call d_write
movlw 0x20 ; space
movwf temp_wr
call d_write
movf MSD,W ; send high digit
movwf temp_wr
call d_write
movf MsD,W ; send middle digit
movwf temp_wr
call d_write
movf LSD,W ; send low digit
movwf temp_wr
call d_write
movlw A'C' ; send "C" for celcius
movwf temp_wr
call d_write
movlw 0x20 ; space
movwf temp_wr
call d_write
movlw 0x20 ; space
movwf temp_wr
call d_write
movlw 0x20 ; space
movwf temp_wr
call d_write
call LCDLine_2 ; send "RB0 = Exit" to LCD
movlw .144
movwf ptr_pos
call stan_char_2
btfss select ; wait for RB0 release
bra $-2
call delay_100ms
btfss select ; exit ?
bra menu_clock ; YES, goto main menu
btfsc PIR1,TMR1IF ; 2 second overflow occur ??
call write_eeprom ; YES
bra get_temp ; NO, get temperature again
;----------------- CLOCK ------------------------------------------
clock
btfss select ; wait for RB0 button release
bra $-2
movlw 0x0F ; intitialize TIMER1
movwf T1CON
clrf seconds
clrf minutes
clrf hours
overflow
bcf PIR1,TMR1IF
movlw 0x80
movwf TMR1H ; load regs for 1 sec overflow
clrf TMR1L
incf seconds,F ; increment seconds
movf seconds,W
sublw .60
btfss STATUS,Z ; increment minutes ?
bra clk_done
incf minutes,F
clrf seconds
movf minutes,W
sublw .60
btfss STATUS,Z ; increment hours ?
bra clk_done
incf hours,F
clrf minutes
movf hours,W
sublw .13
btfss STATUS,Z
bra clk_done
movlw .1 ; start a new 12 hour period
movwf hours
clk_done
movf hours,W ; send hours to LCD
call bin_bcd
call LCDLine_1 ; place time on line 1
movf MsD,W ; send middle digit
movwf temp_wr
call d_write
movf LSD,W ; send low digit
movwf temp_wr
call d_write
movlw 0x3A ; send : colon
movwf temp_wr
call d_write
movf minutes,W ; send minutes to LCD
call bin_bcd
movf MsD,W ; send middle digit
movwf temp_wr
call d_write
movf LSD,W ; send low digit
movwf temp_wr
call d_write
movlw 0x3A ; send : colon
movwf temp_wr
call d_write
movf seconds,W ; send seconds to LCD
call bin_bcd
movf MsD,W ; send middle digit
movwf temp_wr
call d_write
movf LSD,W ; send low digit
movwf temp_wr
call d_write
movlw 0x20 ; send 3 spaces after 00:00:00
movwf temp_wr
call d_write
movlw 0x20
movwf temp_wr
call d_write
movlw 0x20
movwf temp_wr
call d_write
movlw .112 ; send "RA4=Dn RB0=Menu" to LCD
movwf ptr_pos
call stan_char_2
btfss scroll ; set time ??
bra set_time
btfss select ; return to main menu ??
bra menu
btfss PIR1,TMR1IF ; has timer1 overflowed ?
bra $-2 ; NO, wait til overflow
bra overflow ; YES
return
; end clock ----------------------------------------------------
;***************************************************************
;***************************************************************
;************************** ROUTINES ***************************
;***************************************************************
;----Standard code, Place characters on line-1------------------
stan_char_1
call LCDLine_1 ; mvoe cursor to line 1
movlw .16 ; 1-full line of LCD
movwf ptr_count
movlw UPPER stan_table
movwf TBLPTRU
movlw HIGH stan_table
movwf TBLPTRH
movlw LOW stan_table
movwf TBLPTRL
movf ptr_pos,W
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -