📄 i2csint.p18.ex.txt
字号:
;###############################################################################;
;# TITLE "I2C Master General Purpose Library Checking Software" ;
;# ;
;# ;
;# Program: I2CSInt.ex.txt ;
;# Version: 1.0 ;
;# Revision Date: ;
;# Author: Vidyadhar ;
;# ;
;# ;
;# Program demonstrates use of I2C Slave general purpose library module. ;
;# This program transmits 4 bytes of Data on read command from Master ;
;# This program receives 4 bytes of Data on write command from Master ;
;# Timer0 is used for error recovery purpose. It is initialized to interrupt ;
;# every 1 ms. The system clock is taken as 4 MHz. ;
;###############################################################################;
;
list p=18f452 ;
#include <P18F452.INC> ;
;
;***********************************************;
#include "I2CSInt.inc" ;This include all required files and variables.
;***********************************************;
UDATA_ACS
DupW res 1
DupStat res 1
;***********************************************;
;
Starthere code 0x0000 ;
;
goto Start ;
;-----------------------------------------------;
;
intr code 0x0008 ;
;
goto ISRHandler ;
;
;-----------------------------------------------;
Strt code ;
;
Start: ;
;
; ;
; ;
; ;
;
bsf TRISC,4 ;SDA is made i/p
bsf TRISC,3 ;SCL is made i/p
;
movlw 0d1h ;Timer0 with system clock
andwf T0CON,f ;Prescaler 4 (Timer0 timeout = ~1 ms at 4 MHz)
;
call I2CSIntInit ;to Initialise SSP MOdule
;
mSetI2CSIntHighPriority ;
; To Send 4 bytes Data1, Data2, Data3, Data4 ;
; to the Master ;
;
; ;
; ;
; ;
; ;
I2CCommn ;
movlw 000h ;Data1;
call I2CSIntPut ;
;
movlw 001h ;Data2;
call I2CSIntPut ;
;
movlw 002h ;Data3;
call I2CSIntPut ;
;
movlw 003h ;Data4;
call I2CSIntPut ;
rechk ;
btfss vI2CSIntStatus,I2CSTx ;
goto I2CRx ;
;
;
;
;
;
;
goto rechk ;
;
I2CRx:
btfsc vI2CSIntStatus,I2CSRxBufEmpty ;
goto rechk ;
;
;
; To Receive from the Mastar ;
;
call I2CSIntGet ;Data is present in 'W' Register
;
goto I2CRx ;
;
; ;
; ;
; ;
; ;
;
goto $ ;
;-----------------------------------------------;
ISRHandler: ;
;
; movwf DupW ;Uncoment the line only if context saving
; swapf STATUS,w ;is required.
; movwf DupStat ;
; ;
call I2CSIntISR ;
; ;
; ;
; ;
; swapf DupStat,w ;
; movwf STATUS ;
; swapf DupW,f ;
; swapf DupW,w ;
retfie ;
;
;***********************************************;
end ;
;***********************************************;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -