完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
程序代码全部如下,在OVP detection处用AN1做AD时,AD出来的结果一直是0XFF,同样的代码,在
OTP detection处用AN0做AD时,结果正常,不知道问题在哪。 LIST p=12F1822 ; #include "P12F1822.INC" ; Include header file __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_ON & _PWRTE_ON & _MCLRE_ON & _CP_ON & _CPD_ON & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF __CONFIG _CONFIG2, (0X1EFF) ;Fsys=4MHz 01101010 ;timer0 interrupt:1ms ;instruction cycle=4/4MHz=1us ;REF=5V ;AD 10bit ;===================bit defination================== ; status bit defination #define TO STATUS,4 #define PD STATUS,3 #define ZE STATUS,2 #define DCF STATUS,1 #define CF STATUS,0 ;================I/O port defination================== #define OFF PORTA,5 #define PFC PORTA,4 #define DELAY PORTA,2 ;==============universial register defination========== DELAY_FLAG EQU 0X21 #define RELAY_FLAG DELAY_FLAG,0 #define PFC_FLAG DELAY_FLAG,1 #define OFF_FLAG DELAY_FLAG,2 STATUS_FLAG EQU 0X22 #define WAKE_UP_FLAG STATUS_FLAG,0 #define SHUT_DOWN_FLAG STATUS_FLAG,1 #define OVP_FLAG STATUS_FLAG,2 #define OTP_1_FLAG STATUS_FLAG,3 #define PTC_FLAG STATUS_FLAG,4 #define UVP_FLAG STATUS_FLAG,5 T0_BUFFER1 EQU 0X24 T0_BUFFER2 EQU 0X25 T0_COUNTER0 EQU 0X26 T0_COUNTER1 EQU 0X27 T0_COUNTER2 EQU 0X28 T0_COUNTER3 EQU 0X29 ADC_OUNTER EQU 0X30 T0_COUNTER4 EQU 0X31 AD_RECYCLE_COUNTER EQU 0X34 AD_COUNTER EQU 0X35 ADC_BUFFER EQU 0X36 AD_BUFFER1 EQU 0X37 AD_BUFFER2 EQU 0X38 AD_VALUEL EQU 0X39 AD_VALUEH EQU 0X40 AD_AVER_VAL EQU 0X41 INPUT_VOLT EQU 0X42 OTP_DET_1 EQU 0X43 AD_LOWBIT EQU 0X46 ;========================================================== ;========================================================== ;========================================================== ORG 0x00 GOTO start_pro ORG 0x04 GOTO MCU_INT ;GOTO 0X06 ;===========================Interrupt program============================== MCU_INT: MOVLB 0X0 MOVWF T0_BUFFER1 SWAPF STATUS,W MOVWF T0_BUFFER2 TIMER1000MS: BTFSS WAKE_UP_FLAG GOTO EXIT_TIMER00 BTFSC RELAY_FLAG GOTO NEXT_1 INCF T0_COUNTER1,F MOVLW 0X14 ;delay 1s SUBWF T0_COUNTER1,W BTFSS CF GOTO EXIT_TIMER00 BSF DELAY BANKSEL LATA BSF LATA,2 MOVLB 0X0 BSF RELAY_FLAG CLRF T0_COUNTER1 NEXT_1: BTFSC PFC_FLAG GOTO NEXT_2 INCF T0_COUNTER2,F MOVLW 0X0A ;delay 500ms SUBWF T0_COUNTER2,W BTFSS CF GOTO EXIT_TIMER00 BCF PFC BANKSEL LATA BCF LATA,4 MOVLB 0X0 BSF PFC_FLAG CLRF T0_COUNTER2 NEXT_2: BTFSC OFF_FLAG GOTO EXIT_TIMER00 INCF T0_COUNTER3,F MOVLW 0X14 ;delay 1s SUBWF T0_COUNTER3,W BTFSS CF GOTO EXIT_TIMER00 BANKSEL LATA BCF LATA,5 BCF LATA,5 BANKSEL PORTA BCF OFF MOVLB 0X0 BSF OFF_FLAG CLRF T0_COUNTER3 EXIT_TIMER00: BCF INTCON,2 ;Clear TMR0 interrupt flag MOVLW 0X3B ; MAKE COMMENDATION MOVWF TMR0 ; 50ms INT_END: SWAPF T0_BUFFER2,W MOVWF STATUS SWAPF T0_BUFFER1,F SWAPF T0_BUFFER1,W RETFIE ;===========================INITIAL SFR======================== start_pro: BANKSEL OSCCON MOVLW B'01101011' MOVWF OSCCON ;Fosc=4MHz internal RC oscillation ;BANKSEL CPSCON0 ;BCF CPSCON0,7 ;BANKSEL CM1CON0 ;BCF CM1CON0,7 ;BANKSEL DACCON0 ;BCF DACCON0,7 ;BANKSEL MDCON ;CLRF MDCON ;BANKSEL SSP1CON1 ;BCF SSP1CON1,5 BANKSEL PORTA CLRF PORTA BANKSEL LATA CLRF LATA BANKSEL ANSELA CLRF ANSELA BANKSEL TRISA MOVLW B'00001011' MOVWF TRISA ;prot A input and output setup BANKSEL WPUA MOVLW 0X00 MOVWF WPUA ;disable weak pull-up BANKSEL IOCAP MOVWF IOCAP ;disable interupt of level of port A jump MOVWF IOCAN MOVLB 0X0 BSF PFC BSF OFF BCF DELAY BANKSEL LATA BSF LATA,5 BSF LATA,4 CLR_BANK0: ;CLEAR RAM MOVLW 0X20 MOVWF FSR1L MOVLW 0X0 MOVWF FSR1H CLR_LOOP1: CLRF INDF1 INCF FSR1L MOVF FSR1L,W XORLW 0X60 BTFSS ZE GOTO CLR_LOOP1 WAKE_UP: BANKSEL OPTION_REG MOVLW B'10000111' MOVWF OPTION_REG ;TIMER0 CLOCK=CLKOUT/4,CLKOUT=FOSC/4 BANKSEL INTCON MOVLW B'10100000' MOVWF INTCON ;OPEN TIMER0 INTERRUPER MOVLW 0X3B MOVWF TMR0 ;1ms intrance interruper BANKSEL WDTCON MOVLW B'00010111' MOVWF WDTCON MOVLW 0X00 MOVWF PIE1 ;disable external interrupt BANKSEL PIR1 MOVLW 0X00 MOVWF PIR1 ;clear external interrupt flag MOVWF PIR2 MOVLB 0X0 CLRF STATUS_FLAG ;======================================================== ;===================main loop============================ MAIN_LOOP: CLRWDT BANKSEL OPTION_REG MOVLW B'10000111' MOVWF OPTION_REG BANKSEL ANSELA CLRF ANSELA BANKSEL TRISA MOVLW B'00001011' MOVWF TRISA ;prot A input and output setup MOVLB 0X0 BSF WAKE_UP_FLAG ;BANKSEL PORTA ; BCF PFC ; BCF LATA,4 MOVLB 0X0 BTFSC OVP_FLAG GOTO OVP_DETECTION BTFSC UVP_FLAG GOTO OVP_DETECTION BTFSC OTP_1_FLAG GOTO OTP_DET ;=============================OVP detection========================= OVP_DETECTION: BANKSEL ADCON0 MOVLW B'00000101' MOVWF ADCON0 ;AD PORT:AN1 BANKSEL ADCON1 MOVLW B'00100000' MOVWF ADCON1 BANKSEL ANSELA MOVLW B'00000010' ;PIN1 as AD port MOVWF ANSELA CALL ADC MOVLB 0X0 ;MOVLW 0X9D ;MOVWF AD_AVER_VAL MOVF AD_AVER_VAL,W MOVWF ADC_BUFFER MOVWF INPUT_VOLT BTFSC OVP_FLAG GOTO OVP_RELEAX MOVLW 0XA7 ;>290V SUBWF INPUT_VOLT,W BTFSS CF GOTO UVP_DETECTION BSF OVP_FLAG GOTO WARNING OVP_RELEAX: MOVLW 0XA0 ;280V SUBWF INPUT_VOLT,W BTFSC CF GOTO WARNING BCF OVP_FLAG BANKSEL LATA BCF LATA,5 BANKSEL PORTA BCF OFF GOTO MAIN_LOOP ;================================UVP detection========================= UVP_DETECTION: BTFSC UVP_FLAG GOTO UVP_85V_RELEAX MOVLW 0X30 ;>80V ? SUBWF INPUT_VOLT,W BTFSS CF GOTO UVP_75V_DET GOTO OTP_DET UVP_75V_DET: MOVLW 0X2D ;<75V SUBWF INPUT_VOLT,W BTFSC CF GOTO OTP_DET BSF UVP_FLAG GOTO WARNING UVP_85V_RELEAX: MOVLW 0X33 ;>85V SUBWF INPUT_VOLT,W BTFSS CF GOTO WARNING BCF UVP_FLAG BSF WAKE_UP_FLAG BANKSEL LATA BCF LATA,5 BANKSEL PORTA BCF OFF GOTO MAIN_LOOP ;================================OTP detection=========================== OTP_DET: BANKSEL ADCON0 MOVLW B'00000001' MOVWF ADCON0 ;AD PORT:AN0 BANKSEL ADCON1 MOVLW B'00100000' MOVWF ADCON1 BANKSEL ANSELA MOVLW B'00000001' ;PIN7 as AD port MOVWF ANSELA CALL ADC MOVLB 0X0 ;MOVLW 0XA0 ;MOVWF AD_AVER_VAL MOVF AD_AVER_VAL,W MOVWF ADC_BUFFER MOVWF OTP_DET_1 BTFSC OTP_1_FLAG GOTO OTP_1_RELEAX MOVLW 0XB1 ;>90℃ SUBWF OTP_DET_1,W BTFSS CF GOTO MAIN_LOOP BSF OTP_1_FLAG GOTO WARNING OTP_1_RELEAX: MOVLW 0X9D ;<80℃ SUBWF OTP_DET_1,W BTFSC CF GOTO WARNING BCF OTP_1_FLAG CLRF DELAY_FLAG GOTO MAIN_LOOP ADC: MOVLB 0X0 MOVLW 0X80 MOVWF AD_RECYCLE_COUNTER MOVLW 0X07 MOVWF AD_COUNTER ;ADC_CONVERT: ADC_LOOP: CALL DELAY_TIME BANKSEL ADCON0 BSF ADCON0,1 ;ADC START NOP NOP BTFSC ADCON0,1 GOTO $-2 BANKSEL ADRESL MOVF ADRESL,W ;LOW 2bit MOVLB 0X0 ADDWF AD_BUFFER1,F BTFSC CF INCF AD_BUFFER2,F BANKSEL ADRESH MOVF ADRESH,W ;high 8bit MOVLB 0X0 ADDWF AD_VALUEL,F BTFSC CF INCF AD_VALUEH,F DECFSZ AD_RECYCLE_COUNTER,F GOTO ADC_LOOP TAKE_AVER: BCF CF RRF AD_VALUEH,F RRF AD_VALUEL,F BCF CF RRF AD_BUFFER2,F RRF AD_BUFFER1,F DECFSZ AD_COUNTER,F GOTO TAKE_AVER MOVF AD_VALUEL,W MOVWF AD_AVER_VAL MOVF AD_BUFFER1,W MOVWF AD_LOWBIT CLRF AD_VALUEL CLRF AD_VALUEH CLRF AD_BUFFER2 CLRF AD_BUFFER1 RETURN DELAY_TIME: MOVLW 0X64 MOVWF T0_COUNTER4 NOP NOP DECFSZ T0_COUNTER4,F GOTO $-2 RETURN WARNING: BANKSEL LATA BSF LATA,5 BANKSEL PORTA BSF OFF GOTO MAIN_LOOP END |
|
相关推荐
2个回答
|
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
求解外围电路实现的是4脚给持续低电平复位并正常工作,高电平不工作的原因
2111 浏览 1 评论
3669 浏览 3 评论
PIC1946程序有一个变量在运行过程中恢复初始值其他变量保持不变
2357 浏览 2 评论
2782 浏览 0 评论
PIC16F1825的RC5引脚,在主程序中操作无效,在中断中可以改变是为什么?
4072 浏览 5 评论
1014浏览 0评论
用XC8编译PIC18F25K80时提示下面Error,求怎么解决这个问题
6399浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-28 12:22 , Processed in 0.664159 second(s), Total 81, Slave 63 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号