;Functional description:
;1. Make a left shift of a light, and build the 8 codes of the left shift into the TABLE.
;2. Take out the data from the TABLE and store it in 93C46 in 16-bit mode, address 00H-03H.
;3. Take out the data code in the address 00H-03H of 93C46 and store it in the RAM (30H)-(37H) of 877A, and output it to the RC port of 877A.
;When the power is cut off and then restored, the data code will not disappear.
;4. If the 93C46 used in this circuit is ATMEL or M IC RO Chip , or is not from this factory, the programming time will be different
;必须调整本程序的DELAY时间
;本实战的目的是让大家进上步熟悉SPI通信的时序,熟悉93C46的读写,会用软件模拟SPI通信
;硬件接法:
;1.93C46的CS接877A的RB1口;CLK接877A的RB2口;DI接877A的RB4口;DO接877A的RB5口;93C46的ORG端接VCC,使93C46工作于16位方式
;2.实验本实验须将MCD-DEMO实验板上的24CXX系列芯片先取下,在实验过程中不要按动同样接在RB口的按键,以免影响通信时序.
;3.实验板上拔码开关S1要置ON,其它拔码开关都可以关闭。
;PIC 单片机 学习网 陈学乾 http://www.pic16.com 讨论论坛:http://pic16.com/bbs/
;版权所有,转载请注明出处,并不能去掉或改变文件中的说明文字。
;程序文件名“MCD-93C46.ASM"
;程序清单如下:
;************************************
LIST P=16F877A, R=DEC
include "P16F877A.inc"
;***********************************
__CONFIG _DEBUG_OFF&_CP_ALL&_WRT_HALF&_CPD_ON&_LVP_OFF&_BODEN_OFF&_PWRTE_ON&_WDT_OFF&_HS_OSC;
;************************************ 定义查表偏移量
READ EQU 0 ;读93C46
WRITE EQU 1 ;写入93C46
EWEN EQU 2 ;93C46写入使能
EWDS EQU 3 ;93C46写入禁止
;*************************************定义引脚位地址
CS EQU 1
CLK EQU 2
DI EQU 4
DO EQU 5
;*********************
ADR46 EQU 20H
F1 EQU 23H
F2 EQU 24H
F3 EQU 25H
F4 EQU 26H
F5 EQU 27H
F6 EQU 28H
F7 EQU 29H
;**********************
ORG 000H
NOP ;放置一条ICD必需的空操作指令
GOTO MAIN
ORG 0008H
;******************************************************
TABLE
ADDWF PCL ,1 ;查表,PORTC一个灯左移
RETLW 01H
RETLW 02H
RETLW 04H
RETLW 08H
RETLW 10H
RETLW 20H
RETLW 40H
RETLW 80H
;*******************************************************
TO9346
MOVWF F1 ;将W的值送F1暂存
BSF PORTB ,CS ;写入起始位1
BSF PORTB ,DI
BSF PORTB ,CLK
CALL DELAY
BCF PORTB ,CLK
CALL DELAY
MOVFW F1
ADDWF PCL ,1
GOTO SREAD ;读
GOTO SWRITE ;写
GOTO SEWEN ;写使能
GOTO SEWDS ;写禁止
;*****************************************************
MAIN
MOVLW 00H
MOVWF PORTC ;LED先全部熄灭
MOVLW 20H
MOVWF PORTB ;除DO外,其它通信口全送0
BSF STATUS,RP0 ;定义RA口,RC口全部为输出
MOVLW 20H
MOVWF TRISB ;RB口5脚为入,其它全为出
CLRW
MOVWF TRISC ;RC口全为输出.
MOVWF OPTION_REG ;开启RB口内部弱上拉
BCF STATUS,RP0
;****************************************
LOOP
CLRF 21H ;code pointer
CLRF ADR46 ;93C46 address 00H
MOVLW 04H
MOVWF 22H ;4 groups of 8 codes
START
MOVLW EWEN ;write enable
CALL TO9346
MOVFW 21H ;load code pointer
CALL TABLE ;get code from TABLE
MOVWF F5 ;store in "write register"
INCF 21H ,1 ;get next code
MOVFW 21H
CALL TABLE ;get code from TABLE
MOVWF F4
MOVLW WRITE
CALL TO9346 ;write data
MOVLW EWDS
CALL TO9346 ;write disable
INCF 21H ,1 ;get next code
INCF ADR46 ,1 ;get next address
CALL DELAY1
DECFSZ 22H ,1 ;Until writing four addresses
GOTO START
MOVLW 30H ;Store in 877A's RAM first address
MOVWF FSR
CLRF ADR46 ;93C46 address 00
MOVLW 04H
MOVWF 22H ;Read 93C46's four addresses, 8 codes
;********************
A1
MOVLW READ
CALL TO9346 ;Read the data in the address
MOVFW F5
MOVWF INDF ;Store the read data in 877A's RAM
INCF FSR ,1
MOVFW F4
MOVWF INDF
INCF ADR46 ,1 ;Read the next address
INCF FSR ,1
DECFSZ 22H ,1 ;Until reading four addresses
GOTO A1
A2
MOVLW 08H
MOVWF 22H
MOVLW 30H ;RAM 30h-37H 8 codes in total
MOVWF FSR
OUTPUT
MOVFW INDF
MOVWF PORTC ; output result to PORTC
CALL DELAY1
INCF FSR ,1
DECFSZ 22H ,1
GOTO OUTPUT
GOTO A2
;****************************
SREAD
MOVLW 80H
ADDWF ADR46 ,0 ; 6-bit address plus two-bit operation code, 10XXXXXX read instruction
CALL SDT46 ; write operation code and address
CALL RDT46 ; read high data
MOVWF F5 ; store in F5
CALL RDT46 ; read low address
MOVWF F4 ; store in F4
GOTO EX9346
;******************************
SWRITE
MOVLW 40H
ADDWF ADR46 ,0 ; 6-bit address plus two-bit operation code 01XXXXXX write instruction
CALL SDT46 ;Write opcode and address
MOVFW F5 ;Load data
CALL SDT46 ;Write data
MOVFW F4 ;Load data
CALL SDT46 ;Write data
GOTO EX9346
;******************************
SEWEN
MOVLW 30H ;Write opcode 0011XXXX Write enable instruction
CALL SDT46
GOTO EX9346
;******************************
SEWDS
CLRW ;Write 0000XXXX write disable instruction
CALL SDT46
;******************************
EX9346
BCF PORTB ,CS ;Clear CS to 0 when finished
RETURN
;******************************
SDT46:
MOVWF F2 ;Send the data to be written to F2
MOVLW 08H ;Write 8-bit data
MOVWF F3
SD1:
RLF F2 ,1
BSF PORTB ,DI
BTFSS STATUS ,C
BCF PORTB ,DI
BSF PORTB ,CLK
CALL DELAY
BCF PORTB ,CLK
CALL DELAY
DECFSZ F3 ,1
GOTO SD1
RETURN
;******************************
RDT46
MOVLW 08H ;Read 8-bit data
MOVWF F3
RD1
BSF PORTB ,CLK
CALL DELAY
BCF PORTB ,CLK
CALL DELAY
BSF STATUS ,C
BTFSS PORTB ,DO
BCF STATUS ,C
RLF F2 ,1
DECFSZ F3 ,1
GOTO RD1
MOVFW F2 ;Send the read data to W
RETURN
;********************************
DELAY
MOVLW 1FH ;CLK timing delay
MOVWF F7
DECFSZ F7 ,1
GOTO $-1
RETURN
;***********************************
DELAY1 ;Delay
MOVLW .20
MOVWF F4
D1
MOVLW .40
MOVWF F5
D2
MOVLW .248
MOVWF F6
DECFSZ F6 ,1
GOTO $-1
DECFSZ F5 ,1
GOTO D2
DECFSZ F4 ,1
GOTO D1
RETURN
;************************************************
end ;End of source program
;*********************************************************
Previous article:pic16f877a read and write program for 24c01
Next article:877A software simulates I2C communication to read and write 24C02
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Application of Keithley Source Meter in Electronic Thin Film Materials
- How to switch the unit of Proteus simulation software from inches to mm? Pressing m does not work, and Baidu can't find it
- TI C64X+ General Library Function User Manual
- Examples of capacitor applications in power supply design (recommended for collection)
- How can I hide certain items when printing in AD, such as the frequency mark of the crystal oscillator?
- gw1n FPGA reads ADS8598H actual DC measurement
- Shouldn't the charging curve of a capacitor be inversely proportional to its discharging curve?
- IP core issues in ISE
- Attenuator Specifications
- AD15 Help, help, help