commit 5a2a715a11fd01a92d49a0c8e2a4b237126b7a0a Author: sergeyyarkov Date: Fri Feb 3 21:16:04 2023 +0300 final diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ff6ecd4 --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +SRC_FILE = firmware +MCU = t2313 +PROGRAMMER = usbtiny + +build: + avrasm2 -fI -W+ie $(SRC_FILE).asm -l $(SRC_FILE).lss + +flash: + avrdude -c $(PROGRAMMER) -p $(MCU) -U flash:w:$(SRC_FILE).hex:i \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..5b2a72e --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# Shift Register Example with USI module + +This project is an example of using the 74HC595 shift register with the AVR ATtiny2313A microcontroller. The code in the project uses the Universal Serial Interface (USI) module on the ATtiny2313A to transmit data to the 74HC595 shift register. The transfer of data is managed using the USI Overflow Interrupt Flag, and once the transfer is completed, a pulse is sent to the LATCH pin to copy the data from the shift register to the storage register. This project demonstrates how to use the 74HC595 shift register in combination with the ATtiny2313A microcontroller to control a series of outputs. + +![simulation](./simulation.gif) + +Also see [this](https://github.com/sergeyyarkov/attiny2313a_shift-register-example) example of interaction with a shift register without a USI module diff --git a/firmware.asm b/firmware.asm new file mode 100644 index 0000000..0ecb183 --- /dev/null +++ b/firmware.asm @@ -0,0 +1,116 @@ +; +; Project name: shift-register-example +; Description: An example of using the single 74HC595 shift register with an AVR microcontroller +; Source code: https://github.com/sergeyyarkov/attiny2313a_shift-register-example +; Device: ATtiny2313A +; Device Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/doc8246.pdf +; Package: SOIC-20W_7.5x12.8mm_P1.27mm +; Assembler: AVR macro assembler 2.2.7 +; Clock frequency: 8 MHz Internal with CKDIV8 +; Fuses: lfuse: 0x64, hfuse: 0x9F, efuse: 0xFF, lock: 0xFF +; +; Written by Sergey Yarkov 28.01.2023 + +.INCLUDE "tn2313Adef.inc" +.LIST + +.DEF TEMP_REG_A = r16 ; Temp register A +.DEF TEMP_REG_B = r17 ; Temp register B +.DEF DATA = r20 ; DATA to transmit + +;========================================; +; LABELS ; +;========================================; + +.EQU USI_LATCH_PIN = PB0 ; ST_CP on 74HC595 +.EQU USI_DO_PIN = PB6 ; DS on 74HC595 +.EQU USI_CLK_PIN = PB7 ; SH_CP on 74HC595 + +;========================================; +; CODE SEGMENT ; +;========================================; + +.CSEG +.ORG 0x00 + +;========================================; +; VECTORS ; +;========================================; + +rjmp RESET_vect ; Program start at RESET vector + +RESET_vect: + ;========================================; + ; INITIALIZE STACK POINTER ; + ;========================================; + + ldi TEMP_REG_A, low(RAMEND) + out SPL, TEMP_REG_A + +MCU_INIT: + rcall INIT_PORTS + ldi DATA, 0b00000001 + rjmp LOOP + +;========================================; +; MAIN PROGRAM LOOP ; +;========================================; + +LOOP: + rcall USI_TRANSMIT + rol DATA + rcall DELAY + rjmp LOOP + +INIT_PORTS: + ldi r16, (1< USI Wire Mode + ; USICS1 <--------------> USI Clock Source Select + ; USICLK <--------------> USI Clock Strobe + ; USITC <--------------> USI Toggle Clock (Enable clock generation) + ldi TEMP_REG_A, (1< USI Wire Mode + ; USICS1 <--------------> USI Clock Source Select + ; USICLK <--------------> USI Clock Strobe + ; USITC <--------------> USI Toggle Clock (Enable clock generation) +000011 e10b ldi TEMP_REG_A, (1<