📄 main.asm
字号:
;***********************************************************************
; File Name: TMS320x240 Example Code
; Date:24/11/03
; Originator:jzming
; Tianhuang technology dsp development group.
; Description: this program use spwm to contol the three-phase asm-motor.
; Control mode: v/f control ,pwm frequency:20khz
; The system uses the key to control the speed:
; IOPB4---->"START"; IOPB5---->"STOP"; IOPB6---->"+";IOPB7---->"-".
; Control varies: frequency-->freqstep, voltage-->vf_cmp1,vf_cmp2,vf_cmp3.
; Resource: intertupt:sine-->int2
;
;***********************************************************************
.include "x24x.h"
;-----------------------------------------------------------------------
table .usect ".blk0",1
toptable .usect ".blk0",1
comparet1 .usect ".blk0",1
freqstep .usect ".blk0",1
vf_freq .usect ".blk0",1
ad_res_0 .usect ".blk0",1
ad_res_1 .usect ".blk0",1
p_counter .usect ".blk0",1
modreg .usect ".blk0",1
sineval .usect ".blk0",1
b_sadd .usect ".blk0",1
c_sadd .usect ".blk0",1
vf_cap .usect ".blk0",1
vf_cen .usect ".blk0",1
vf_cmp1 .usect ".blk0",1
vf_cmp2 .usect ".blk0",1
vf_cmp3 .usect ".blk0",1
count .usect ".blk0",1 ;read the key number which pressed
count1 .usect ".blk0",1 ;temp register
count2 .usect ".blk0",1 ;temp register
yjax_flag .usect ".blk0",1 ;set the yjax flag
count_h .usect ".blk0",1 ;high num of the led (dec)
count_l .usect ".blk0",1 ;low num of the led (dec)
count_hl .usect ".blk0",1 ;V/F control register
option .usect ".blk0",1
start_key .usect ".blk0",1
comm_flag .usect ".blk0",1 ;the serial_comm control flag
add_var .usect ".blk0",1 ;the add variables(use to serial_comm)
sub_var .usect ".blk0",1 ;the substruct variables(use to serial_comm)
add_var_h .usect ".blk0",1
add_var_l .usect ".blk0",1
add_temp .usect ".blk0",1
add_cen .usect ".blk0",1
add_pn .usect ".blk0",1
LED0_LED1 .usect ".blk0",1
LED0 .usect ".blk0",1 ;display (lowest bits)
LED1 .usect ".blk0",1
LED2 .usect ".blk0",1
LED3 .usect ".blk0",1
TEMP .usect ".blk0",1 ;temporary register
*-----------------------------------------------------------------------
; Context
;-------------------------------------------------------------------
ST0 .set 0
ST1 .set 1
ST0_save .set 060h ; saved status register ST0
ST1_save .set 061h ; saved status register ST1
ACCH .set 062h ; saved accumulator high
ACCL .set 063h ; saved accumulator low
AR0_save .set 064h ; saved AR0 content
AR1_save .set 065h ; saved AR1 content
P_hi .set 066h ; saved P high byte
P_lo .set 067h ; saved P low byte
T_save .set 068h ; saved T content
;-----------------------------------------------------------------------
.bss GPR0,1 ;General purpose register.
;=======================================================================
.global _c_int0,
.ref sys_int,
.def sine,PHANTOM
t1compare .set 0
t1period .set 1000
normal .set 500
b_phase .set 170
c_phase .set 85
;=======================================================================
; C O D E - starts here
;=======================================================================
.text
_c_int0:
LDP #00E0h
SPLK #006Fh, WDCR ;disable watchdog w/max. overflow
KICK_DOG ;Reset watchdog counter
;
CALL sys_int ;
;
CALL init_pwm
CALL start_pwm
call main_prog
CLRC INTM
;----------------------------------------------------------------------
ini
ldp #04h
lacl comm_flag
sub #01h
bcnd comm_loop,eq
;-------------- key control main part --------------------------------
main_loop
ldp #04h
splk #00h,yjax_flag ;clear the yjax_flag
nop
call jpan ;call the jpan sub_program
lacc yjax_flag ;decide if some key pressed
sub #01h
bcnd main_loop,neq ;no?
ldp #04h ;decide if "start" key?
lacc count
sub #10h
bcnd main_loop,neq ;no?
turn_on ;"start" key
call _co ;send #01h to the PC
lacl #31h
SACL SCITXBUF
ldp #04H
SPLK #0H,LED0
SPLK #0H,LED1
SPLK #0fH,LED2
SPLK #1H,LED3
SETC INTM
CALL DIS
CLRC INTM
turn1
ldp #04h
splk #00h,yjax_flag ;clear the yjax_flag
nop
call jpan ;call the jpan sub_program
lacc yjax_flag ;decide if some key pressed
sub #01h
bcnd other_key,eq ;yes
KICK_DOG
b turn1
other_key
ldp #04h
lacc count
sub #40h ;"+" key?
bcnd up_butn,eq
lacc count
sub #80h ;"-" key
bcnd dn_butn,eq
lacc count
sub #20h ;"stop" key
bcnd cut_off,eq
b turn1
up_butn ;"+" button-->IOPB6
ldp #04h
lacc count_h ;dicide if the count_h'number equal 6
sub #6
bcnd led_max,eq ;yes,jump led_max
lacc count_l
sub #9
bcnd led_jinwei,eq
add #9
sacl count_l
LACC count_l ; count_l +1
ADD #1
SACL count_l
b xunhuan
led_jinwei ;if count_l=9,then led_jinwei
ldp #04h
splk #0,count_l
lacc count_h ;increase the count_h
add #1
sacl count_h
lacc count_h
sub #6
bcnd led_max,eq ;if=6,then led_max
add #6 ;restore
sacl count_h
b xunhuan
led_max ;the maxim desplayed(60)
ldp #04h
splk #0,count_l
splk #6,count_h
b xunhuan
dn_butn ;decrease button:IOPB7
ldp #04h
lacc count_l
bcnd dn_next1,eq ;decide if it's "00"
b dn_next2
dn_next1
lacc count_h
bcnd led_min,eq
dn_next2 ;jiewei
lacc count_l
bcnd led_jiewei,eq
sub #1
sacl count_l
b xunhuan
led_jiewei
ldp #04h
splk #9,count_l
lacc count_h
sub #1
sacl count_h
b xunhuan
led_min ;the minimum displayed
ldp #04h
splk #0,count_l
splk #0,count_h
b xunhuan
cut_off
call _co ;Send the #02h to PC,then return the ini configure
lacl #32h
SACL SCITXBUF
ldp #04h
SPLK #0FH,LED0
SPLK #0FH,LED1
SPLK #0FH,LED2
SPLK #0FH,LED3
splk #0,count_h
splk #0,count_l
SETC INTM
CALL DIS
CLRC INTM
b ini
xunhuan ;displayed based on led_table
ldp #04h
lacc count_h
and #0fh
SACL LED1
lacc count_l
and #0fh
SACL LED0
SETC INTM
CALL DIS
call _co ;Send the display value to the PC
ldp #04h
LACC LED1,4
OR LED0
LDP #0E0H
SACL SCITXBUF
CLRC INTM
sfjx
LDP #0E0H
SPLK #006FH,WDCR
KICK_DOG ;delay intervel
; call pjsf
; bcnd sfjx,neq
mar *,ar2 ;
lar ar2,#500h ;change the display speed
ysjg
KICK_DOG
call delay_time
banz ysjg
B turn1 ; End of background loop
jpan
clrc tc ;the main key program
ldp #0e1h
lacc PBDATDIR
cmpl
and #0ffh
ldp #04h
sacl count1
lacl count1
lar ar0,count1
bcnd yjaxm,neq
b jpan
yjaxm ;back wobble
SETC INTM
call delay_time
call delay_time
CLRC INTM
ldp #0e1h
lacc PBDATDIR
cmpl
and #0ffh
ldp #04h
sacl count2
lacc count2
lar ar1,count2
bcnd yjax,neq
b jpan
yjax
;
ldp #04h
mar *,AR1
cmpr 00
bcnd jpan,ntc
sar ar0,count
splk #01h,yjax_flag ;set yiax flag
ret
;pjsf
; ldp #0e1h
; lacc PBDATDIR
; cmpl
; and #0ffh
; ret
;---------------------------------------------------------------------------------
;---------------the serial_comm main loop-----------------------------------------
comm_loop
ldp #04h
splk #0h,add_var
splk #0h,add_cen
splk #0h,sub_var
call _ci
LACL SCIRXBUF ; else, load ACCL with character received
AND #00FFh ; mask unsignificant bits in ACC
ldp #4
sacl start_key
lacl start_key
sub #31h ; is it start key ? (PC<-->01H)
bcnd key_con,neq ; if not branch to key_con
call _co ; Send the same value to the PC
ldp #04h
lacl start_key
LDP #0E0H
SACL SCITXBUF
B start_loop
key_con
ldp #04h ;if recesive #00h,then jump to the main_loop
lacl start_key
sub #30h
bcnd comm_loop,neq
b main_loop
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
start_loop ;start key
ldp #04H
SPLK #0H,LED0
SPLK #0H,LED1
SPLK #0fH,LED2
SPLK #1H,LED3
SETC INTM
CALL DIS
CLRC INTM
start_loop1
call _ci
lacl SCIRXBUF
and #00ffh ;only 8 bits !!!
ldp #04h ;if yes, get it and store it in option
sacl option
lacl option
sub #32h ;(PC<-->02H)
bcnd notstop_key,neq
call _co
ldp #04h
lacl option
LDP #0E0H
SACL SCITXBUF
;-------------------------------------------------------------------------------
stop_key
ldp #04h ;point to variables
splk #0,count_h
splk #0,count_l
SPLK #0FH,LED0
SPLK #0FH,LED1
SPLK #0FH,LED2
SPLK #0FH,LED3
SETC INTM
CALL DIS
CLRC INTM
b comm_loop
;-------------------------------------------------------------------------------
notstop_key
ldp #04h
lacc option
sub #33h ;(<PC-->03H)
bcnd notadd_key,neq
call _co
ldp #04h
lacl option
LDP #0E0H
SACL SCITXBUF
;-------------------------------------------------------------------------------
add_key ;add key
setc intm
ldp #04h
lacl add_var
add #1
sacl add_var
sacl add_temp
call hex_bcd
ldp #04h
lacl add_var_h
sub #06h
bcnd yichu,geq
lacl add_var_h
sacl LED1
lacl add_var_l
sacl LED0
add_xun
lacl LED0
sacl count_l
lacl LED1
sacl count_h
CALL DIS
clrc intm
B start_loop1
yichu
splk #06h,LED1
splk #00h,LED0
splk #60,add_var
b add_xun
;--------------------------------------------------------------------------------
notadd_key
ldp #04h
lacc option
sub #34h ;(PC<-->04H)
bcnd notsub_key,neq
call _co
ldp #04h
lacl option
LDP #0E0H
SACL SCITXBUF
;--------------------------------------------------------------------------------
sub_key ;substract key
setc intm
ldp #04h
lacl add_var
sub #00h
bcnd sub_yichu,eq
sub #01h
sacl add_var
sacl add_temp
call hex_bcd
lacl add_var_l
sub #0
bcnd sub_yichu,lt
lacl add_var_h
sacl LED1
lacl add_var_l
sacl LED0
sub_xun
lacl LED0
sacl count_l
lacl LED1
sacl count_h
CALL DIS
clrc intm
B start_loop1
sub_yichu
splk #00h,LED0
splk #00h,LED1
splk #00h,add_var
b sub_xun
;-------------------------------------------------------------------------------
notsub_key
b start_loop1 ;query other keys pressed
;---------------------------------------------------------------------------------
;--------------------- END SERIAL_COMM ---------------------------------------
;================================================================================= ;beginning and continue.
init_pwm:
LDP #0e8h
SPLK #666H,ACTR ;
SPLK #01E0H,DBTCON
SPLK #0207H,COMCON
SPLK #08707H,COMCON
SPLK #t1period,T1PR ;set the pwm frequency=20kHZ
SPLK #0000H,T1CNT
SPLK #0000H,T2CNT
SPLK #0000H,T3CNT
SPLK #2802h,T1CON
SPLK #0000000000000000b,T2CON
SPLK #0000000000000000b,T3CON
SPLK #t1compare,CMPR1
SPLK #t1compare,CMPR2
SPLK #t1compare,CMPR3 ;
LDP #0e8h
LACC GPTCON ; General-purpose timer control register
OR #0080H ; mask for enabling ADC start on GPT1
AND #0FFFFH ; mask for enabling ADC start on GPT1 Period Event
SACL GPTCON ; seting T1 period interrupt flag, set T1 period interrup flag
; to start A/D conversion
RET
;====================================================================================
start_pwm:
; enable T1 timer operations
LDP #0e8h
LACL T1CON
OR #40h,0
SACL T1CON
LDP #0h
LACL IMR
OR #02h,0
SACL IMR ;set IMR bit2
LDP #0e8h
splk #0ffffh,EVIFRA
SPLK #0080H,EVIMRA
RET
;------------------------------------------------------------------------------------
main_prog:
ldp #4h
splk #00h,table
splk #stable,toptable
; splk #3FFH,freqstep
splk #00h,modreg
LDP #0E1H
LACL OCRA ;configure the I/O port
AND #0FFh
SACL OCRA
SPLK #0F0H,OCRB
LACL OCRB
AND #3FH
SACL OCRB ;configure the iopc6/iopc7 general I/O
SPLK #0000H,PADATDIR ;set the PB as input
SPLK #00FFH,PBDATDIR
SPLK #0C0FFH,PCDATDIR ;configure the iopc6/iopc7 as output
* Serial communication initialization
***********************************************************
ldp #0E0H
splk #0017h,SCICCR ;one stop bit, no parity, 8bits
splk #0013h,SCICTL1 ;enable RX, TX, clk
splk #0022h,SCIPC2 ;I/O setting
splk #0000h,SCICTL2 ;disable SCI interrupts
splk #0000h,SCIHBAUD ;MSB |
splk #0081h,SCILBAUD ;LSB |19200 Baud for sysclk 10MHz
LDP #0E0H
LACL SCICTL1
OR #0020H
SACL SCICTL1
; splk #0033h,SCICTL1 ;end initialization
***********************************************************
ldp #04h ;point to variables
splk #0,add_var
splk #0,sub_var
splk #0,add_var_h
splk #0,add_var_l
splk #0,add_cen
splk #0h,add_pn
splk #01h,comm_flag
splk #0,count_h
splk #0,count_l ;initialize the display
SPLK #15,LED0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -