⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.s

📁 该文件包含30F的电机控制程序
💻 S
字号:
;START_HEADER
;
; dsPIC30F6014 Demo Source File
; (c) Copyright 2005 Microchip Technology, All rights reserved
;
; --------------------------------------------------------------------------
; File Revision History:
; --------------------------------------------------------------------------
;
; $Log: main.s,v $
; Revision 1.4  2005/04/04 23:43:31  VasukiH
; Updates to comments in file header
;
; Revision 1.3  2005/04/04 23:14:58  VasukiH
; Updates for MPLAB C30 v1.30 compatiblity
;
; Revision 1.2  2003/11/04 02:35:28  VasukiH
; This release will function on dsPIC30F6014 Rev A2 devices (not 6001)
;
; Revision 1.1.1.1  2003/08/23 00:38:32  VasukiH
; First import of demo source into CVS Repository
;
;
;
; --------------------------------------------------------------------------
;
; Software and Development Tools Info:
; --------------------------------------------------------------------------
; Tool                          Version
; --------------------------------------------------------------------------
; MPLAB IDE                     7.0
; MPLAB C30 Toolsuite           1.30
; dsPICDEM(TM) Processor Board  1.10
; --------------------------------------------------------------------------
;
; File Notes:
; 1. This file contains the "_main" routine. The run-time C start-up library
;    will bring code execution to the label "_main" after initializing
;    data RAM.
; 2. All peripheral initialization routines are called in this file.
;    To understand what functions the peripherals will perform in this demo
;    please see headers and comments in the associated peripheral init_ files.
;
;END_HEADER



.include        "p30fxxxx.inc"
.include        "common.inc"


;In future these Macros will be supported under MPLAB IDE framework
;Macros to load configuration fuse bits in MPLAB IDE for ICD2/Pro Mate II
;Note: If using ICD2 as a Debugger, ensure that the "Background Debug"
;      fuse has been set from the "Configuration Bits" window in MPLAB

config          __FOSC, CSW_FSCM_OFF & XT_PLL4

config          __FWDT, WDT_OFF

config          __FBORPOR, PBOR_OFF & MCLR_EN
config          __FGS, CODE_PROT_OFF



.extern         _Diagnostics

.global         _main
.section        .text

_main:                                          ;C-run-time library brings you here

        bset    INTCON2, #ALTIVT                ;Enable Alternate Interrupt Vector Table
                                                ;in preparation for diagnostics.

        bset    TRISA, #TRISA12                 ;Set Port A pin RA12 as an input so that
                                                ;Switch S1 input can be accepted.
        btss    PORTA, #RA12                    ;On Power-up check if Diagnostic services
        rcall   _Diagnostics                    ;are being requested by the user. If so,
                                                ;call the Diagnostic routine.
                                                ;Diagnostics are requested by depressing switch
                                                ;S1 during power-up.
        bclr    INTCON2, #ALTIVT                ;If no diagnostics, then revert to processing
                                                ;main vector table.


        rcall   _init_port                      ;Configure any port pins to be used for GPIO



        rcall   _init_dci_master                ;Configure Data Converter Interface module for
                                                ;communication with Si3000 Codec
                                                ;DCI module is the Master
        rcall   _init_codec_slave               ;Initialize Codec as slave for framed
                                                ;multi-channel communication with DCI


        rcall   _init_adc12_A                   ;Configure 12-bit A/D converter converting
                                                ;input on pin AN3



        rcall   _init_timer1_16b                ;Configure 16-bit General Purpose Timer - Timer1
                                                ;used to provide sampling rate timing for Sinusoid
                                                ;generation

        rcall   _init_timer2_16b                ;Configure 16-bit General Purpose Timer - Timer2
                                                ;to time-out at 1 second and interrupt the CPU


        rcall   _init_timer3_16b                ;Configure 16-bit General-Purpose Timer
                                                ;- Timer 3


        rcall   _init_timer45_32b               ;Configure 32-bit General-Purpose Timer
                                                ;- Timer5:Timer4


                                                ;Configure Serial Peripheral Interface module - SPI2
        rcall   _init_spi2_A                    ;Initialize SPI2 as Master for LCD control
        rcall   _sub_reset_lcd_controller       ;Reset LCD Controller
        rcall   _sub_lcd_menu_disp              ;Display Welcome Message on LCD via SPI2


                                                ;Configure UART module - UART2
        rcall   _init_uart2                     ;Initialize UART to 57.6 Kbaud
        rcall   _sub_power_on_uart_display      ;Display Power-On Message via UART2



;Wait for User to press switch S1 on the Expansion Board
wait1:
        btsc    PORTA, #RA12
        bra     wait1


        clr     SwitchPress                     ;Clear all menu selection flag bits
        bset    SwitchPress, #0x1

        rcall   _init_int_pins                  ;Configure external interrupt pins

        bset    ADCON1, #ADON                   ;Turn on A/D

        bset    T3CON, #TON                     ;Turn on Timer3

main_loop:
        clr     TMR1                            ;Clear Timer1


        bset    T1CON, #TON                     ;Start Timer1
wait2:  btss    ADCDataAvailable, #0            ;Has ADC collected 256 samples from pin AN3?
        bra     wait2                           ;If not then wait!
        bclr    T1CON, #TON                     ;Else stop Timer1 (stops Sine wave generation)


        rcall   _sub_process_adcsamples         ;Process the 256 samples collected from the ADC

        bra     main_loop                       ;Loop to "main_loop"



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                                                                    ;
;                       Software License Agreement                   ;
;                                                                    ;
;   The software supplied herewith by Microchip Technology           ;
;   Incorporated (the "Company") for its dsPIC controller            ;
;   is intended and supplied to you, the Company's customer,         ;
;   for use solely and exclusively on Microchip dsPIC                ;
;   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.  ;
;                                                                    ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;





.end                                            ;EOF





⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -