;Program function: Power on: PIN5 is high level, the green light is on; PIN2, PIN3 are low level, the red light is off;
; Alternately detect PIN6, PIN7 pin level, undervoltage 3.9V, 10V, red light on, green light off, overvoltage 5.9V, 15.9V
; Red light on, green light off, alram is TTL high level, overvoltage lock
LIST P=12F675
INCLUDE __CONFIG(B'11000101110100') ;Highest band gap voltage,0,0,Data memory is not protected ;Program memory is code-protected,BOD enabled,MCLR pin is MCLR function ;PWRT enabled,WDT disabled,INTOSC oscillator ;************************************** READH EQU 2Ah; read the high 2 bits of data READL EQU 2Bh ; read the lower 8 bits of data SOUH EQU 40h; Undervoltage setting, high 2 bits storage address SOU EQU 41h ; Undervoltage setting, lower 8 bits storage address RLTH EQU 42h ; Overvoltage setting, high 2 bits storage address RLT EQU 43h ; Overvoltage setting, lower 8 bits storage address ORG 0000H GOTO MAIN ORG 0004H GOTO ADBEGIN ORG 0030H MAIN BCF STATUS,RP0;BANK 0 CLRF GPIO MOVLW 07H MOVWF CMCON ; turn off the comparator BSF STATUS,RP0;BANK 1 CALL 3FFH ; Read the internal oscillator factory calibration word, the return value is in the W register MOVWF OSCCAL ; Calibrate crystal oscillator MOVLW B'00001011';TRISIO tri-state controller MOVWF TRISIO ; Set TRISIO direction controller, GP0, GP1, GP3 as input port MOVLW B'00010011' MOVWF ANSEL; 8-frequency crystal oscillator, AN0AN1 is analog port, AN2AN3 is digital port BANKSEL OPTION_REG MOVLW B'00000000'; Assign the prescaler to the TIMER0 module, divide by 2 MOVWF OPTION_REG ; BANKSEL INTCON MOVLW B'10100000'; Enable global interrupts, disable peripheral interrupts, enable TRMO interrupts, disable GP2/INT external interrupts MOVWF INTCON ; Disable GPIO port level change interrupt, TMR0 register does not overflow, GP2/INT interrupt does not occur ;GP5:GP0 pin level has not changed MOVLW 02H MOVWF 24H ;AD channel setting selection MOVLW D'10' MOVWF 25H; Delay sampling after overvoltage, 10*90uS=900uS ;******************************************** ; Undervoltage setting 2.5V, 5V corresponding value 3.8V, 15V corresponding value 10V MOVLW 0002H MOVWF SOUH MOVLW 0000H MOVWF SOU ;**************************************************** ;Overvoltage setting value 3.9V, 5V path corresponding value 5.9V, 15V path corresponding value 15.9V MOVLW 0003H MOVWF RLTH MOVLW 0020H MOVWF RLT MOVLW B'10000001' MOVWF ADCON0 ;right alignment, reference voltage Vdd, analog channel 0 BANKSEL TMR0 MOVLW D'242' MOVWF TMR0 GOTO $ ;**************************************************** ; Start AD conversion after timing interrupt ADBEGIN BTFSC INTCON,T0IF ; Is it timer TMR0 interrupt? BANKSEL ADCON0 BSF ADCON0,GO ; Start conversion ADWAIT BTFSC ADCON0,GO GOTO ADWAIT ; Wait for conversion to complete ;************************************************** ;Data judgment and processing after AD conversion READ BANKSEL ADRESH ; Automatically set the storage address bank MOVF ADRESH,W; read the voltage value high 2 bits, CLRF STATUS MOVWF READH ; put the high 2 bits of data read into the vrevh register BANKSEL ADRESL; Automatically set the storage address bank MOVF ADRESL,w ; read voltage low 8 bits CLRF STATUS MOVWF READL ;************************************************************ LOWPOWER MOVF SOU,W SUBWF READL,W BTFSS STATUS, C; No borrow, skip GOTO JUMP1 MOVF SOUH,W CONTIUE1 SUBWF READH,W BTFSS STATUS, C ; No borrow, skip GOTO ALARM0 OVERPOWER MOVF RLT,W SUBWF READL,W BTFSS STATUS, C ; No borrow, skip GOTO JUMP2 MOVF RLTH,W CONTIUE2 SUBWF READH,W BTFSS STATUS,C ;;No borrow, skip GOTO NORMAL GOTO ALARM1 ;************************************************ ; Time is up, prepare to select channel and assign value LOOP DECFSZ 24H,F GOTO SKIP BANKSEL ADCON0 MOVLW B'10000001' MOVWF ADCON0 ;right alignment, reference voltage Vdd, analog channel 0 MOVLW D'2' MOVWF 24H GOON BCF INTCON, T0IF; Restore timer to continue judgment BANKSEL INTCON BSF INTCON,7 BANKSEL TMR0 MOVLW D'242' ADDWF TMR0,F GOTO $ ;******************************************************* ;Subroutines SKIP BANKSEL ADCON0 MOVLW B'10000101' MOVWF ADCON0 ;right alignment, reference voltage Vdd, analog channel 0 GOTO GOON JUMP1 INCFSZ SOUH,W GOTO CONTIUE1 JUMP2 INCFSZ RLTH,W GOTO CONTIUE2 NORMAL BANKSEL GPIO BTFSC 22H,0 ; skip if 0 GOTO BACK BSF GPIO,2 ;Green light on BCF GPIO,4; Red light off BACK BCF 22H,0 GOTO LOOP ALARM0 BSF 22H,0 BANKSEL GPIO BCF GPIO,2 ;Green light off BSF GPIO,4 ;Red light on GOTO LOOP ALARM1 DECFSZ 25H,F ; Jump if it is 0 GOTO LOOP BANKSEL GPIO BSF GPIO,5 ; Shutdown BCF GPIO,2 ;Red light on BSF GPIO,4 ;Green light off GOTO $ END
Previous article:PIC16F873A MCU Illuminance Measurement Project Schematic and Source Code
Next article:PIC microcontroller 16*64 dot matrix screen proteus simulation
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- [MPS Mall Big Discount Experience Season] Unboxing
- [New Product Release] | Intelligent Driving Data Post-Processing Analysis Tool—INTEWORK-VDA
- I'm new to power supplies, some power chips have multiple output SWs, how do I connect them?
- Homemade super mini writing robot (including schematics, PCB, firmware code, mechanical drawings)
- Using a fuel gauge chip to achieve fast and intelligent charging of dual-series lithium batteries
- FAQ_How to solve the problem of drastic jumps in the ADC sampling of BlueNRG-12
- Matrix keyboard program problem
- [GD32L233C-START Review] (4) LPTIMER wake-up trigger ADC in Sleep low power mode
- DSP Math Library - TMS320C55x DSP Library
- Qorvo helps Murata launch small UWB module to enable low-power IoT devices