|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
- ;==============================================================================
- ; FEELING TECHNOLOGY CORP.
- ;==============================================================================
- ;IC : FM8PC71A
- ;CPUCLK : 1 MHz
- ;WDT : Disable
- ;------------------------------------------------------------------------------
- ;MODIFY BY : KL Lai
- ;DATE : 2011-0905
- ;VER : 1.00
- ;------------------------------------------------------------------------------
-
- #include "C71AS_define.ash"
-
- SEL_CPUCLK_DELAY EQU 01D ; 1=1MHz , 2=2MHz , 4=4MHz , 8=8MHz , 16=16MHz
-
- ;=====================================================================
- ;-------------------------- ROM Areas --------------------------------
- ;=====================================================================
-
- ORG 000H
- GOTO reset
-
- ORG 003H
-
- ;---------------------------------------------------------------------
- INT_VECTOR:
- MOVAR INTACCTMP ;Push Stack
- SWAPR STATUS,A
- MOVAR INTSTATMP
- MOVR EFR_1,A
- MOVAR INTEFR1TMP
-
- BCR EFR_1,ROMBK_B ;ROM BANK0
- BCR EFR_1,RAMBK_B ;RAM BANK0
-
- BTRSC intflag,paif_b
- GOTO paitask ;porta
-
- BTRSC intflag,pbif_b
- GOTO pbitask ;portb
-
- BTRSC PWM0CR,P0TMIF_B
- GOTO PWM0Itask ;PWM0
-
- BTRSC PWM1CR,P1TMIF_B
- GOTO PWM1Itask ;PWM1
-
- BTRSC PWM2CR,P2TMIF_B
- GOTO PWM2Itask ;PWM2
-
- BTRSC PWM3CR,P3TMIF_B
- GOTO PWM3Itask ;PWM3
-
- BTRSC ADCON_2,ADCIF_B
- GOTO ADCItask ;ADC
-
-
- int_exit:
- MOVR INTEFR1TMP,A ;Pop Stack
- MOVAR EFR_1
- SWAPR INTSTATMP,A
- MOVAR STATUS
- SWAPR INTACCTMP,R
- SWAPR INTACCTMP,A
- RETFIE
- ;=====================================================================
- ;------------------ Main Programme Beginning -------------------------
- ;=====================================================================
-
-
- ;=====================================================================
- ;=====================================================================
- ; Variable : m=Low-byte , n=High-byte
- ; Delay Time = n*256*40us + (m+1)*40us
- ; The Min. delay time = 40us , the Max. delay time = 2631680us = 2631.68ms
- FM_Delay_40us MACRO n,m
-
- movia m
- movar DlyCnt_L
- movia n
- movar DlyCnt_M
-
- CALL F_Dec_counter_40us ;6 cycles
- ENDM
- ;--------------------------------------------------
-
- FC_delay_40us:
-
- if SEL_CPUCLK_DELAY=01D
- call Eight_Cycle
- call Four_Cycle
- endif
-
- if SEL_CPUCLK_DELAY=02D
- call Sixteen_Cycle
- call Sixteen_Cycle
- endif
-
- if SEL_CPUCLK_DELAY=04D
- call Eight_Cycle
- call Sixteen_Cycle
- call Sixteen_Cycle
- call Sixteen_Cycle
- call Sixteen_Cycle
- endif
- if SEL_CPUCLK_DELAY=08D
- movia 007h
- movar DlyCnt_temp
- call Sixteen_Cycle
- nop
- decrsz DlyCnt_temp,r
- goto $-3 ;20
- nop
- call Eight_Cycle
- endif
- if SEL_CPUCLK_DELAY=16D
- movia 00fh
- movar DlyCnt_temp
- call Sixteen_Cycle
- nop
- decrsz DlyCnt_temp,r
- goto $-3 ;20
- nop
- call Eight_Cycle
- endif
-
- F_Dec_counter_40us:
- movia 0xFF
- addar DlyCnt_L,r
- btrsc status,0
- incr DlyCnt_M,r
- addar DlyCnt_M,r
- btrsc status,0
- goto FC_delay_40us ;8 cycles
- F_exit_delay_40us: ;7 cycles
- ;counter overflow
- if SEL_CPUCLK_DELAY=01D
- nop
- goto $+1
- goto $+1
- endif
-
- if SEL_CPUCLK_DELAY=02D
- nop
- call Eight_Cycle
- call Sixteen_Cycle
- endif
- if SEL_CPUCLK_DELAY=04D
- nop
- call Sixteen_Cycle
- call Sixteen_Cycle
- call Sixteen_Cycle
- call Sixteen_Cycle
- endif
- if SEL_CPUCLK_DELAY=08D
- movia 007h
- movar DlyCnt_temp
- call Sixteen_Cycle
- nop
- decrsz DlyCnt_temp,r
- goto $-3 ;20
- goto $+1
- goto $+1
- endif
- if SEL_CPUCLK_DELAY=16D
- movia 00fh
- movar DlyCnt_temp
- call Sixteen_Cycle
- nop
- decrsz DlyCnt_temp,r
- goto $-3 ;20
- goto $+1
- goto $+1
- endif
- RETURN
- Sixteen_Cycle:
- goto $+1
- goto $+1
- goto $+1
- goto $+1
- Eight_Cycle:
- goto $+1
- goto $+1
- RETURN
- Four_Cycle:
- RETURN
- ;---------------------------------------------------------------------
- ;---------------------------------------------------------------------
- ; Variable : n
- ; Delay Time ~= n*100ms
- ; The Min. delay time = 0ms , the Max. delay time = 25500ms = 25.5s
- ; パ?Delay?丁耕?, ??ぃ暗弘絋?璸衡
- FM_Delay_ms MACRO n
-
- movia n
- movar DlyCnt_H
- movr DlyCnt_H,A
- btrsc status,2
- goto $+9 ;If counter=0 , exit count
- ;Dec_counter_ms:
- clrwdt
- movia 195d
- movar DlyCnt_L
- movia 009d
- movar DlyCnt_M
- CALL FC_delay_40us ;100ms
- decrsz DlyCnt_H,R
- goto $-7 ;Dec_counter_ms
-
- ;exit_delay_ms:
-
- ENDM
-
- ;=====================================================================
- ;=====================================================================
-
-
- reset:
- NOP
- NOP
- NOP
- clrwdt
-
- BCR WDT,WDTE_B //Disable Watch dog timer
- NOP
- NOP
-
- CALL CLEAR_RAM
-
- CALL RESET_INIT
-
- CALL IO_INITIAL
-
- CALL ADC_CON_INITIAL
-
- FM_Delay_ms 2 ;DELAY 200MS
-
- NOP
- NOP
-
-
- MAIN_LOOP:
- CLRWDT
- NOP
- NOP
- NOP
- CALL GET_ADC_DATA //Polling ADC conversion has completed ?
- NOP
- NOP
- NOP
- GOTO MAIN_LOOP
-
-
- ;-----------------------------------------------------------
- GET_ADC_DATA:
- BSR ADCON_1,ADCST_B //Start to ADC sample, when ADC is trigger mode.
-
- BTRSC ADCON_1,ADCST_B
- GOTO $-1
- NOP
- NOP
- MOVR ADCLB,A
- MOVAR ADCLB_TEMP //Move ADCLB data to ADCLB_TEMP register
- MOVR ADCHB,A
- MOVAR ADCHB_TEMP //Move ADCHB data to ADCHB_TEMP register
- RETURN
- ;-----------------------------------------------------------
-
- ;=====================================================================
- ;=====================================================================
- ADC_CON_INITIAL:
- BSR ADCON_1,CHSEL0_B //ADC input channel is PB1
- BCR ADCON_1,CHSEL1_B
- BCR ADCON_1,CHSEL2_B
-
- BCR ADCON_1,ADCSR0_B
- BCR ADCON_1,ADCSR1_B //ADC clock is Fcpu/8
-
- BCR ADCON_2,SVREFH_B //Internal VREFH
-
- BCR ADCON_2,ADCNT_B //Trigger mode
-
- BCR ADCON_2,DACOEN_B //Disable DAC output to PB3
- BSR ADCON_2,ADCTMS_B //Fixed convert timing
- BCR ADCON_2,ADCIF_B //Clear ADC completed flag
- BCR ADCON_2,ADCIE_B //Disable ADC interrupt
-
- BSR ADCON_2,SELVER0_B
- BSR ADCON_2,SELVER1_B //Internal VREFH = 2V
-
- BSR ADCON_1,ADCEN_B //Enable ADC
- RETURN
- ;=====================================================================
- ;=================== I/O Mode Setting ================================
- ;=====================================================================
- IO_INITIAL:
- MOVIA 00000000B
- IOST PAMODE0
- MOVIA 11111111B
- IOST PAMODE1
-
- MOVIA 0FFH
- MOVAR PORTA
-
- MOVIA 00000000B
- IOST PBMODE0
- MOVIA 11101101B //PB1, PB4 are input mode
- IOST PBMODE1 //Because PB1 as AIN pin ,PB4 as VREFH pin
-
- MOVIA 0FFH
- MOVAR PORTB
-
- FM_Delay_40us 000D,049D //Delay 2 ms
-
- RETURN
-
-
- ;=====================================================================
- ;=====================================================================
- paitask:
- BCR INTFLAG,PAIF_B
- GOTO int_exit
-
- pbitask:
- BCR INTFLAG,PBIF_B
- GOTO int_exit
-
- PWM0Itask:
- BCR PWM0CR,P0TMIF_B
- GOTO int_exit
-
- PWM1Itask:
- BCR PWM1CR,P0TMIF_B
- GOTO int_exit
-
- PWM2Itask:
- BCR PWM2CR,P2TMIF_B
- GOTO int_exit
-
- PWM3Itask:
- BCR PWM3CR,P3TMIF_B
- GOTO int_exit
-
- ADCItask:
- BCR ADCON_2,ADCIF_B
- NOP
- NOP
- MOVR ADCLB,A
- MOVAR ADCLB_TEMP //Move ADCLB data to ADCLB_TEMP register
- MOVR ADCHB,A
- MOVAR ADCHB_TEMP //Move ADCHB data to ADCHB_TEMP register
- GOTO int_exit
-
- ;=====================================================================
- ;=====================================================================
- CLEAR_RAM:
- MOVIA 040H
- MOVAR FSR
-
- CLEAR_LOOP:
- CLRR INDF
- MOVIA 07FH
- XORAR FSR,A
- BTRSC STATUS,Z_B
- RETURN
- INCR FSR,R
- GOTO CLEAR_LOOP
-
- ;=====================================================================
- ;=====================================================================
- RESET_INIT:
- CLRR INTEN
- CLRR INTFLAG
- CLRR PAIE
- CLRR PBIE
- RETURN
- ;=====================================================================
- ;=====================================================================
复制代码 |
|