펌웨어디자인(Firmware Design)

PIC18F8490

arirangled 2006. 3. 10. 22:44

 

 

 

디버거로 사용시에 에러가 나는 경우는 에러가 발생한 부분을 마우스로 더블 클릭하면 도움말이 나옵니다.이를 통해 쉽게 발생된 문제를 해결해 나갈수 있습니다. (아래는 데모보드에 DC전원플러그가 꽂혀 있지 않아서 발생된 예입니다.)

 

;***********************************************************************;
;*                                                                      ;
;* Production test file for LCD Demo Board                              ;
;*                                                                      ;
;***********************************************************************;
;* FileName:            LCDDemo.asm                                     ;   
;* Dependencies:                                                        ;
;* Processor:           PIC18F8490                            ;
;* Assembler:           MPASMWIN 02.70.02 or higher                     ;
;* Linker:              MPLINK 2.33.00 or higher                        ;
;* Company:             Microchip Technology, Inc.                      ;
;*                                                                      ;
;* Software License Agreement                                           ;
;*                                                                      ;
;* The software supplied herewith by Microchip Technology Incorporated  ;
;* (the "Company") for its PICmicro?Microcontroller is intended and    ;
;* supplied to you, the Company's customer, for use solely and          ;
;* exclusively on Microchip PICmicro Microcontroller products. The      ;
;* software is owned by the Company and/or its supplier, and is         ;
;* protected under applicable copyright laws. All rights are reserved.  ;
;* Any use in violation of the foregoing restrictions may subject the   ;
;* user to criminal sanctions under applicable laws, as well as to      ;
;* civil liability for the breach of the terms and conditions of this   ;
;* license.                                                             ;
;*                                                                      ;
;* THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES,    ;
;* WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED    ;
;* TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A          ;
;* PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,    ;
;* IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR           ;
;* CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.                    ;
;*                                                                      ;
;*                                                                      ;
;* ANY SPECIAL DESCRIPTION THAT MIGHT BE USEFUL FOR THIS FILE.          ;
;*                                                                      ;
;* Author               Date            Comment                         ;
;*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
;* Vidyadhar       Sept 14, 2004    Initial Release (V1.0)              ;
;*                                                                      ;
;***********************************************************************;
                                                                        ;
        #include                                          ;
                                                                        ;
        #include "LCD.inc"                                              ;
        #include "MWMEE.inc"                                            ;
        #include "USRTPol.inc"                                          ;
        #include "LCDMsgs.inc"                                          ;
        #include "LCDBoard.inc"                                         ;
                                                                        ;
#define PeriPwrWithIO       ;Peropherals powered using an I/O           ;
;#define SwitchWithAD       ;Switches are sensed using A2D.(Please comment this)    ;
                                                                        ;
#define UserMode            ;User mode (If commented removes user mode)              ;
#define VMDemo              ;Volt-meter Demo (If commented removes Voltmeter)        ;
#define TMDemo              ;Thermo-meter Demo (If commented removes Thermometer)    ;
#define BVIDemo             ;Battery Voltage indicator Demo (If commented removes BVI);
#define RTCDemo             ;RTC Demo (If commented removes RTC)                     ;
                                                                        ;
;***********************************************************************;
;Configuration bits
                                                     ;
                                                                        ;
  __CONFIG  _CONFIG1H, _IESO_OFF_1H & _FCMEN_OFF_1H & _OSC_INTIO67_1H   ;
  __CONFIG  _CONFIG2L, _PWRT_OFF_2L & _BOREN_OFF_2L & _BORV_25_2L       ;
  __CONFIG  _CONFIG2H, _WDT_OFF_2H & _WDTPS_32_2H                       ;
  __CONFIG  _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _CCP2MX_PORTC_3H;
  __CONFIG  _CONFIG4L, _STVREN_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L   ;
  __CONFIG  _CONFIG5L, _CP_OFF_5L                                       ;
  __CONFIG  _CONFIG7L, _EBTR_OFF_7L                                     ;
                                                                        ;
;***********************************************************************;
                                                ;
LCDDemo UDATA                                   ;
                                                ;
Temp        res 1                               ;
Temp1       res 1                               ;
Temp2       res 1                               ;
Temp3       res 1                               ;
HourReg     res 1                               ;
MinReg      res 1                               ;
SecReg      res 1                               ;
TimeCount   res 1                               ;
MenuStatus  res 1                               ;
                                                ;
;***********************************************;
                                                ;
ClkConst    equ  CLOCK_FREQ/(.4*.6)             ;
                                                ;
;***********************************************;
;Reset Vector                                   ;
;-----------------------------------------------;
                                                ;
ResetVector     CODE    0x00                    ;
                                                ;
     goto start                           ;
                                                ;
;-----------------------------------------------;
;Interrupt Vector                               ;
;-----------------------------------------------;
                                                ;
IntrptVector     CODE    0x08                   ;
                                                ;
    #ifdef UserMode                             ;
      #ifdef RTCDemo                            ;
                                                ;
     goto ISR                             ;
                                                ;
      #endif                                    ;
    #endif                                      ;
                                                ;
;-----------------------------------------------;
                                                ;
Main_Start CODE                                ;
                                             ;
start                                         ;
        movlw   B'01110000'                     ;Select 8MHz frequency
        movwf   OSCCON                          ;
                                                ;
        movlw   0x0d                            ;AN0 & AN1 are made analog and all the rest digital
        movwf   ADCON1                          ;Vdd & Vss are used as VRefs
                                                ;
        bcf     PeriPwr                         ;
        bcf     Transeiver                      ;
        bcf     EEProm                          ;
        bcf     LED1                            ;
        bcf     LED2                            ;
                                                ;
        bcf     PeriPwrCon                      ;
        bcf     TrnsverCon                      ;
        bcf     EEPromCon                       ;
        bcf     LED1Con                         ;
        bcf     LED2Con                         ;
        bcf     LED1                            ;
        bcf     LED2                            ;
                                                ;
        call    LCDInit                         ;Initialize LCD
                                                ;
     mLCDDisplayCodedMessage MsgM_CHIP       ;;Display "M-CHIP"
        call    LongDelay                       ;Delay to read
        call    LongDelay                       ;
                                                ;
       mLCDDisplayCodedMessage MsgLCD_DEMO     ;Display "LCDBOARD"
;        call    LongDelay                       ;Delay to read;
        call    LongDelay                       ;
                                                ;
    #ifdef TestMode                             ;
                                                ;
ChkIsTestMode                                   ;Check Production test entry switch
        mEnableSwitch                           ;
                                                ;
    #ifndef SwitchWithAD                        ;
        btfss   Switch1                         ;
    #else                                       ;
        call    InitADC                         ;
        call    ScanKeys                        ;
        tstfsz  WREG                            ;
    #endif                                      ;
        goto    TestModE                        ;
                                                ;
    #endif                                      ;
                                                ;
;-----------------------------------------------;
;************* STANDARD USER CODE **************;
                                                ;
    #ifdef UserMode                             ;
                                                ;
UserModE                                        ;
    #ifdef SwitchWithAD                         ;
        bcf     ADCON0,ADON                     ;
    #endif                                      ;
        mDisableSwitch                          ;
                                                ;
        bcf     INTCON,RBIF                     ;
        bsf     INTCON,RBIE                     ;
        sleep                                   ;
        nop                                     ;
        bcf     INTCON,RBIF                     ;
        bcf     INTCON,RBIE                     ;
                                                ;
;-----------------------------------------------;
Menu                                            ;
                                                ;
    #ifndef SwitchWithAD                        ;
      #ifdef VMDemo                             ;
                                                ;
Menu_V_Mtr                                      ;
     mLCDDisplayCodedMessage MsgVolt_Mtr     ;Display "VOLT MTR"
        call    LongDelay                       ;Delay to read
                                             ;
        mEnablePot                              ;
                                                ;
        call    InitADC                         ;
                                                ;
        movlw   0xC3                            ;select Ch0
        andwf   ADCON0
        call    Delay10mS                                        ;
                                                                    ;
        bsf     PIE1,ADIE                       ;

      
                                                ;
Rpt_V_Mtr                                       ;
        bsf     ADCON0,GO                       ;Start Conversion
                                                ;
        sleep                                   ;
        btfsc   ADCON0, NOT_DONE                ;
        bra     $-4                             ;
                                                ;
     movff ADRESH,Temp                     ;
        bcf     PIR1,ADIF                       ;
                                                ;
        call    VoltCnv                         ;convert the read value into voltage
                                                ;
        call    LCDClear                        ;
                                                ;
        mLCDDisplayVar Digit1, Temp1            ;
        mLCDDisplayVar Digit2, Temp2            ;
        mLCDDisplayVar Digit3, Temp3            ;
        bsf     DP1                             ;
        mLCDDisplayChar Digit5, 'V'             ;
        call    Delay10mS                       ;
                                                ;
;        mEnableSwitch                           ;
        call    ScanKeys                        ;check should exit or not
;        mDisableSwitch                          ;
                                                ;
        xorlw   0x00                            ;
        bnz     $+4                             ;
        bra     Rpt_V_Mtr                       ;
                                                ;
        mDisablePot                             ;
                                                ;
        bcf     ADCON0,ADON                     ;
        bcf     PIE1,ADIE                       ;
                                                ;
      #endif                                    ;
    #endif                                      ;
                                                ;
;...............................................;
                                                ;
    #ifdef TMDemo                               ;
                                                ;
Menu_Tempr                                      ;
     mLCDDisplayCodedMessage MsgThrm_Mtr     ;
        call    LongDelay                       ;Delay to read
                                             ;
        mEnableTherm                            ;
                                                ;
        call    InitADC                         ;
                                                ;
        movlw   0xC3                            ;
        andwf   ADCON0                          ;
        bsf     ADCON0,CHS0                     ;select ch1
        call    Delay10mS                                        ;
        bsf     PIE1,ADIE                       ;
                                                ;
Rpt_T_Mtr                                       ;
        bsf     ADCON0,GO                       ;Start Conversion
                                                ;
        sleep                                   ;
        btfsc   ADCON0, NOT_DONE                ;
        bra     $-4                             ;
                                                ;
     movff ADRESH,Temp                     ;
        bcf     PIR1,ADIF                       ;
                                                ;
        call    VoltCnv                         ;convert the read value into tempareture
                                                ;
        call    LCDClear                        ;
                                                ;
        mLCDDisplayVar Digit1, Temp1            ;
        mLCDDisplayVar Digit2, Temp2            ;
        mLCDDisplayVar Digit3, Temp3            ;
        bsf     DP2                             ;
        bsf     AP5                             ;
        mLCDDisplayChar Digit5, 'C'             ;
        call    Delay10mS                       ;
                                                ;
;        mEnableSwitch                           ;
        call    ScanKeys                        ;check should exit or not
;        mDisableSwitch                          ;
                                                ;
        xorlw   0x00                            ;
        bnz     $+4                             ;
        bra     Rpt_T_Mtr                       ;
                                                ;
        mDisableTherm                           ;
                                                ;
        bcf     ADCON0,ADON                     ;
        bcf     PIE1,ADIE                       ;
                                                ;
    #endif                                      ;
                                                ;
;...............................................;

                                                ;
    #ifdef BVIDemo                              ;
                                                ;
Menu_BVol                                       ;
     mLCDDisplayCodedMessage MsgBatt_Vol     ;
        call    LongDelay                       ;Delay to read
                                             ;
    #ifdef SwitchWithAD                         ;
        call    InitADC                         ;
    #endif                                      ;
                                                ;
        call    InitLVD                         ;
                                                ;
Rpt_BV_Mtr                                      ;
        clrf    Temp1                           ;
                                                ;       
;        movlw   0x81                            ;
;        movlw   0x8e                            ;
        movlw   0x01                            ;
        movwf   HLVDCON                         ;
                                                ;
RptChk                                          ;
        bsf     HLVDCON,HLVDEN                  ;
;        bsf     HLVDCON,
        nop                                     ;
        nop                                     ;
                                                ;
        btfss   HLVDCON,IRVST                   ;
        bra     $-2                             ;
        nop                                     ;
        nop                                     ;
                                                ;
        bcf     PIR2,HLVDIF                     ;
;        nop
                                                ;
        btfsc   PIR2,HLVDIF                     ;
        bra     ChkVolt                         ;jump to check the voltage
        decfsz  Temp1                           ;
        bra     $-6                             ;
                                                ;
        bcf     HLVDCON,HLVDEN                  ;
        incf    HLVDCON                         ;
;        decf    HLVDCON                         ;
                                                ;
        movf    HLVDCON,W                       ;
        andlw   0x0f                            ;
        xorlw   0x0e                            ;
        bnz     RptChk                          ;
                                                ;
;        call    Volt450                         ;
        goto    Volt475
                                                ;
BVEnd                                           ;
        mEnableSwitch                           ;
        call    ScanKeys                        ;check should exit or not
        mDisableSwitch                          ;
                                                ;
        xorlw   0x00                            ;
        bnz     $+4                             ;
        bra     Rpt_BV_Mtr                      ;
                                                ;
        bcf     HLVDCON,HLVDEN                  ;
    #ifdef SwitchWithAD                         ;
        bcf     ADCON0,ADON                     ;
    #endif                                      ;
                                                ;
    #endif                                      ;
                                                ;
;...............................................;
                                                ;
    #ifdef RTCDemo                              ;
                                                ;
Menu_RTC                                        ;
     mLCDDisplayCodedMessage MsgRTC          ;
        call    LongDelay                       ;Delay to read
                                             ;
    #ifdef SwitchWithAD                         ;
        call    InitADC                         ;
    #endif                                      ;
                                                ;
        call    InitRTC                         ;
                                                ;
Rpt_RTC                                         ;
        call    LCDClear                        ;
                                                ;
        movff   HourReg,Temp                    ;
        call    BCDCnv                          ;
        mLCDDisplayVar Digit1, Temp2            ;
        mLCDDisplayVar Digit2, Temp3            ;
                                                ;
        movff   MinReg,Temp                     ;
        call    BCDCnv                          ;
        mLCDDisplayVar Digit4, Temp2            ;
        mLCDDisplayVar Digit5, Temp3            ;
                                                ;
        movff   SecReg,Temp                     ;
        call    BCDCnv                          ;
        mLCDDisplayVar Digit7, Temp2            ;
        mLCDDisplayVar Digit8, Temp3            ;
;        call    Delay10mS                       ;
                                                ;
        mEnableSwitch                           ;
        call    ScanKeys                        ;
        mDisableSwitch                          ;
                                                ;
        tstfsz  WREG                            ;;
        bra     $+4                             ;
        bra     Rpt_RTC                         ;;
                                                ;
        decfsz  WREG                            ;
        bra     $+4                             ;
        bra     RTCExit                         ;
                                                ;
        decfsz  WREG                            ;
        bra     $+4                             ;
        bra     RTCExit                         ;
                                                ;
        decfsz  WREG                            ;
        bra     Set_Hr                          ;
Set_Min                                         ;
        incf    MinReg                          ;
        movlw   .59                             ;
        cpfsgt  MinReg                          ;
        bra     Rpt_RTC                         ;
        clrf    MinReg                          ;
        bra     Rpt_RTC                         ;
Set_Hr                                          ;
        incf    HourReg                         ;
        movlw   .23                             ;
        cpfsgt  HourReg                         ;
        bra     Rpt_RTC                         ;
        clrf    HourReg                         ;
        bra     Rpt_RTC                         ;
                                                ;
RTCExit                                         ;
    #ifdef SwitchWithAD                         ;
        bcf     ADCON0,ADON                     ;
    #endif                                      ;
                                                ;
        bcf     T1CON,TMR1ON                    ;
        bcf     PIE1,TMR1IE                     ;
        bcf     INTCON,PEIE                     ;
        bcf     INTCON,GIE                      ;
                                                ;
    #endif                                      ;
                                                ;
        bra     Menu                            ;
                                                ;
;-----------------------------------------------;

;-----------------------------------------------;
    #ifdef RTCDemo                              ;
                                                ;
InitRTC:                                        ;
        BANKSEL SecReg                          ;
        clrf    SecReg                          ;
        clrf    MinReg                          ;
        clrf    HourReg                         ;
        clrf    TMR1L                           ;
        movlw   0x80                            ;
        movwf   TMR1H                           ;
                                                ;
        movlw   B'00001111'                     ;Timer 1 on, Osc on
        movwf   T1CON                           ;
                                                ;
        bcf     PIR1,TMR1IF                     ;
        bsf     PIE1,TMR1IE                     ;
        bsf     INTCON,PEIE                     ;
        bsf     INTCON,GIE                      ;
                                                ;
        return                                  ;
                                                ;
    #endif                                      ;
                                                ;
;-----------------------------------------------;
    #ifdef BVIDemo                              ;
                                                ;
InitLVD:                                        ;
        movlw   B'10001110'                     ;
        movwf   HLVDCON                         ;
                                                ;
        bcf     PIR2,HLVDIF                     ;
                                                ;
        return                                  ;
                                                ;
;-----------------------------------------------;

;...............................................;
ChkVolt                                         ;
        bcf     HLVDCON,HLVDEN                  ;
                                                ;
        movlw   UPPER(B_Vols)                  ;
        movwf   PCLATU                          ;
        movlw   HIGH(B_Vols)                   ;
        movwf   PCLATH                          ;
                                                ;
        movf    HLVDCON,W                       ;
        andlw   0x0f                            ;
                                                ;
        decf    WREG                            ;
        rlncf   WREG                            ;
        addlw   B_Vols                          ;
        bnc     $+.8                            ;
        incf    PCLATH                          ;
        bnc     $+4                             ;
        incf    PCLATU                          ;
                                                ;
        movf    HLVDCON,W                       ;
        andlw   0x0f                            ;
        decf    WREG                            ;
        rlncf   WREG                            ;
        addwf   PCL                             ;
                                                ;       
B_Vols:                                         ;
        bra     Volt200                         ;
        bra     Volt200                         ;
        bra     Volt225                         ;
        bra     Volt250                         ;
        bra     Volt250                         ;
        bra     Volt275                         ;
        bra     Volt300                         ;
        bra     Volt325                         ;
        bra     Volt350                         ;
        bra     Volt350                         ;
        bra     Volt375                         ;
        bra     Volt400                         ;
        bra     Volt425                         ;
        bra     Volt450                         ;
        bra     Volt450                         ;
        bra     Volt450                         ;
                                                ;
;...............................................;
Volt200                                         ;
        movlw   0x02                            ;
        movwf   Temp1                           ;
        movlw   0x00                            ;
        movwf   Temp2                           ;
        movlw   0x00                            ;
        movwf   Temp3                           ;
        bra     BVDis                           ;
                                                ;
Volt225                                         ;
        movlw   0x02                            ;
        movwf   Temp1                           ;
        movlw   0x02                            ;
        movwf   Temp2                           ;
        movlw   0x05                            ;
        movwf   Temp3                           ;
        bra     BVDis                           ;
                                                ;
Volt250                                         ;
        movlw   0x02                            ;
        movwf   Temp1                           ;
        movlw   0x05                            ;
        movwf   Temp2                           ;
        movlw   0x00                            ;
        movwf   Temp3                           ;
        bra     BVDis                           ;
                                                ;
Volt275                                         ;
        movlw   0x02                            ;
        movwf   Temp1                           ;
        movlw   0x07                            ;
        movwf   Temp2                           ;
        movlw   0x05                            ;
        movwf   Temp3                           ;
        bra     BVDis                           ;
                                                ;
Volt300                                         ;
        movlw   0x03                            ;
        movwf   Temp1                           ;
        movlw   0x00                            ;
        movwf   Temp2                           ;
        movlw   0x00                            ;
        movwf   Temp3                           ;
        bra     BVDis                           ;
                                                ;
Volt325                                         ;
        movlw   0x03                            ;
        movwf   Temp1                           ;
        movlw   0x02                            ;
        movwf   Temp2                           ;
        movlw   0x05                            ;
        movwf   Temp3                           ;
        bra     BVDis                           ;
                                                ;
Volt350                                         ;
        movlw   0x03                            ;
        movwf   Temp1                           ;
        movlw   0x05                            ;
        movwf   Temp2                           ;
        movlw   0x00                            ;
        movwf   Temp3                           ;
        bra     BVDis                           ;
                                                ;
Volt375                                         ;
        movlw   0x03                            ;
        movwf   Temp1                           ;
        movlw   0x07                            ;
        movwf   Temp2                           ;
        movlw   0x05                            ;
        movwf   Temp3                           ;
        bra     BVDis                           ;
                                                ;
Volt400                                         ;
        movlw   0x04                            ;
        movwf   Temp1                           ;
        movlw   0x00                            ;
        movwf   Temp2                           ;
        movlw   0x00                            ;
        movwf   Temp3                           ;
        bra     BVDis                           ;
                                                ;
Volt425                                         ;
        movlw   0x04                            ;
        movwf   Temp1                           ;
        movlw   0x02                            ;
        movwf   Temp2                           ;
        movlw   0x05                            ;
        movwf   Temp3                           ;
        bra     BVDis                           ;
                                                ;
Volt450                                         ;
        movlw   0x04                            ;
        movwf   Temp1                           ;
        movlw   0x05                            ;
        movwf   Temp2                           ;
        movlw   0x00                            ;
        movwf   Temp3                           ;
        bra     BVDis                           ;
                                                ;
Volt475                                         ;
        movlw   0x04                            ;
        movwf   Temp1                           ;
        movlw   0x07                            ;
        movwf   Temp2                           ;
        movlw   0x05                            ;
        movwf   Temp3                           ;
                                                ;
BVDis                                           ;
        call    LCDClear                        ;
                                                ;
        mLCDDisplayVar Digit1, Temp1            ;
        mLCDDisplayVar Digit2, Temp2            ;
        mLCDDisplayVar Digit3, Temp3            ;
        bsf     DP1                             ;
        mLCDDisplayChar Digit5, 'V'             ;
        bsf     D6G                             ;
        bsf     D6K                             ;
        bsf     D6I                             ;
        bsf     D6M                             ;
        call    LongDelay                       ;
                                                ;
        goto    BVEnd                           ;
                                                ;
    #endif                                      ;
                                                ;
;***********************************************;
    #ifdef RTCDemo                              ;
                                                ;
ISRCODE CODE                                    ;
;-----------------------------------------------;
ISR:                                            ;
        btfss   PIR1,TMR1IF                     ;
        retfie  FAST                            ;
                                                ;
        bsf     TMR1H,7                         ;
        BANKSEL SecReg                          ;
        incf    SecReg                          ;
        movlw   .60                             ;
        xorwf   SecReg, W                       ;
        bnz     retturn                         ;
                                                ;
        clrf    SecReg                          ;
        incf    MinReg                          ;
        movlw   .60                             ;
        xorwf   MinReg, W                       ;
        bnz     retturn                         ;
                                                ;
        clrf    MinReg                          ;
        incf    HourReg                         ;
        movlw   .24                             ;
        xorwf   HourReg, W                      ;
        bnz     retturn                         ;
        clrf    HourReg                         ;
                                                ;
retturn                                         ;
        bcf     PIR1,TMR1IF                     ;
        retfie  FAST                            ;
                                                ;
    #endif                                      ;
                                                ;
    #endif                                      ;
                                                ;
;***********************************************;
;-----------------------------------------------;
InitADC:                                        ;
        movlw   B'00001101'                     ;
        movwf   ADCON1                          ;Configure RA0 & RA1 as analog, Int Ref
                                                ;
;        movlw   B'00111010'                     ;Left justigied, 20TAD Acq time, FOSC/32
        movlw   B'00000011'                     ;Left justigied, Clk_ADRC
        movwf   ADCON2                          ;
                                                ;
        movlw   B'00000001'                     ;AD on
        movwf   ADCON0                         ;
                                                ;
        return                                  ;
                                                ;
;-----------------------------------------------;
ScanKeys:                                       ;
    #ifdef SwitchWithAD                         ;  
                                                ;
        bsf     PIE1,ADIE                       ;
        movlw   0xC3                            ;select Ch0
        andwf   ADCON0                          ;
                                                ;
        bsf     ADCON0,GO                       ;Start Conversion
                                                ;
        sleep                                   ;
        btfsc   ADCON0, NOT_DONE                ;
        bra     $-4                             ;
                                                ;
     movff ADRESH,Temp                     ;
        bcf     PIE1,ADIE                       ;
        bcf     PIR1,ADIF                       ;
                                                ;
        movlw   0x10                            ;
        cpfsgt  Temp                            ;
        retlw   0x00                            ;
                                                ;
        movlw   0x26 ;0x38                            ;
        cpfsgt  Temp                            ;
        retlw   0x04                            ;
                                                ;
        movlw   0x3c ;0x48                            ;
        cpfsgt  Temp                            ;
        retlw   0x03                            ;
                                                ;
        movlw   0x60                            ;
        cpfsgt  Temp                            ;
        retlw   0x02                            ;
                                                ;
        movlw   0x90                            ;
        cpfsgt  Temp                            ;
        retlw   0x01                            ;
                                                ;
        retlw   0x00                            ;
                                                ;
    #else                                       ;
                                                ;
        btfss   Switch1                         ;
        retlw   0x01                            ;
                                                ;
        btfss   Switch2                         ;
        retlw   0x02                            ;
                                                ;
        btfss   Switch3                         ;
        retlw   0x03                            ;
                                                ;
        btfss   Switch4                         ;
        retlw   0x04                            ;
                                                ;
        retlw   0x00                            ;
                                                ;
    #endif                                      ;
                                                ;
;-----------------------------------------------;
VoltCnv:                                        ;
        BANKSEL Temp1                           ;
        clrf    Temp1                           ;
        clrf    Temp2                           ;
        clrf    Temp3                           ;
        bcf     STATUS,C                        ;
        rlcf    Temp                            ;
        bnc     $+.10                           ;
        incf    Temp1                           ;
        incf    Temp1                           ;
        movlw   0x55                            ;
        movwf   Temp3                           ;
        bra     $+8                             ;
                                                ;
BCDCnv                                          ;
        clrf    Temp1                           ;
        clrf    Temp2                           ;
        clrf    Temp3                           ;
        movf    Temp,W                          ;
        andlw   0xf0                            ;
        movwf   Temp2                           ;
        swapf   Temp2                           ;
                                                ;
        movf    Temp,W                          ;
        andlw   0x0f                            ;
        bcf     STATUS,C                        ;
        bcf     STATUS,DC                       ;
        daw                                     ;
        addwf   Temp3                           ;
                                                ;
        movf    Temp2                           ;
        btfsc   STATUS,Z                        ;
        bra     rpt2                            ;
rpt                                             ;
        movlw   0x16                            ;
        addwf   Temp3,W                         ;
        bcf     STATUS,C                        ;
        bcf     STATUS,DC                       ;
        daw                                     ;
        bnc     $+4                             ;
        incf    Temp1                           ;
        movwf   Temp3                           ;
        decfsz  Temp2                           ;
        bra     rpt                             ;
                                                ;
rpt1                                            ;
        movf    Temp3,W                         ;
        andlw   0xf0                            ;
        movwf   Temp2                           ;
        swapf   Temp2                           ;
                                                ;
        movlw   0x0f                            ;
        andwf   Temp3                           ;
                                                ;
        return                                  ;
                                                ;
rpt2                                            ;
        movf    Temp3,W                         ;
        andlw   0x0f                            ;
        sublw   0x09                            ;
        bc      rpt1                            ;
        movf    Temp3,W                         ;
        bcf     STATUS,C                        ;
        bcf     STATUS,DC                       ;
        daw                                     ;
        bnc     $+4                             ;
        incf    Temp1                           ;
        movwf   Temp3                           ;
        bra     rpt1                            ;
                                                ;
        return                                  ;
                                                ;
;***********************************************;
; Function:     LongDelay                       ;
;                                               ;
; PreCondition: None                            ;
;                                               ;
; Overview:     Provides approx 2S delay @ 8MHz ;
;                                               ;
; Input:        None                            ;
;                                               ;
; Output:       None                            ;
;                                               ;
; Side Effects: Databank changed                ;
;                                               ;
; Stack requirement: 1                          ;
;                                               ;
;***********************************************;
                                                ;
LongDelay                                       ;
        BANKSEL Temp1                           ;
     clrf Temp1                           ;
     clrf Temp2                           ;
     movlw 0x0a                            ;0x0b
     movwf Temp3                           ;
                                                ;
LongDelay_1                                     ;
     decfsz Temp1,F                         ;
     bra LongDelay_1                         ;
                                                ;
       decfsz Temp2,F                         ;
     bra LongDelay_1                         ;
                                                ;
     decfsz Temp3,F                         ;
     bra LongDelay_1                         ;
                                                ;
     return                                 ;
                                                ;
;-----------------------------------------------;
Delay10mS                                       ;
    BANKSEL Temp1                               ;
 clrf Temp1                               ;
    movlw   0x0a                                ;
 movwf Temp2                               ;
Dly10mS_1                                       ;
 decfsz Temp1,F                             ;
 bra Dly10mS_1                               ;
 decfsz Temp2,F                             ;
 bra Dly10mS_1                               ;
 return                                     ;
                                                ;
;***********************************************;

;***********************************************;
    END                                         ;
;***********************************************;

반응형

'펌웨어디자인(Firmware Design)' 카테고리의 다른 글

PIC12F629  (0) 2006.07.24
PIC베이직컴파일러참조매뉴얼  (0) 2006.05.05
충전기제작  (0) 2006.05.05
asass  (0) 2006.02.05
마이크로칩사 원칩마이컴IC  (0) 2006.01.03