Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://learn.sparkfun.com/tutorials/raspberry-pi-spi-and-i2c-tutorial/all
- wiringPi I/O library for C/C++
- http://wiringpi.com/
- //set up SPI
- clr r16
- ldi r16,(1<<SPE)|(0<<DORD)|(1<<MSTR) ;SPI Enable, MSB of the data word is transmitted first, Master
- out SPCR,r16 ;Save settings for SPI
- clr r16
- ldi r16,(1<<SPI2X) ;Set the speed setting
- out SPSR,r16 ;Save speed settings for SPI
- ; --------------------------------------------------------------
- ; -- DRIVER - transmits data to the BCD-display
- ; -- Uses: r16,r17
- ; -- Gets data from stack (4 bytes)
- DRIV_TRANSMIT:
- //push all registers used.
- push r16
- push r17
- push ZH
- push ZL
- //Load the Z pointer with stack pointer and add 7 to get down the the data.
- in ZH,SPH
- in ZL,SPL
- adiw Z,7
- //Load the loop register to 4 (one for each of the data we need to send)
- ldi r16,4
- DISPLAY_TO_LED_TRANSMIT:
- ld r17,Z+ ;Get the data from the stack
- out SPDR, r17 ;Send the data
- DISPLAY_TO_LED_WAIT_TRANSMIT:
- sbis SPSR,SPIF ;Check if transmission is completed
- rjmp DISPLAY_TO_LED_WAIT_TRANSMIT ;If not, go back
- dec r16
- brne DISPLAY_TO_LED_TRANSMIT
- //pop all registers used.
- pop ZL
- pop ZH
- pop r17
- pop r16
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement