📄 50_60hz模拟.asm
字号:
;*********************************************************************************
;Process:定义 **
;IC:SN8P2501A **
; **
; ┌──┐┌──┐ **
; SCAS2 I/O P2.2 ┤1 └┘ 14├ P2.3 SCAS3 O **
; SCAS1 I/O P2.1 ┤2 13├ P2.4 SCAS4 O **
; SCAS0 I/O P2.0 ┤3 12├ P2.5 SCAS5 O **
; VDD ┤4 11├ VSS **
; XIN/P1.3 ┤5 10├ P0.0/INT0 ON/OFF I **
; XOUT/P1.2 ┤6 9├ P1.0 TESET I **
; VPP/RST/P1.1 ┤7 8├ P5.4/PWM0/BZ0 MOTOR OUT O **
; └──────┘ **
; SN8P2501A (OTP) **
; **
;Attention: P1.1 only used for input port **
;*********************************************************************************
;===========================================================
CHIP SN8P2501b
//{{SONIX_CODE_OPTION
.Code_Option LVD LVD_H ; 2.4V Reset Enable LVD36 bit of PFLAG for 3.6V Low Voltage Indicator
.Code_Option Reset_Pin P11
.Code_Option Watch_Dog Enable
.Code_Option High_Clk 4M_X'tal ; Crystal/Resonator: 2Mhz~10Mhz'
.Code_Option Fcpu #2 ; Fcpu = Fosc/4
.Code_Option Security Enable
.Code_Option Noise_Filter Disable
//}}SONIX_CODE_OPTION
;===========================================================
include SONIXMACRO.INC
.data
pflag_buff ds 1
mode_select ds 1 ;模式全局变量
mode_select_sub ds 1 ;子模式局部变量
shred_speed_50 ds 1 ;shred模式速寄存器 50%
mix_speed_70 ds 1 ;miz模式速寄存器 70%
blend_speed_80 ds 1 ;blend模式速寄存器 80%
liquefy_speed_90 ds 1 ;liquefy模式速寄存器 90%
flag ds 1
flag_1 ds 1
key_value ds 1 ;键值全局变量
acc_buff ds 1 ;acc 缓冲
speed_temp ds 1 ;控制速度变量
speed_load ds 1 ;速度变量暂存
timer_buff ds 1 ;定时累加用暂存
speed_zero ds 1 ;零速
timer_20ms ds 1 ;10ms累加用暂存
timer_8_3ms ds 1 ;8.3ms累加用暂存
test_0 ds 1 ;交流负半周,测试交流电翻转用,
test_1 ds 1 ;交流正半周,测试交流电翻转用,
mode_loop ds 1 ;模式循环用
key_value_buf ds 1 ;键值暂存
key_cnt ds 1 ;键计数器,消抖用
.code
;===========================================================
;io define
p_scas0 equ p2.0
p_scas1 equ p2.1
p_scas2 equ p2.2
p_scas3 equ p2.3
p_scas4 equ p2.4
p_scas5 equ p2.5
p_on_off equ p0.0 ;on/off开关 in
p_test equ p1.0 ;交流相位检测 in
p_motor_out_ equ p5.4 ;低有效
;===========================================================
;标致位定义
flag_1ms equ flag.0 ;2ms标致位 1=2ms到
flag_10ms equ flag.1 ;20ms标致位 1=20ms到
flag_20ms equ flag.2
flag_50hz equ flag.3 ;1=50hz,0=60hz
flag_full equ flag.4 ;全速运行标致
;=======================================>>>>>>>>>>>>>>>>
;Name :RAM初始化子程序
;Function:
;Input :
;Output :
;Register Used:
;*************************************************
ORG 000H ;Code section start
jmp RESET ;Reset vector
REPEAT 7
dw 0XFFFF ;Address 4 to 7 are reserved
ENDM
ORG 008H
jmp ISR ;中断向量入口
REPEAT 7
dw 0XFFFF
ENDM
;========================================================
ORG 010H
clr_ram:
clr Y
mov A,#0x2f
b0mov Z,A
loop_clr:
clr @yz
next z,loop_clr
clr @yz
ret
;*************************************************
;;Name :IO初始化子程序
;Function:
;Input :
;Output :
;Register Used:
;*************************************************
io_INIT:
nop
PORT_INITAL:
; mov_c p2m,11000111b ;1为输出,0为输入
; mov_c p2ur,11111111b ;1为上拉
mov a,#0xff
mov p5m,a
mov p5ur,a
clr p0m
clr p1m
b0bset p0ur.0
ret
;*************************************************
;*************************************************
;;Name :中断定时器初始化子程序
;Function:
;Input :
;Output :
;Register Used:
;*************************************************
intermit_init:
b0bclr ftc0ien
b0bclr ftc0enb
mov a,#01110000b
b0mov tc0m,a ;set Fcpu/2
mov a,#256-80
b0mov tc0c,a ;set 250us interrupt 80*2*fcpu=160us
b0bclr ftc0irq
b0bclr ft0ien
b0bclr ft0enb
mov a,#01010000b
b0mov t0m,a ;set Fcpu/8
mov a,#256-125
b0mov t0c,a ;set 2ms interrupt 125*8*fcpu=1ms
b0bclr ft0irq
ret
;=====================================
; 初 始 化
;=====================================
RESET:
nop
RESET_WDT
mov A,#0X7F ;Initial stack pointer and
b0mov stkp,a ;disable global interrupt
call io_init ;io初始化
call intermit_init ;中断初始化
b0bts1 fnt0
jmp main ;看门狗复位,不用初始化ram
call clr_ram ;ram 初始化
; call test_50_60hz ;检测50/60Hz 并加载常数
;-------------------------------------------------
b0bset fgie
;--------------------------------------------------
jmp main
;================================================================
; 主 程 序
;================================================================
main:
RESET_WDT
b0bts0 p_on_off
jmp hz_60
hz_50:
b0bset ft0enb ;test
b0bset ft0ien
b0bclr ftc0enb
b0bclr ftc0ien
jmp main
hz_60:
b0bclr ft0enb ;test
b0bclr ft0ien
b0bset ftc0enb
b0bset ftc0ien
jmp main
;===============================================================
; interrupt
; 4ms interrupt
; 程序功能:中断服务程式
; 入口参数:
; 出口参数:
; 版本信息:1.0
; 编制日期:2007-08-10
;===============================================================
isr:
b0xch a,acc_buff
b0mov A,PFLAG
b0mov PFLAG_BUFF,A
b0bts0 ftc0irq
jmp tc0_int
b0bts1 ft0irq
jmp isr_exit
;----------------------------------------------------------------
;名称:T0中断程式
;功能:产生1ms and 10ms 标致
;----------------------------------------------------------------
t0_int: ;t0中断 1ms中断一次
mov_c t0c,256-125 ;125*8*fcpu=1ms
b0bclr ft0irq ;清除中断标志
incms timer_20ms
cmpc timer_20ms,10
jne isr_exit
not_bit p5.4
clr timer_20ms
jmp isr_exit
;----------------------------------------------------------------
;名称:TC0中断程式 ;160us 中断一次
;功能:160*52=8320us 1/60/2=0.008333=8333us
;----------------------------------------------------------------
tc0_int:
mov_c tc0c,256-65 ;80*2*fcpu=160us
b0bclr ftc0irq ;清除中断标志
b0bclr ftc0enb
b0bclr ftc0ien
incms timer_8_3ms
cmpc timer_8_3ms,52
jne isr_exit
not_bit p5.4
clr timer_8_3ms
tc0_int_end:
jmp isr_exit
;----------------------------------------------------------------
isr_exit:
b0xch A,PFLAG_BUFF
b0mov PFLAG,A
b0xch a,acc_buff
reti
endp
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -