Path:AVR-EN => Applications => Ticker => Software
ATmega16 Application of
AVR-Single-Chip-Controller AT90S, ATtiny, ATmega and ATxmega
Ticker with ATmega16A and LEDs
Assembler software for the ticker
Logo

Assembler code for the ticker with an ATmega16

Click here to download a zipped version of this page (1.43 MB)

;
; ******************************************
; * Text ticker for 24*8 LEDs & ATmega16   *
; * Version 1, August 2017                 *
; * (C)2017 by http://avr-asm-tutorial.net *
; ******************************************
;
; Include AVR type file
.NOLIST
.INCLUDE "m16Adef.inc" ; Header file for ATmega16
.LIST
;
; ============================================
;   H A R D W A R E    I N F O R M A T I O N 
; ============================================
;
; Device = ATmega16A
;             ____________
;          1 /            |40
;     C0 o--|pb0       pa0|--o A0
;          2|             |39
;     C1 o--|pb1       pa1|--o A1
;          3|             |38
;     C2 o--|pb2       pa2|--o A2
;          4|             |37
;     C3 o--|pb3       pa3|--o A3
;          5|             |36
;     C4 o--|pb4       pa4|--o A4
;          6|             |35
;     C5 o--|pb5       pa5|--o A5
;          7|             |34
;     C6 o--|pb6       pa6|--o A6
;          8|             |33
;     C7 o--|pb7       pa7|--o A7
;          9|             |32
;  RESET o--|reset    AREF|--o
;         10|             |31
;   +5 V o--|vcc       gnd|--o 0 V
;         11|             |30
;    0 V o--|gnd      AVCC|--o +5 V
;         12|             |29
;        o--|XTAL2     pc7|--o C15
;         13|             |28
;        o--|XTAL1     pc6|--o C14
;         14|             |27
;    C16 o--|pd0       pc5|--o C13
;         15|             |26
;    C17 o--|pd1       pc4|--o C12
;         16|             |25
;    C18 o--|pd2       pc3|--o C11
;         17|             |24
;    C19 o--|pd3       pc2|--o C10
;         18|             |23
;    C20 o--|pd4       pc1|--o C9
;         19|             |22
;    C21 o--|pd5       pc0|--o C8
;         20|             |21
;    C22 o--|pd6       pd7|--o C23
;           |_____________|
;
; ============================================
;      P O R T S   A N D   P I N S 
; ============================================
;
.equ pAO = PORTA
.equ pAD = DDRA
.equ p0O = PORTB
.equ p0D = DDRB
.equ p1O = PORTC
.equ p1D = DDRC
.equ p2O = PORTD
.equ p2D = DDRD
;
; ================================================
;                 T I M I N G
; ================================================
;
;   Controler clock     = 1.000.000 Hz
;   TC0 prescaler       =         8
;   TC0 Int-Frequency   =       488.28 Hz
;   Number of MUX rounds=         8
;   MUX Frequency       =        61.04 Hz
;   Phase divider       =        32
;   Display change freq.=         1.91 Hz
;
; ================================================
;     C O N S T A N T S   T O   C H A N G E
; ================================================
;
; Display speed adjustment
.equ cCount = 32 ; for ca. 2 Hz display change freq.
;
; ========================================================
;  F I X E D    A N D   D E R I V E D   C O N S T A N T S 
; ========================================================
;
; Clock frequency by default
.equ Clock = 1000000 ; Standard default for ATmega16A
.equ Tc0Presc = 8 ; Prescaler TC0
.equ MuxFrequ = Clock / Tc0Presc ; Resulting MUX frequency
.equ MuxDispl = MuxFrequ / 8 ; Run frequency display
;
; ============================================
;   R E G I S T E R    D E F I N I T I O N S
; ============================================
;
; Free: R0..R15
.DEF rmp = R16 ; multi purpose register
.DEF rAnode = R17 ; Anode driver
.DEF rAnd = R18 ; All Ones register
.DEF rCount = R19 ; MUX rounds counter
; free: R20..R25
; Used: X = XH:XL = R27:R26
; free: Y = YH:YL = R29:R28
; Used: Z = ZH:ZL = R31:R30
;
; ============================================
;       S R A M   D E F I N I T I O N S
; ============================================
;
; (not used, for stack only)
;;
; ==============================================
;   R E S E T   A N D   I N T   V E C T O R S
; ==============================================
;
.CSEG
.ORG $0000
	rjmp Main ; RESET
	nop
	reti ; INT0 External Interrupt Request 0
	nop
	reti ; INT1 External Interrupt Request 1
	nop
	reti ; TIMER2 COMP Timer/Counter2 Compare Match
	nop
	reti ; TIMER2 OVF Timer/Counter2 Overflow
	nop
	reti ; TIMER1 CAPT Timer/Counter1 Capture Event
	nop
	reti ; TIMER1 COMPA Timer/Counter1 Compare Match A
	nop
	reti ; TIMER1 COMPB Timer/Counter1 Compare Match B
	nop
	reti ; TIMER1 OVF Timer/Counter1 Overflow
	nop
	rjmp Tc0Ovf ; TIMER0 OVF Timer/Counter0 Overflow
	nop
	reti ; SPI, STC Serial Transfer Complete
	nop
	reti ; USART, RXC USART, Rx Complete
	nop
	reti ; USART, UDRE USART Data Register Empty
	nop
	reti ; USART, TXC USART, Tx Complete
	nop
	reti ; ADC ADC Conversion Complete
	nop
	reti ; EE_RDY EEPROM Ready
	nop
	reti ; ANA_COMP Analog Comparator
	nop
	reti ; TWI Two-wire Serial Interface
	nop
	reti ; INT2 External Interrupt Request 2
	nop
	reti ; TIMER0 COMP Timer/Counter0 Compare Match
	nop
	reti ; SPM_RDY Store Program Memory Ready
	nop
;
; ==========================================
;    I N T E R R U P T   S E R V I C E
; ==========================================
;
; TC0 Overflow Interrupt Service Routine
Tc0Ovf:
	ldi rmp,0 ; Anode outputs off
	out pAO,rmp 
	lpm rmp,Z+ ; Read byte 0
	out p0O,rmp
	and rAnd,rmp ; All Ones?
	lpm rmp,Z+ ; Read byte 1
	out p1O,rmp
	and rAnd,rmp ; All Ones?
	lpm rmp,Z+ ; Read byte 2
	out p2O,rmp
	and rAnd,rmp ; All Ones?
	out pAO,rAnode ; Anode outputs on
	lsl rAnode ; Next MUX output
	brcc Tc0OvfRet ; No overflow, continue
	dec rCount ; Count down
	breq Tc0OvfEnd ; Restart when zero
	mov ZH,XH ; Start MUX run from previous address
	mov ZL,XL
	ldi rAnode,1 ; with first anode output
	ldi rAnd,0xFF ; Set All Ones detector
	reti
Tc0OvfEnd:
	cpi rAnd,0xFF ; All Ones?
	brne Tc0OvfRst ; No, continue with table
	ldi ZH,HIGH(2*Table) ; Restart at the beginning of table
	ldi ZL,LOW(2*Table)
Tc0OvfRst:
	mov XH,ZH ; Copy position reached to X
	mov XL,ZL
	ldi rAnode,1 ; start with first anode
	ldi rAnd,0xFF ; Set All Ones
	ldi rCount,cCount ; Set number of MUX runs
Tc0OvfRet:
	reti
;
; ============================================
;    M A I N   P R O G R A M    I N I T
; ============================================
;
Main:
	; Init stack
	ldi rmp,HIGH(RamEnd) ; Stack MSB
	out SPH,rmp
	ldi rmp,LOW(RamEnd) ; dto., LSB
	out SPL,rmp
	; Init ports
	clr rmp ; All anodes off
	out pAO,rmp
	ldi rmp,0xFF ; all cathode outputs high
	out p0O,rmp
	out p1O,rmp
	out p2O,rmp
	out pAD,rmp ; Anode driver as output
	out p0D,rmp ; All cathodes as output
	out p1D,rmp
	out p2D,rmp
	; Init output mechanism
	ldi ZH,High(2*Table) ; Z points to table
	ldi ZL,Low(2*Table)
	mov XH,ZH ; X points to the same address
	mov XL,ZL
	ldi rAnd,0xFF ; Set all Ones
	ldi rAnode,1 ; Start with first anode
	ldi rCount,cCount ; Load speed counter
	; Init Timer TC0
	ldi rmp,1<<CS01 ; Prescaler by 8
	out TCCR0,rmp
	ldi rmp,1<<TOIE0 ; TC0-Overflow-Interrupt
	out TIMSK,rmp
	; Sleep and Interrupts
	ldi rmp,1<<SE ; Enable sleep mode idle
	out MCUCR,rmp
	sei
;
; ============================================
;        P R O G R A M   L O O P
; ============================================
;
Loop:
	sleep ; go to sleep
	nop ; Dummy for wake-up
	rjmp loop ; Back to sleep
;
.include "tickertable.inc"
;
; End of  source code
; Copyright
.db "(C)2017 by Gerhard Schmidt  " ; human readable
.db "C(2)10 7ybG reahdrS hcimtd  " ; wordwise
;



Top of page




Praise, dispraise, error reports, criticaster, scolding and unqualified spam please via the comments page to me.

©2017 by http://www.avr-asm-tutorial.net