在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 4769|回复: 3

[资料] FM8PC 实验代码分享

[复制链接]
发表于 2015-11-3 07:59:05 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x




  1. ;==============================================================================
  2. ; FEELING TECHNOLOGY CORP.
  3. ;==============================================================================                        
  4. ;IC     : FM8PC71A
  5. ;cpuCLK : 1 MHz
  6. ;WDT    : Disable                                                                                                                        

  7. ;------------------------------------------------------------------------------
  8. ;MODIFY BY     : KL Lai                                                                              
  9. ;DATE          : 2011-0905
  10. ;VER           : 1.00                                                                        
  11. ;------------------------------------------------------------------------------
  12.                   
  13. #include   "C71AS_define.ash"                             
  14.                  
  15. SEL_CPUCLK_DELAY    EQU    01D  ; 1=1MHz , 2=2MHz , 4=4MHz , 8=8MHz , 16=16MHz                                                                       
  16.                                                                                        
  17. ;=====================================================================                              
  18. ;-------------------------- ROM Areas --------------------------------                                    
  19. ;=====================================================================
  20.                                                                                                    
  21.                 ORG     000H                                                                        
  22.                 GOTO    reset                                                   
  23.                                                                         
  24.                 ORG     003H         
  25.                                          
  26. ;---------------------------------------------------------------------
  27. INT_VECTOR:                                                
  28.                 MOVAR   INTACCTMP               ;Push Stack           
  29.                 SWAPR   STATUS,A                             
  30.                 MOVAR   INTSTATMP               
  31.                 MOVR    EFR_1,A
  32.                 MOVAR   INTEFR1TMP            
  33.                  
  34.                 BCR     EFR_1,ROMBK_B           ;ROM BANK0
  35.                 BCR     EFR_1,RAMBK_B           ;RAM BANK0
  36.                                                      
  37.                 BTRSC   intflag,paif_b                                
  38.                 GOTO    paitask                 ;porta   
  39.                                           
  40.                 BTRSC   intflag,pbif_b
  41.                 GOTO    pbitask                 ;portb            
  42.                                              
  43.                 BTRSC   PWM0CR,P0TMIF_B      
  44.                 GOTO    PWM0Itask               ;PWM0
  45.                               
  46.                 BTRSC   PWM1CR,P1TMIF_B
  47.                 GOTO    PWM1Itask               ;PWM1
  48.                
  49.                 BTRSC   PWM2CR,P2TMIF_B
  50.                 GOTO    PWM2Itask               ;PWM2
  51.                
  52.                 BTRSC   PWM3CR,P3TMIF_B           
  53.                 GOTO    PWM3Itask               ;PWM3
  54.                                        
  55.                 BTRSC   ADCON_2,ADCIF_B
  56.                 GOTO    ADCItask                ;ADC                                                      
  57.                  
  58.                                              
  59. int_exit:               
  60.                 MOVR    INTEFR1TMP,A            ;Pop Stack
  61.                 MOVAR   EFR_1
  62.                 SWAPR   INTSTATMP,A            
  63.                 MOVAR   STATUS                           
  64.                 SWAPR   INTACCTMP,R
  65.                 SWAPR   INTACCTMP,A   
  66.                 RETFIE               

  67. ;=====================================================================
  68. ;------------------ Main Programme Beginning -------------------------
  69. ;=====================================================================

  70.                                                                                                 
  71.                            
  72. ;=====================================================================
  73. ;=====================================================================

  74. ; Variable : m=Low-byte , n=High-byte
  75. ; Delay Time = n*256*40us + (m+1)*40us   
  76. ; The Min. delay time = 40us , the Max. delay time = 2631680us = 2631.68ms

  77. FM_Delay_40us   MACRO n,m
  78.                              
  79.     movia   m
  80.     movar   DlyCnt_L
  81.     movia   n
  82.     movar   DlyCnt_M
  83.                                     
  84.     CALL    F_Dec_counter_40us     ;6 cycles

  85. ENDM

  86. ;--------------------------------------------------
  87.                      
  88. FC_delay_40us:                     
  89.                                  
  90. if SEL_CPUCLK_DELAY=01D
  91.    call    Eight_Cycle
  92.    call    Four_Cycle
  93. endif
  94.                           
  95. if SEL_CPUCLK_DELAY=02D
  96.    call    Sixteen_Cycle
  97.    call    Sixteen_Cycle
  98. endif
  99.                      
  100. if SEL_CPUCLK_DELAY=04D
  101.    call    Eight_Cycle
  102.    call    Sixteen_Cycle
  103.    call    Sixteen_Cycle
  104.    call    Sixteen_Cycle
  105.    call    Sixteen_Cycle
  106. endif

  107. if SEL_CPUCLK_DELAY=08D
  108.    movia   007h
  109.    movar   DlyCnt_temp   
  110.    call    Sixteen_Cycle
  111.    nop
  112.    decrsz  DlyCnt_temp,r
  113.    goto    $-3                 ;20
  114.    nop              
  115.    call    Eight_Cycle
  116. endif

  117. if SEL_CPUCLK_DELAY=16D   
  118.    movia   00fh
  119.    movar   DlyCnt_temp  
  120.    call    Sixteen_Cycle
  121.    nop                    
  122.    decrsz  DlyCnt_temp,r      
  123.    goto    $-3                 ;20
  124.    nop
  125.    call    Eight_Cycle                          
  126. endif
  127.               
  128. F_Dec_counter_40us:   
  129.    movia   0xFF   
  130.    addar   DlyCnt_L,r
  131.    btrsc   status,0
  132.    incr    DlyCnt_M,r
  133.    addar   DlyCnt_M,r
  134.    btrsc   status,0   
  135.    goto    FC_delay_40us              ;8 cycles

  136. F_exit_delay_40us:                   ;7 cycles        
  137.                                      ;counter overflow

  138. if SEL_CPUCLK_DELAY=01D
  139.    nop
  140.    goto    $+1
  141.    goto    $+1   
  142. endif                                    
  143.                                     
  144. if SEL_CPUCLK_DELAY=02D
  145.    nop
  146.    call    Eight_Cycle
  147.    call    Sixteen_Cycle   
  148. endif

  149. if SEL_CPUCLK_DELAY=04D
  150.    nop
  151.    call    Sixteen_Cycle
  152.    call    Sixteen_Cycle
  153.    call    Sixteen_Cycle
  154.    call    Sixteen_Cycle                 
  155. endif

  156. if SEL_CPUCLK_DELAY=08D
  157.    movia   007h
  158.    movar   DlyCnt_temp   
  159.    call    Sixteen_Cycle
  160.    nop
  161.    decrsz  DlyCnt_temp,r
  162.    goto    $-3                 ;20
  163.    goto    $+1
  164.    goto    $+1         
  165. endif

  166. if SEL_CPUCLK_DELAY=16D
  167.    movia   00fh
  168.    movar   DlyCnt_temp  
  169.    call    Sixteen_Cycle
  170.    nop
  171.    decrsz  DlyCnt_temp,r
  172.    goto    $-3                 ;20
  173.    goto    $+1
  174.    goto    $+1        
  175. endif     
  176.    RETURN                           


  177. Sixteen_Cycle:   
  178.               goto $+1
  179.               goto $+1
  180.               goto $+1
  181.               goto $+1
  182. Eight_Cycle:   
  183.               goto $+1
  184.               goto $+1                        
  185.               RETURN

  186. Four_Cycle:                          
  187.               RETURN              
  188. ;---------------------------------------------------------------------               
  189. ;---------------------------------------------------------------------
  190. ; Variable : n
  191. ; Delay Time ~= n*100ms
  192. ; The Min. delay time = 0ms , the Max. delay time = 25500ms = 25.5s
  193. ; パ?Delay?丁耕?, ??ぃ暗弘絋?璸衡

  194. FM_Delay_ms   MACRO n
  195.             
  196.              movia   n
  197.              movar   DlyCnt_H
  198.              movr    DlyCnt_H,A
  199.              btrsc   status,2
  200.              goto    $+9                       ;If counter=0 , exit count

  201. ;Dec_counter_ms:
  202.              clrwdt                        
  203.              movia   195d
  204.              movar   DlyCnt_L
  205.              movia   009d
  206.              movar   DlyCnt_M                  
  207.              CALL    FC_delay_40us              ;100ms                                            
  208.              decrsz  DlyCnt_H,R
  209.              goto    $-7                       ;Dec_counter_ms
  210.                                                                           
  211. ;exit_delay_ms:        
  212.                      
  213. ENDM                                                      
  214.                                                                                                                     
  215. ;=====================================================================                                 
  216. ;=====================================================================                                                
  217.                                                       
  218.                                     
  219. reset:                                                                                                   
  220.              NOP
  221.              NOP
  222.              NOP
  223.              clrwdt                     
  224.                                       
  225.              BCR       WDT,WDTE_B               //Disable Watch dog timer           
  226.              NOP                                          
  227.              NOP
  228.                                                                                                                                                          
  229.              CALL      CLEAR_RAM                                                                             
  230.                                                                         
  231.              CALL      RESET_INIT                                                                       
  232.                                                                  
  233.              CALL      IO_INITIAL     
  234.                                                                                                                                                                                                                                                                                                                                                                                     
  235.              CALL      ADC_CON_INITIAL                                                      
  236.             
  237.              FM_Delay_ms    2           ;DELAY 200MS   
  238.                                                                   
  239.              NOP   
  240.              NOP                                                        
  241.                            
  242.                                  
  243. MAIN_LOOP:                                                
  244.              CLRWDT
  245.              NOP
  246.              NOP                                                                                 
  247.              NOP                                                                                 
  248.              CALL      GET_ADC_DATA            //Polling ADC conversion has completed ?            
  249.              NOP
  250.              NOP
  251.              NOP                                       
  252.              GOTO      MAIN_LOOP                                


  253.                                                       
  254.             
  255. ;-----------------------------------------------------------
  256. GET_ADC_DATA:                                                                                                               
  257.              BSR       ADCON_1,ADCST_B         //Start to ADC sample, when ADC is trigger mode.
  258.                                     
  259.              BTRSC     ADCON_1,ADCST_B            
  260.              GOTO      $-1              
  261.              NOP
  262.              NOP
  263.              MOVR      ADCLB,A
  264.              MOVAR     ADCLB_TEMP            //Move ADCLB data to ADCLB_TEMP register
  265.              MOVR      ADCHB,A  
  266.              MOVAR     ADCHB_TEMP            //Move ADCHB data to ADCHB_TEMP register                                                
  267.              RETURN                                                                                               
  268. ;-----------------------------------------------------------                                            
  269.                                                   








  270. ;=====================================================================
  271. ;=====================================================================                                                                                                              
  272. ADC_CON_INITIAL:
  273.              BSR       ADCON_1,CHSEL0_B        //ADC input channel is PB1  
  274.              BCR       ADCON_1,CHSEL1_B        
  275.              BCR       ADCON_1,CHSEL2_B
  276.                                                                      
  277.              BCR       ADCON_1,ADCSR0_B
  278.              BCR       ADCON_1,ADCSR1_B        //ADC clock is Fcpu/8   
  279.                                                                            
  280.              BCR       ADCON_2,SVREFH_B        //Internal VREFH  
  281.                                                                                                      
  282.              BCR       ADCON_2,ADCNT_B         //Trigger mode
  283.                                                                      
  284.              BCR       ADCON_2,DACOEN_B        //Disable DAC output to PB3                          
  285.              BSR       ADCON_2,ADCTMS_B        //Fixed convert timing
  286.              BCR       ADCON_2,ADCIF_B         //Clear ADC completed flag
  287.              BCR       ADCON_2,ADCIE_B         //Disable ADC interrupt
  288.                                                                     
  289.              BSR       ADCON_2,SELVER0_B        
  290.              BSR       ADCON_2,SELVER1_B       //Internal VREFH = 2V
  291.             
  292.              BSR       ADCON_1,ADCEN_B         //Enable ADC
  293.              RETURN         


  294. ;=====================================================================
  295. ;=================== I/O Mode Setting ================================
  296. ;=====================================================================                                         
  297. IO_INITIAL:
  298.              MOVIA     00000000B
  299.              IOST      PAMODE0         
  300.              MOVIA     11111111B              
  301.              IOST      PAMODE1
  302.               
  303.              MOVIA     0FFH
  304.              MOVAR     PORTA
  305.                               
  306.              MOVIA     00000000B  
  307.              IOST      PBMODE0
  308.              MOVIA     11101101B               //PB1, PB4 are input mode
  309.              IOST      PBMODE1                 //Because PB1 as AIN pin ,PB4 as VREFH pin
  310.                                                                            
  311.              MOVIA     0FFH                          
  312.              MOVAR     PORTB     
  313.             
  314.              FM_Delay_40us   000D,049D         //Delay 2 ms
  315.                              
  316.              RETURN
  317.                           
  318.                                  
  319. ;=====================================================================
  320. ;=====================================================================                 
  321. paitask:                                      
  322.             BCR        INTFLAG,PAIF_B  
  323.             GOTO       int_exit
  324.                                 
  325. pbitask:                           
  326.             BCR        INTFLAG,PBIF_B  
  327.             GOTO       int_exit
  328.                        
  329. PWM0Itask:                                                   
  330.             BCR        PWM0CR,P0TMIF_B   
  331.             GOTO       int_exit                                 
  332.                                     
  333. PWM1Itask:                                                   
  334.             BCR        PWM1CR,P0TMIF_B
  335.             GOTO       int_exit
  336.                                                                                                                     
  337. PWM2Itask:                                                   
  338.             BCR        PWM2CR,P2TMIF_B   
  339.             GOTO       int_exit                                 
  340.                                     
  341. PWM3Itask:                                                   
  342.             BCR        PWM3CR,P3TMIF_B
  343.             GOTO       int_exit
  344.                        
  345. ADCItask:                          
  346.             BCR        ADCON_2,ADCIF_B
  347.             NOP
  348.             NOP
  349.             MOVR       ADCLB,A
  350.             MOVAR      ADCLB_TEMP            //Move ADCLB data to ADCLB_TEMP register
  351.             MOVR       ADCHB,A  
  352.             MOVAR      ADCHB_TEMP            //Move ADCHB data to ADCHB_TEMP register
  353.             GOTO       int_exit   
  354.                                                       
  355. ;=====================================================================
  356. ;=====================================================================   
  357. CLEAR_RAM:
  358.             MOVIA      040H
  359.             MOVAR      FSR                     
  360.                              
  361. CLEAR_LOOP:                          
  362.             CLRR       INDF
  363.             MOVIA      07FH  
  364.             XORAR      FSR,A               
  365.             BTRSC      STATUS,Z_B   
  366.             RETURN               
  367.             INCR       FSR,R         
  368.             GOTO       CLEAR_LOOP
  369.                                                 
  370. ;=====================================================================
  371. ;=====================================================================
  372. RESET_INIT:                 
  373.             CLRR       INTEN  
  374.             CLRR       INTFLAG   
  375.             CLRR       PAIE
  376.             CLRR       PBIE                             
  377.             RETURN                                         
  378. ;=====================================================================
  379. ;=====================================================================



复制代码
发表于 2015-12-4 21:55:01 | 显示全部楼层
此帖仅作者可见
发表于 2015-12-29 16:32:42 | 显示全部楼层
此帖仅作者可见
发表于 2016-1-1 11:00:37 | 显示全部楼层
此帖仅作者可见
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /1 下一条

关闭

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-3-29 18:11 , Processed in 0.022277 second(s), 9 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表