Websearch is a good way to find circuits to build and code to try. I found this example bundled in a simulator program and it comes with some software.
Change the LED bar to a 7 segment display and load the hex file. The example comes with software that runs a single bit down the segments. This is AVR assembly language that you can program with MicroChip Studioor Avra.
We say that Assembly language is low-level compared to PyThon that imports complex functions. In assembly we push numbers into registers and increment them, copying the actions we saw in Shift Register project.
Look through the code running on the demo, it toggles bits in the PORTB register hardware. Find DMS_OUTER: DELAYTEMP, 20 and increase the number to slow the speed of the demo.
;Chip Model: MEGA328P
;Assembler header file
.INCLUDE "m328pdef.inc"
;SREG bit names (for AVR Assembler compatibility, GCBASIC uses different names)
#define I 7
#define T 6
#define H 5
#define S 4
#define V 3
#define N 2
#define Z 1
#define C 0
;********************************************************************************
;Set aside memory locations for variables
.EQU BITOUT=256
.EQU INDEX=257
;********************************************************************************
;Register variables
.DEF DELAYTEMP=r25
.DEF DELAYTEMP2=r26
.DEF SysBitTest=r5
.DEF SysCalcTempA=r22
.DEF SysValueCopy=r21
.DEF SysWaitTempMS=r29
.DEF SysWaitTempMS_H=r30
.DEF SysTemp1=r0
;********************************************************************************
;Vectors
;Interrupt vectors
nop
rjmp BASPROGRAMSTART ;Reset
nop
reti ;INT0
nop
reti ;INT1
nop
reti ;PCINT0
nop
reti ;PCINT1
nop
reti ;PCINT2
nop
reti ;WDT
nop
reti ;TIMER2_COMPA
nop
reti ;TIMER2_COMPB
nop
reti ;TIMER2_OVF
nop
reti ;TIMER1_CAPT
nop
reti ;TIMER1_COMPA
nop
reti ;TIMER1_COMPB
nop
reti ;TIMER1_OVF
nop
reti ;TIMER0_COMPA
nop
reti ;TIMER0_COMPB
nop
reti ;TIMER0_OVF
nop
reti ;SPI_STC
nop
reti ;USART_RX
nop
reti ;USART_UDRE
nop
reti ;USART_TX
nop
reti ;ADC
nop
reti ;EE_READY
nop
reti ;ANALOG_COMP
nop
reti ;TWI
nop
reti ;SPM_READY
;********************************************************************************
;Start of program memory page 0
nop
BASPROGRAMSTART:
;Initialise stack
ldi SysValueCopy,high(RAMEND)
out SPH, SysValueCopy
ldi SysValueCopy,low(RAMEND)
out SPL, SysValueCopy
;Call initialisation routines
rcall INITSYS
;Start of the main program
rcall INIT595
SysDoLoop_S1:
ldi SysValueCopy,1
sts BITOUT,SysValueCopy
rcall SHIFTBIT
ldi SysWaitTempMS,244
ldi SysWaitTempMS_H,1
rcall Delay_MS
ldi SysValueCopy,0
sts INDEX,SysValueCopy
SysForLoop1:
lds SysTemp1,INDEX
inc SysTemp1
sts INDEX,SysTemp1
ldi SysValueCopy,0
sts BITOUT,SysValueCopy
rcall SHIFTBIT
ldi SysWaitTempMS,244
ldi SysWaitTempMS_H,1
rcall Delay_MS
lds SysCalcTempA,INDEX
cpi SysCalcTempA,7
brlo SysForLoop1
SysForLoopEnd1:
rjmp SysDoLoop_S1
SysDoLoop_E1:
BASPROGRAMEND:
sleep
rjmp BASPROGRAMEND
;********************************************************************************
Delay_MS:
inc SysWaitTempMS_H
DMS_START:
ldi DELAYTEMP2,254
DMS_OUTER:
ldi DELAYTEMP,20
DMS_INNER:
dec DELAYTEMP
brne DMS_INNER
dec DELAYTEMP2
brne DMS_OUTER
dec SysWaitTempMS
brne DMS_START
dec SysWaitTempMS_H
brne DMS_START
ret
;********************************************************************************
INIT595:
sbi DDRB,5
sbi DDRB,4
sbi DDRB,3
sbi DDRB,2
sbi DDRB,1
cbi PORTB,5
cbi PORTB,4
cbi PORTB,3
cbi PORTB,2
cbi PORTB,1
sbi PORTB,5
ret
;********************************************************************************
INITSYS:
ldi SysValueCopy,0
out PORTB,SysValueCopy
ldi SysValueCopy,0
out PORTC,SysValueCopy
ldi SysValueCopy,0
out PORTD,SysValueCopy
ret
;********************************************************************************
SHIFTBIT:
cbi PORTB,3
cbi PORTB,4
cbi PORTB,1
lds SysBitTest,BITOUT
sbrc SysBitTest,0
sbi PORTB,1
sbi PORTB,4
sbi PORTB,3
ret
;********************************************************************************
Assembly is like punching the buttons with your hands.
Upload Binary Hex FileThe hexadecimal file contains the ones and zeros for our program. We build it on a PC and move it to a target MCU. The file provided by the simulator works on real Uno boards. Program a Uno normally or follow Arduino IDE Upload with external programmer.
With the simulation right-click on the processor and look for load firmware. Folder explorer to the demo hex file.
Look at our development hardware and software. ATmega328 processor, standard shift-register, 7segment LED. We have a circuit that blinks segments a to g and dot.
Read the pins, trace the leads, make a Connection Table. Expect the names on one device to be different on the next. Here are some of the signals we are using.
This table needs some explanation. Blank means not applicable.
The ATmega processor chip a has metal pins named B1, B2, B3, B4, B5, AVR Assembly language calls these pins PORTB, 1 etc. Arduino Corp uses pin9, pin10, pin11, pin12, pin13.
Wires connect our processor to an LS74HC595 shift register. It works like the hands-on in Shift Register Project. Data Strobe, Output Enable, Clock, Latch and Reset are connected. But the names are slightly different. > is a clocking symbol.
We need a data input and a clock. Maybe we want a latch signal every 8 clock pulses to handle bytes. Our assembly demo holds latch and reset high to keep the shift register running. Output enable is kept low and the screen stays on.
Next StepsLots of options. Websearch for assembly programs and there are plenty using this display. Now that you know which pins are used you can modify that code to run.
High level languages such as C++. This is the same processor as in the Arduino Uno.
Comments
Please log in or sign up to comment.