PIC12F675 two-channel AD conversion assembly program

Publisher:自由思想Latest update time:2019-11-12 Source: 51heiKeywords:PIC12F675 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

;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


Keywords:PIC12F675 Reference address:PIC12F675 two-channel AD conversion assembly program

Previous article:PIC16F873A MCU Illuminance Measurement Project Schematic and Source Code
Next article:PIC microcontroller 16*64 dot matrix screen proteus simulation

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号