📄 subprogram.asm
字号:
;==================================================================================
; The information contained herein is the exclusive property of
; Sunplus Technology Co. And shall not be distributed, reproduced,
; or disclosed in whole in part without prior written permission.
; (C) COPYRIGHT 2004 SUNPLUS TECHNOLOGY CO.
; ALL RIGHTS RESERVED
; The entire notice above must be reproduced on all authorized copies.
;==================================================================================
;==================================================================================
; Program Name : Subprogram.asm
; Description : data processing for IIC communication
; Reference : SPMC65P2404A/2408A Data Sheet
; Revision history :
;----------------------------------------------------------------------------------
; Version Date Description
; 1.0.0 2004-10-27 First Edition
;==================================================================================
.SYNTAX 6502 ;Process standard 6502 addressing syntax
.LINKLIST ;Generate linklist information
.SYMBOLS ;Generate symbolic debug information
;************************************************************************************
;* *
;* System Register Define *
;* *
;************************************************************************************
;************************************************************************************
.INCLUDE IICMacro.inc
;************************************************************************************
;************************************************************************************
;************************************************************************************
;* *
;* Data memory Define *
;* *
;************************************************************************************
.PAGE0 ;Define values in the range from 00h to FFh
GB_Flag DS 1
GB_TxCnt DS 1
GB_RxCnt DS 1
GB_CSCnt DS 1
GB_INT_Cnt DS 1
GB_CheckStop_Cnt DS 1
GB_MCapacity DS 1 ;the Capacity of data
GB_Register DS 3
GB_Address_Rx DS 10
GB_Address_Tx DS 10
GP_IIC_BitRate .EQU GB_Register
GP_IIC_RxBuf .EQU GB_Register+1 ;buffer for receivind data
GP_IIC_TxBuf .EQU GB_Register+2 ;buffer for send data
GB_MCommand .EQU GB_Address_Tx ;the command of the master
GB_MData_Addr .EQU GB_Address_Tx+1 ;the head address of data
GB_SCommand .EQU GB_Address_Rx ;the command from the slaver
GB_SData_Addr .EQU GB_Address_Rx+1 ;the head address of data from slaver
;************************************************************************************
.DATA ;Define data storage section
;************************************************************************************
;* *
;* Subprogram Area *
;* *
;************************************************************************************
.CODE
;***********************************************************************************
; system initialize
;
;***********************************************************************************
.PUBLIC F_Sys_Init
F_Sys_Init:
lda #$FF
sta P_SYS_Ctrl
sta P_SYS_Ctrl ;clear the CPU reset flag
lda #C_WDT_Clr
sta P_WDT_Clr
lda #%10110000
sta P_WDT_Ctrl
sta P_WDT_Ctrl
;===================================================================================
; setting the I/O
; PB5,PB4 -----> input with pull-high
;===================================================================================
lda #%00110000
sta P_IOB_Data
lda #%00000000
sta P_IOB_Attrib
lda #%00000000
sta P_IOB_Dir
;===================================================================================
;* setting the Timer
;===================================================================================
lda GP_IIC_BitRate ;f = 8MHz/4/156 = 12.8KHz
sta P_TMR0_1_Ctrl1
lda #100
sta P_TMR0_Preload
;===================================================================================
;* setting the Interrupt
;===================================================================================
lda #C_IRQOpt1_IRQ1ES ;select rising edge trigger(PB5)
sta P_IRQ_Opt1
sta P_IRQ_Opt1
; lda #C_INT_IRQ1E
; sta P_INT_Ctrl0
lda #C_INT_T0OIE
sta P_INT_Ctrl1
;===================================================================================
;* var initialize
;===================================================================================
lda #0
sta GB_MCapacity
lda #$F3
sta GB_MCommand
lda #%10000000 ;bit1-->flag for check stop signal
sta GB_Flag ;bit6--->set if receive ACK
rts ;bit7--->stop or start flag (0--start,1--stop)
;************************************************************************************
;* *
;* create start signal *
;* *
;************************************************************************************
.PUBLIC F_Start
F_Start:
lda GB_Flag
and #%10000000 ;check the flag for stop signal occurring
beq ?L_Rts
M_SCL_Output;
M_SetSCL;
M_SetSDA;
M_SDA_Output;
lda GB_MCommand ;\
eor #%00000010 ; + change slaver
sta GB_MCommand ;/
lda #0
sta GB_TxCnt
sta GB_RxCnt
sta GB_CSCnt
sta GB_INT_Cnt
M_BitClr GB_Flag,7; ;clear the flag
M_BitClr GB_Flag,6;
M_ClrSDA;
?L_Rts:
rts
;************************************************************************************
;* *
;* communication *
;* *
;************************************************************************************
.PUBLIC F_WrData
F_WrData:
lda GB_Flag
and #%11000000 ;check if has the start signal
bne ?L_Rts ;no
lda GB_MCapacity
cmp GB_TxCnt
bcc ?L_Rts
M_TxData; ;write the data which is been send to buffer and enable Timer1
M_BitSet GB_Flag,6;
inc GB_TxCnt
?L_Rts:
rts
;************************************************************************************
;* *
;* check stop signal *
;* *
;************************************************************************************
.PUBLIC F_CheckStop
F_CheckStop:
lda GB_Flag
and #%00000010 ;the receiver check Stop Signal
beq ?L_Rts
inc GB_CheckStop_Cnt
lda GB_CheckStop_Cnt
cmp #4
bcc ?L_Rts
lda #0
sta GB_CheckStop_Cnt
M_BitSet GB_Flag,7; ;set the flag if stop signal has occured
M_BitClr GB_Flag,1;
lda P_INT_Ctrl0
and #%11111101
sta P_INT_Ctrl0 ;disable IRQ1
lda GB_MCommand
and #%00000010
bne ?L_Wr_DispBuf
lda GB_SData_Addr
sta GB_ShowBuf
lda GB_SData_Addr+1
sta GB_ShowBuf+1
jmp ?L_Rts
?L_Wr_DispBuf:
lda GB_SData_Addr ;\
sta GB_ShowBuf+2 ;+
lda GB_SData_Addr+1 ;+ = store the data from slaver to display buffers
sta GB_ShowBuf+3 ;/
?L_Rts:
rts
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -