main.asm
资源名称:I2C.rar [点击查看]
上传用户:yinyuzhe
上传日期:2015-02-23
资源大小:542k
文件大小:7k
源码类别:
嵌入式/单片机编程
开发平台:
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.
- ;==================================================================================
- ;==================================================================================
- ; Project Name :
- ; Applied Body : SPMC65P2404A
- ; Firmware version:
- ; Programer :
- ; Date : 2004-11-10
- ; Description : slave Communicates with master
- ;
- ; Hardware Connect:
- ; Link File :
- ; IDE Version : V1.6.5
- ; BODY Version : V1.0.0A
- ;==================================================================================
- .SYNTAX 6502 ;Process standard 6502 addressing syntax
- .LINKLIST ;Generate linklist information
- .SYMBOLS ;Generate symbolic debug information
- ;************************************************************************************
- ;* *
- ;* System Register Define *
- ;* *
- ;************************************************************************************
- ;************************************************************************************
- .INCLUDE SPMC65P2404A.inc ;Define all hardware,Registers and ports.
- ;************************************************************************************
- ;************************************************************************************
- ;* *
- ;* Data memory Define *
- ;* *
- ;************************************************************************************
- .PAGE0 ;Define values in the range from 00h to FFh
- ;************************************************************************************
- .DATA ;Define data storage section
- ;************************************************************************************
- ;* *
- ;* Program Area *
- ;* *
- ;************************************************************************************
- .CODE
- .INCLUDE Subprogram.asm
- ;************************************************************************************
- ;* *
- ;* Power on Reset Process *
- ;* *
- ;************************************************************************************
- .PUBLIC V_Reset
- V_Reset:
- sei ;Disable interrupt
- ldx #C_STACK_BOTTOM ;Initial stack pointer at $00FF
- txs
- lda #C_T0FCS_Div_4
- sta GP_IIC_BitRate ;select the Prescaler of Timer1
- jsr F_Sys_Init ;initialize the I/O,Timer and clock for communication
- lda #%11110011 ;require master receive data
- sta GB_SCommand
- lda #2
- sta GB_SCapacity ;the size of the data
- lda #2
- sta GB_SData_Addr ;store the Slaver number
- lda #$10
- sta GB_SData_Addr+1
- cli
- L_MainLoop:
- jsr F_WrData ;dispose when send the data
- jsr F_CheckACK ;ACK check
- lda P_IOC_Data
- and #%00000001 ;if PC0=0 then clear the counter and display
- bne ?L_Display
- lda #0
- sta GB_TimeCnt1
- sta GB_DisCnt
- ?L_Display:
- lda GB_DisCnt ;display the value of the counter
- sta GB_SData_Addr+1
- ?L_Wait:
- lda P_INT_Flag1
- and #C_INT_T2OIF ;time 704us ?
- beq ?L_Wait ;no
- lda #C_INT_T2OIF
- sta P_INT_Flag1
- inc GB_CSCnt
- lda GB_CSCnt
- cmp #2
- bcc ?L_Count
- lda #0
- sta GB_CSCnt
- sta GB_INT_Cnt
- ?L_Count:
- inc GB_TimeCnt1
- lda GB_TimeCnt1
- cmp #250 ;time 0.5s
- bcc L_MainLoop ;no
- lda #0
- sta GB_TimeCnt1
- inc GB_TimeCnt2
- lda GB_TimeCnt2
- cmp #2
- bcc L_MainLoop
- lda #0
- sta GB_TimeCnt2
- inc GB_DisCnt
- lda GB_DisCnt
- cmp #$10
- bcc L_MainLoop
- lda #0
- sta GB_DisCnt
- jmp L_MainLoop
- ;************************************************************************************
- ;* *
- ;* Interrupt Service Process *
- ;* *
- ;************************************************************************************
- V_IRQ:
- pha
- txa
- pha
- ;===============================================================================
- ; Timer0 INT
- ;===============================================================================
- lda P_INT_Flag1
- and #C_INT_T0OIF
- beq ?L_IRQ_INT
- M_ClrSCL; ;clear SCL
- lda GB_INT_Cnt
- cmp #8
- bcc ?L_SendData
- M_SDA_Input; ;set free the SDA
- M_DisableT1; ;disable the Timer1
- inc GB_TxCnt
- M_BitSet GB_Flag,0; ;set the flag for check ACK
- jmp ?L_INT_rti
- ?L_SendData:
- asl GP_IIC_TxBuf
- bcs ?L_OutputH
- M_ClrSDA; ;SDA export '0'
- jmp ?L_Rising
- ?L_OutputH:
- M_SetSDA; ;SDA export '1'
- ?L_Rising:
- inc GB_INT_Cnt
- M_SetSCL; ;set SCL
- jmp ?L_INT_rti
- ;===============================================================================
- ; IRQ INT
- ;===============================================================================
- ?L_IRQ_INT:
- lda P_INT_Flag0
- and #(C_INT_IRQ0IF+C_INT_IRQ1IF)
- beq ?L_INT_rti
- lda GB_Flag
- and #%10000000
- beq ?L_NoSart
- lda P_IOB_Data
- and #%00100000 ;check the SCL is high ?
- beq ?L_INT_rti ;No
- M_BitClr GB_Flag,7; ;start flag
- lda #C_IRQOpt1_IRQ1ES ;select rising edge trigger
- sta P_IRQ_Opt1
- sta P_IRQ_Opt1
- lda P_INT_Ctrl0
- ora #C_INT_IRQ1IE ;enable IRQ1
- sta P_INT_Ctrl0
- jmp ?L_INT_rti
- ?L_NoSart:
- lda #0
- sta GB_CSCnt
- lda P_IOB_Data ;
- and #%00010000 ;
- rol a ; + = catch one bit
- rol a ; /
- rol a ;/
- rol a
- rol GP_IIC_RxBuf
- inc GB_INT_Cnt
- lda GB_INT_Cnt
- cmp #8 ;catch 8 bit ?
- bcc ?L_INT_rti ;no
- M_RxData;
- inc GB_RxCnt
- M_BitClr GB_Flag,5; ;clear if receive the command
- lda #0
- sta GB_INT_Cnt
- lda #00 ;select rising edge trigger
- sta P_IRQ_Opt1
- sta P_IRQ_Opt1
- lda P_INT_Ctrl0
- ora #C_INT_IRQ1IE ;enable IRQ1
- sta P_INT_Ctrl0
- ?L_INT_rti:
- lda #(C_INT_IRQ0IF+C_INT_IRQ1IF)
- sta P_INT_Flag0
- lda #C_INT_T0OIF
- sta P_INT_Flag1
- pla
- tax
- pla
- rti
- V_NMI:
- rti
- ;************************************************************************************
- ;* *
- ;* Interrupt Vector Table *
- ;* *
- ;************************************************************************************
- VECTOR .SECTION
- DW V_NMI ;Non-mask interrupt vector(no use)
- DW V_Reset ;Reset vector
- DW V_IRQ ;IRQ interrupt vector
- ;************************************************************************************
- ;* *
- ;* End of Interrupt Vector Table *
- ;* *
- ;************************************************************************************
- .END