en23535862_microcomputers_lab2
en23535862_microcomputers_lab2
Faculty of Engineering
Department of Electrical and Electronic
Engineering
1
Code:
#include <xc.inc>
;--------initializing-------------
PSECT start, CLASS = CODE, DELTA=2
start:
PAGESEL MAIN
GOTO MAIN
;RB0 Data
;RB1 CS
;RB2 CLK
2
movlw 0x04 ;configuration address loaded to WREG
movwf 0x22 ;configuration address moved to file register 0x22
movlw 0x81 ;configuration data loaded to WREG. Does not blink because
the ;MSB is 1
movwf 0x23 ; configuration data moved to file register 0x23
3
movlw 0x11 ;hex value 11 (17 in denary) is moved to the WREG
movwf COUNTER ;this counts the number of registers handled by the FSR
first8bit_loop1:
bsf PORTB,1 ;set CS to high
CALL DELAY
BCF PORTB,2 ;clear CLK
CALL DELAY
BCF PORTB,1 ;clear CS
CALL DELAY
MAIN:
DECFSZ loop1_15, f ;decrement loop1 counter
goto first_word_rotation ;jump to first_word_rotation if loop1 counter is not zero
goto second8bit_loop2 ;jump to second8bit_loop2 if loop1 counter is zero
first_word_rotation:
bcf PORTB,2 ;clear CLK
CALL DELAY
BTFSS displayData,7 ;test MSB of value in displayData
goto zero1 ;jumps to zero1 if MSB is 0
bsf PORTB,0 ;set DIN to 1
CALL DELAY
BSF PORTB,2 ;set CLK to 1
CALL DELAY
BCF STATUS,0 ;clear carry flag
RLF displayData, f ;rotate value in displayData by one position to the left
goto MAIN ;repeat MAIN until loop1 counter is 0
4
zero1:
bcf PORTB,2 ;clear CLK
CALL DELAY
BCF PORTB,0 ;clear DIN
CALL DELAY
BSF PORTB,2 ;set CLK to 1
CALL DELAY
BCF STATUS,0 ;clear carry flag
RLF displayData,f ;rotate value in displayData by one position to the left
goto MAIN ;repeat MAIN until loop1 counter is 0
second8bit_loop2:
INCF FSR ;increment the FSR
MOVF INDF,W ;move the value pointed to by the address in the FSR to
the ;WREG
movwf displayData ;move the value in the WREG to displayData file register
DECF COUNTER, 1 ;decrement value in COUNTER
MAIN2:
DECFSZ loop2_8, f ;decrement loop2 counter
goto second_word_rotation ;jump to second_word_rotation if loop2 counter is not zero
goto first8bit_loop1 ;jump to first8bit_loop1 if loop2 counter is zero
second_word_rotation:
bcf PORTB,2 ;clear CLK
CALL DELAY
BTFSS displayData,7 ;test MSB of value in displayData
goto zero2 ;jumps to zero2 if MSB is 0
bsf PORTB,0 ;set DIN to 1
CALL DELAY
BSF PORTB,2 ;set CLK to 1
CALL DELAY
BCF STATUS,0 ;clear carry flag
RLF displayData, f ;rotate value in displayData by one position to the left
goto MAIN2 ;repeat MAIN2 until loop2 counter is 0
zero2:
bcf PORTB,2 ;clear CLK
CALL DELAY
BCF PORTB,0 ;clear DIN
CALL DELAY
BSF PORTB,2 ;set CLK to 1
CALL DELAY
BCF STATUS,0 ;clear carry flag
RLF displayData,f ;rotate value in displayData by one position to the left
goto MAIN ;repeat MAIN2 until loop2 counter is 0
5
END_PROGRAM: ;after all the data is sent, the PIC stops rotating the FSR and
sending ;data to the MAX6952
CALL DELAY
GOTO END_PROGRAM
DELAY:
decfsz use_delay ;decrement the value in use_delay
goto DELAY
movlw 0X0f ;move hex value 0f to WREG
movwf use_delay ;move value in WREG to use_delay
return