Sie sind auf Seite 1von 15

1 E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\Debug\AssemblerApplication1.

lss
AVRASM ver. 2.1.52 E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\dewpoint_bb.asm
Wed Dec 04 18:27:35 2013
E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\dewpoint_bb.asm(45): Including file
'E:\Program Files(x86)\Atmel\Atmel Toolchain\AVR Assembler\Native\2.1.39.1005\avrassembler\Include\
m16def.inc'
E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\dewpoint_bb.asm(746): warning:
Register r18 already defined by the .DEF directive
E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\dewpoint_bb.asm(747): warning:
Register r19 already defined by the .DEF directive
E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\dewpoint_bb.asm(792): warning:
Register r16 already defined by the .DEF directive
E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\dewpoint_bb.asm(793): warning:
Register r17 already defined by the .DEF directive
E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\dewpoint_bb.asm(794): warning:
Register r16 already defined by the .DEF directive
E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\dewpoint_bb.asm(795): warning:
Register r17 already defined by the .DEF directive
E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\dewpoint_bb.asm(796): warning:
Register r18 already defined by the .DEF directive
E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\dewpoint_bb.asm(797): warning:
Register r19 already defined by the .DEF directive
E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\dewpoint_bb.asm(798): warning:
Register r20 already defined by the .DEF directive
E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\dewpoint_bb.asm(845): warning:
Register r14 already defined by the .DEF directive
E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\dewpoint_bb.asm(846): warning:
Register r15 already defined by the .DEF directive
E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\dewpoint_bb.asm(847): warning:
Register r16 already defined by the .DEF directive
E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\dewpoint_bb.asm(848): warning:
Register r17 already defined by the .DEF directive
E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\dewpoint_bb.asm(849): warning:
Register r18 already defined by the .DEF directive
E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\dewpoint_bb.asm(850): warning:
Register r19 already defined by the .DEF directive


* dewpoint_bb.asm
* Design Task 1
* ESE 380 Lab 10 Section 3 Table 2
* Author: Raymond Talusan
* LABORATORY 10: Unsigned Binary Computations and Binary to BCD Conversion -
* Introduction to the Thermoelectric Cooler
*
* DESCRIPTION
* Calls "left_shift_Display" to use as an interrupt. Left shift display
* takes a new digit and places it in r0. It shifts the original r0 value
* to r1 and r1 to r2. r2's previous value is discarded. keypress_interrupt
* reads the 3-bit key value from PortD. There are now 2 interrupts.
* mux_display serves as an timer interrupt as "keypress_isr" is an external
* interrupt. Additionally, we add a subroutine display_post. This subroutine
* light all the segments of the display for one second and then blank the display.
* A subroutine is also included that uses ATmega16's ADC to countinously measure
* an analog voltage connected to ADC7. In addtion, we our main objective of this
* program is to measure the dewpoint of the ambient air and display it on the
* LED displays.
*
* INPUTS
* PD2-PD0: input switches
* PD3: input from EO output of Encoder
* PD6: input from DPS
* PA5-PA7: temp inputs
*
* OUTPUTS
2 E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\Debug\AssemblerApplication1.lss
* PORTB: output of switch values at the seven-segment display
* PA0-PA2: output for transistors
* PC6: DPS LED
* PC7: EN_FAN
* PD4-PD5: EN_TEC, C/H output
*
* register Assignments/Purposes
* r0 - dig0
* r1 - dig1
* r2 - dig2
* r16-r21: general purpose
*
* Target: ATmega16 @ 1 MHz
*************************************************************************************/


.list

.dseg
000060 atempl: .byte 1 ;allocate 1 byte for variable
000061 atempm: .byte 1 ;allocate 1 byte for variable


.equ ENFAN = 7
.equ ENTEC = 4
.equ CH = 5
.equ DPS = 6

.cseg
reset:
.org 0 ;reset interrupt vector
000000 940c 0014 jmp intialization ;program starts here at reset

.org INT1addr ;INT1 interrupt vector
000004 940c 00dd jmp keypress_isr

.org OVF0addr ;Timer interrupt vector
000012 940c 009c jmp mux_display_isr



intialization:
;Configure port B as an output port
000014 ef0f ldi r16, $FF ;load r16 with all 1s
000015 bb07 out DDRB, r16 ;port B - all bits configured as outputs

;Configure port A bit 0 & bit 1 as an output
000016 ee07 ldi r16, $E7 ;PA2 - PA0 outputs, others inputs
000017 bb0a out DDRA, r16
000018 e007 ldi r16, $07 ;all digits OFF
000019 bb0b out PORTA, r16

;Configure port D as an input port
00001a e800 ldi r16, $80 ;PD7 LED Output
00001b bb01 out DDRD, r16


;Configure port C
00001c e003 ldi r16, $03 ;PC0/PC1 LED Output
00001d bb04 out DDRC, r16


;load LED register values with 0s
00001e e080 ldi r24, $00
00001f 2e28 mov r2, r24 ;dig2
000020 2e18 mov r1, r24 ;dig1
3 E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\Debug\AssemblerApplication1.lss
000021 2e08 mov r0, r24 ;dig0

;Initialize stack pointer to allow subroutine calls
000022 e50f ldi r16, LOW(RAMEND) ;load low byte of stack pointer
000023 bf0d out SPL, r16
000024 e004 ldi r16, HIGH(RAMEND) ;load high byte of stack pointer
000025 bf0e out SPH, r16

;configure interupt
000026 e00c ldi r16, (1 << ISC11) | (1 << ISC10) ;interrupt sense
000027 bf05 out MCUCR, r16 ;rising edge at INT1 requests interrupt
000028 e800 ldi r16, 1<<INT1 ;enable interrupt request at INT1
000029 bf0b out GICR, r16

00002a e002 ldi r16,(0<<CS02) | (1<<CS01) | (0<<CS00)
00002b bf03 out TCCR0,r16 ; Timer clock = system clock / 8
00002c ef0f ldi r16, $FF ;all segments OFF
00002d bb08 out PORTB, r16
00002e e001 ldi r16,1<<TOIE0
00002f bf09 out TIMSK,r16 ; Enable Timer/Counter0 Overflow Interrupt


;initialize adc conversion
000030 e804 ldi r16,(1<<ADEN)|(1<<ADPS2)|(0<<ADPS1)|(0<<ADPS0) ;load fosc/16
000031 b906 out ADCSRA, r16
000032 ec05 ldi r16, 0b11000101 ;load ADMUX value
000033 b907 out ADMUX, r16


000034 940e 0110 call display_post ;POST test

000036 9478 sei ;set global interrupt enable



main:
000037 ec05 ldi r16, 0b11000101 ;load ADMUX value
000038 b907 out ADMUX, r16
000039 940e 0095 call adc_conv ;call adc_conv for ambient
00003b 9300 0060 sts atempl, r16 ;save low byte for ambient
00003d 9310 0061 sts atempm, r17 ;save high byte for ambient

00003f ec07 ldi r16, 0b11000111 ;mirror temp
000040 b907 out ADMUX, r16

read_mirror:
000041 940e 0095 call adc_conv ;call adc_conv
000043 940e 0070 call displayADC
000045 9120 0060 lds r18, atempl ;load low byte of ambient
000047 9130 0061 lds r19, atempm ;load high byte of ambient
000049 1720 cp r18, r16 ;compare if temp is same
00004a 1731 cp r19, r17
00004b 9320 0060 sts atempl, r18 ;save low byte for ambient
00004d 9330 0061 sts atempm, r19 ;save high byte for ambient
00004f f789 brne read_mirror

more_sec:
000050 e015 ldi r17, 5 ;allow temp to go higher
one_sec:
000051 ef0f ldi r16, $ff ;load delay parameter
000052 940e 00d1 call var_delay ;call var_delay
000054 ef0f ldi r16, $ff ;load delay parameter
000055 940e 00d1 call var_delay ;call var_delay
000057 ef0f ldi r16, $ff ;load delay parameter
000058 940e 00d1 call var_delay ;call var_delay
00005a ef0f ldi r16, $ff ;load delay parameter
4 E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\Debug\AssemblerApplication1.lss
00005b 940e 00d1 call var_delay ;call var_delay
00005d 951a dec r17
00005e f791 brne one_sec

00005f 9a97 sbi PORTD, ENFAN ;cool down temp
000060 9a95 sbi PORTD, CH

000061 940e 0095 call adc_conv
000063 940e 0070 call temp_display ;keep constant display

read_dps:
000065 b300 in r16, PIND ;check for dps 0
000066 940e 0095 call adc_conv
000068 940e 0070 call temp_display ;keep constant display
00006a 9986 sbic PIND, DPS
00006b cff9 rjmp read_dps
00006c 7002 andi r16, $02
00006d bb05 out PORTC, r16 ;light dps led

00006e 9894 cbi PORTD, ENTEC ;turn off drive

00006f cfc7 rjmp main


;********************************************************************
;* "displayADC" - Multiplexes Seven-Segment Display
;*
;* Description:
;* The 10-bit result of the conversion is to be output in hexadecimal
;* to your three-digit seven-segment display.The program must convert
;* the temperature volt to a real value by using multiplication
;* and division subroutines.
;* -from Lab description
;*
;* Author: Raymond Talusan
;* Version: 1.0
;* Last updated: 11/13/13
;* Target: ATmega16
;* Low registers modified: none
;* High registers modified: r16
;* NOTE:
;* Dependent on subroutine mpy16u, div32u, bin2BCD16, hex_2_7seg
;********************************************************************
displayADC:

.cseg
temp_display:
000070 940e 008a call calculation

000072 2f02 mov r16, r18 ;move low byte
000073 2f13 mov r17, r19 ;move high byte
000074 940e 0152 call bin2BCD16 ;change to BCD

000076 2d0d mov r16, r13
000077 700f andi r16, $0f ;keep ms bits
000078 940e 00c2 call hex_2_7seg
00007a 2e00 mov r0, r16 ;enter bcd value to dig

00007b 2d0e mov r16, r14
00007c 700f andi r16, $0f ;keep ls bits
00007d 940e 00c2 call hex_2_7seg
00007f 2e20 mov r2, r16 ;enter bcd value to dig

000080 2d0d mov r16, r13
000081 7f00 andi r16, $f0 ;keep ls bits
000082 9506 lsr r16 ;move to ms bits
5 E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\Debug\AssemblerApplication1.lss
000083 9506 lsr r16
000084 9506 lsr r16
000085 9506 lsr r16
000086 940e 00c2 call hex_2_7seg
000088 2e10 mov r1, r16 ;enter bcd value to dig

000089 9508 ret


;********************************************************************
;* "calculation" - multiples and divide
;*
;* Description:
;* Does the necessary conversions to get a bcd value.
;*
;* Author: Raymond Talusan
;* Version: 1.0
;* Last updated: 11/13/13
;* Target: ATmega16
;* Low registers modified: none
;* High registers modified: r16
;* NOTE:
;* Dependent on subroutine mpy16u, div32u, bin2BCD16, hex_2_7seg
;********************************************************************

.cseg
calculation:
;multiply ADC by 5

00008a b104 in r16, ADCL ;multiplicand low byte
00008b b115 in r17, ADCH ;multiplicand high byte

00008c e025 ldi r18, 5 ;multiplier low byte
00008d e030 ldi r19, 0 ;multiplity high byte

00008e d0a1 rcall mpy16u
;desired result is now in r18, r19

;divide ADC by 2

00008f 2f02 mov r16, r18 ;dividend low byte
000090 2f13 mov r17, r19 ;dividend high byte

000091 e022 ldi r18, 2 ;divisor low byte
000092 e030 ldi r19, 0 ;divisor high byte

000093 d0ab rcall div16u
;desired result is now in r16,r17
000094 9508 ret


;********************************************************************
;* "adc_conv" - Multiplexes Seven-Segment Display
;*
;* Description:
;* This program uses the ATmega16s ADC to continuously measure an
;* analog voltage connected to its ADC7 pin. This is accomplished by
;* operating the ADC in single conversion mode and continuously
;* performing conversions. Use an ADC clock prescalar value of 16.
;* The program must poll appropriate ADC flag to determine when
;* a conversion is complete.
;* -from Lab description
;*
;* Author: Raymond Talusan
;* Version: 1.0
;* Last updated: 11/13/13
6 E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\Debug\AssemblerApplication1.lss
;* Target: ATmega16
;* Low registers modified: none
;* High registers modified: r16
;********************************************************************

.cseg
adc_conv:
000095 9a36 sbi ADCSRA, ADSC ;start conversion

read_adc:
000096 9b34 sbis ADCSRA, ADIF ;wait for end of conversion
000097 cffe rjmp read_adc
000098 9a34 sbi ADCSRA, ADIF ;clear adif flag
000099 b104 in r16, ADCL ;read adcl
00009a b115 in r17, ADCH ;read adch

00009b 9508 ret

;***************************************************
;* "mux_display_isr" - Multiplexes Seven-Segment Display
;* Interrupt
;* Description: Each time subroutine is called it turns OFF the
;* previous digit and turns ON the next digit of a three digit
;* seven segment display.The segment values to be displayed are
;* taken from registers r2 through r0 for digits dig2 to dig0
;* respectively. The subroutine maintains a digit counter (r20)
;* indicating which digit is currently being displayed.
;* To keep each digit ON for a longer time requires a separate
;* delay subroutine.
;*
;* Original author: Ken Short
;* Modified by: Raymond Talusan
;* Target: ATmega16
;* Number of words: 20
;* Number of cycles: 20-23
;* Low registers modified: none
;* High registers modified: r20, r16
;*
;* Parameters: The segment values to be displayed are passed in
;* r0 - r2
;* r0 - dig0
;* r1 - dig1
;* r2 - dig2
;*
;* Notes: 0s turn on digits and 0s turn on segments
;* The segments are a through g at PB6 through PB0 respectively.
;* The digit drivers are PA2 through PA0 for digits dig2 through.
;* dig0
;**************************************************************

mux_display_isr:
00009c 930f push r16 ;save registers and status
00009d b70f in r16, SREG
00009e 930f push r16

00009f b30b in r16, PORTA ;turn all digits OFF
0000a0 7f08 andi r16, 0b11111000
0000a1 6007 ori r16, 0b00000111
0000a2 bb0b out PORTA, r16

0000a3 0000 nop ;slight delay to prevent display ghosting
0000a4 0000 nop
0000a5 0000 nop
0000a6 0000 nop
0000a7 0000 nop

7 E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\Debug\AssemblerApplication1.lss
0000a8 9583 inc r24 ;increment digit counter

0000a9 3080 cpi r24, 0 ;check value of digit counter & transfer control
0000aa f031 breq lite_dig0
0000ab 3081 cpi r24, 1
0000ac f039 breq lite_dig1
0000ad 3082 cpi r24, 2
0000ae f041 breq lite_dig2
0000af e000 ldi r16, 0 ;digit counter was incremented to 3,change to 0
0000b0 2f80 mov r24, r16

lite_dig0: ;activate digit 0
0000b1 ba08 out PORTB, r0 ;output digit 0 seven-segment value
0000b2 98d8 cbi PORTA, 0 ;turn on digit 0 driver
0000b3 c005 rjmp exit_update_display

lite_dig1: ;activate digit 1
0000b4 ba18 out PORTB, r1 ;output digit 1 seven-segment value
0000b5 98d9 cbi PORTA, 1 ;turn on digit 1 driver
0000b6 c002 rjmp exit_update_display

lite_dig2: ;activate digit 2
0000b7 ba28 out PORTB, r2 ;output digit 2 seven-segment value
0000b8 98da cbi PORTA, 2 ;turn on digit 2 driver

exit_update_display:
0000b9 910f pop r16 ;restore status and registers
0000ba bf0f out SREG, r16
0000bb 910f pop r16
0000bc 9518 reti

;*****************************************************************
;*
;* "left_shift_display" - Subroutine to Left Shift the Seven-Segment
;* Display and Enter a New Digit
;*
;* calls "hex_2_7seg" subroutine
;*
;* Description: This subroutine is passed a value in r16.
;* This value is interpreted as a right justified hexadecimal digit.
;* The subroutine shifts the registers r2 through r0 one digit
;* position to the left. The subroutine then enters the seven-segment
;* value, corresponding to the hexadecimal digit passed in r16, into r0.
;* To do the later, subroutine left_shift_display calls subroutine
;* hex_2_7seg to get the seven-segment value.
;* Original description by: Ken Short
;* Modified by: Raymond Talusan
;* Target: ATmega16
;* Number of words: 5
;* Number of cycles: 9 + 13 from hex_2_7seg subroutine = 22
;* Low registers modified: none
;* High registers modified: r16
;*
;* Parameters: The segment values to be shifted are passed in r0 - r2
;* r0 - dig0
;* r1 - dig1
;* r2 - dig2
;* r16 - hex input value to be used in hex_2_7seg to load in r0
;*
;*********************************************************************


left_shift_display:

0000bd d004 rcall hex_2_7seg ;convert hex value in r16 to seven-segment

8 E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\Debug\AssemblerApplication1.lss
0000be 2c21 mov r2, r1 ;shift left r2,r1,r0 <- r16
0000bf 2c10 mov r1, r0
0000c0 2e00 mov r0, r16

0000c1 9508 ret


;*************************************************************
;*
;* "hex_2_7seg" - Hexadecimal to Seven-Segment Table Look Up
;*
;* Description: This subroutine receives a hexadecimal value, right
;* justified, in r16 and returns its seven-segment representation
;* in r16.If the value received is greater than 15, the value
;* displayed should be the input value modulo 16. The segments
;* are assigned with a through g in bits 6 through 0. 0s in the
;* seven-segment pattern turn segments ON an
;* 1s turn segments OFF.
;* Original author: Ken Short
;* Modified by: Raymond Talusan
;* Target: ATmega16
;* Number of words: 7
;* Number of cycles: 13
;* Low registers modified: none
;* High registers modified: r16
;*
;* Parameters: The segment values to be displayed are passed to r16
;* r16 - input hex value to a 7seg output
;*************************************************************
.
hex_2_7seg:

0000c2 700f andi r16, $0F ;mask for hex digit
0000c3 e0f1 ldi ZH, high (hextable * 2) ;set Z to point to start of table
0000c4 e9e2 ldi ZL, low (hextable * 2)

0000c5 0fe0 add ZL, r16

0000c6 9104 lpm r16, Z ;load byte from table pointed to by Z
0000c7 6800 ori r16, $80 ;decimal off

0000c8 9508 ret

;Table of segment values to display digits 0 - F

0000c9 4f01
0000ca 0612
0000cb 244c
0000cc 0f20
0000cd 0c00 hextable: .db $01, $4F, $12, $06, $4C, $24, $20, $0F, $00, $0C
0000ce 6008
0000cf 4230
0000d0 3830 .db $08, $60, $30, $42, $30, $38


;************************************************************************
;*
;* "var_delay" - Hexadecimal to Seven-Segment Table Look Up
;*
;* Description: This subroutine is passed a value in r16 that is the
;* desired duration of the delay in 0.1 ms increments. Thus, the delay
;* can range from approximately 0.1 ms to 25.6 ms.
;*
;* Original description: Ken Short
;* Modified by: Raymond Talusan
;* Target: ATmega16 @ 1 MHz
9 E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\Debug\AssemblerApplication1.lss
;* Number of words: 10
;* Number of cycles: r16 * 100
;* Low registers modified: none
;* High registers modified: r16
;*
;* Parameters: The segment values to be displayed are passed to r16
;* r16 - delay counter
;********************************************************************

var_delay: ;delay for ATmega16 @ 1MHz
0000d1 931f push r17
0000d2 b71f in r17, SREG
0000d3 931f push r17

o_loop:
0000d4 e210 ldi r17, 32 ;
i_loop:
0000d5 951a dec r17
0000d6 f7f1 brne i_loop
0000d7 950a dec r16
0000d8 f7d9 brne o_loop

0000d9 911f pop r17
0000da bf1f out SREG, r17
0000db 911f pop r17

0000dc 9508 ret


;****************************************************************
;*
;* "keypress_isr" - Count Interrupts at INT1
;*
;* calls "left_shift_display"
;*
;* Description: Edge triggered interrupt at INT1 (PD3)
;* to left shift the displays
;*
;* Modified by: Raymond Talusan
;* Target: ATmega16
;* Number of words: 0
;* Number of cycles: 41
;* Low registers modified: none
;* High registers modified: r16
;*
;* Parameters: Uses register r16 to taken PIND value and
;* call subroutine "left_shift_display"
;* .
;*
;* Notes:
;*
;******************************************************************

;INT1 interrupt service routine


keypress_isr:


0000dd 930f push r16 ;save r16
0000de b70f in r16, SREG ;save SREG
0000df 930f push r16
0000e0 933f push r19



10 E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\Debug\AssemblerApplication1.lss
;LEDS OFF
0000e1 9897 cbi PORTD, 7
0000e2 98a8 cbi PORTC, 0
0000e3 98a9 cbi PORTC, 1


0000e4 e03a ldi r19, 10 ;wait var x 0.1ms for debounce to go away
0000e5 940e 00d1 call var_delay


0000e7 b330 in r19, PIND
0000e8 7037 andi r19, $07 ; mask, just want first 3 bit

;check pushbutton press 7/6/5
0000e9 3030 cpi r19, 0
0000ea f029 breq yellow
0000eb 3031 cpi r19, 1
0000ec f049 breq green
0000ed 3032 cpi r19, 2
0000ee f069 breq red

0000ef c011 rjmp finish_press




;pushbutton 7
yellow:

0000f0 ec36 ldi r19, $C6
0000f1 b937 out ADMUX, r19
0000f2 9a97 sbi PORTD, 7
0000f3 98a8 cbi PORTC, 0
0000f4 98a9 cbi PORTC, 1

0000f5 c00b rjmp finish_press

;pushbutton 6
green:

0000f6 ec37 ldi r19, $C7
0000f7 b937 out ADMUX, r19
0000f8 9aa8 sbi PORTC, 0
0000f9 9897 cbi PORTD, 7
0000fa 98a9 cbi PORTC, 1

0000fb c005 rjmp finish_press

;pushbutton 5

red:

0000fc ec35 ldi r19, $C5
0000fd b937 out ADMUX, r19
0000fe 9aa9 sbi PORTC, 1
0000ff 9897 cbi PORTD, 7
000100 98a8 cbi PORTC, 0

finish_press:


;disable INT1

000101 e030 ldi r19, (0 << INT1)
000102 bf3b out GICR, r19
000103 9478 sei ;enable mux_display interrupt
11 E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\Debug\AssemblerApplication1.lss

pollkey: ;checks for release


000104 9983 sbic PIND, 3 ;check E0 for 0 for break
000105 cffe rjmp pollkey ;loop checking E0 hold press


000106 e03a ldi r19,10 ;wait var x 0.1ms for debounce to go away
000107 940e 00d1 call var_delay


;enable INT1

000109 e830 ldi r19, (1 << INT1)
00010a bf3b out GICR, r19

00010b 913f pop r19
00010c 910f pop r16 ;restore SREG
00010d bf0f out SREG,r16 ;restore r16
00010e 910f pop r16


00010f 9518 reti

;****************************************************************
;*
;* "display_post" - Power-on self test (POST) subroutine
;*
;* Description: This subroutine lights all of the segments of
;* all of the
;* digits of the seven-segment display for approximately one
;* second and then
;* blanks the display.
;*
;* 50 ms x 20 = 1 second
;*
;* Original description by: Ken Short
;* Modified by: Raymond Talusan
;* Target: ATmega16 @ 1 MHz
;* Number of words:
;* Number of cycles:
;* Low registers modified: none
;* High registers modified: r16, r17,r18
;*
;* Parameters:
;*
;**************************************************************


display_post:

000110 e000 ldi r16, $00
000111 bb08 out PORTB, r16 ;turn all segements

;LEDS ON
000112 9a97 sbi PORTD, 7
000113 9aa8 sbi PORTC, 0
000114 9aa9 sbi PORTC, 1

000115 ec28 ldi r18, 200 ; 20 times 50ms is calledfor 1 s

000116 ef0e ldi r16, $FE
000117 bb0b out PORTA, r16 ;start with dig0 turned on

m_loop:
12 E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\Debug\AssemblerApplication1.lss
;mux
000118 9bc8 sbis PINA, 0 ;if it displayed dig0
000119 ef0d ldi r16, $FD ;display dig1 next
00011a 9bc9 sbis PINA, 1 ;if it displayed dig1
00011b ef0b ldi r16, $FB ;display dig2 next
00011c 9bca sbis PINA, 2 ;if it displayed dig2
00011d ef0e ldi r16, $FE ;displat dig0 next

00011e bb0b out PORTA, r16 ;turn on dig0/1/2

loop:


00011f 940e 0129 call delay_50ms
000121 952a dec r18
000122 f7a9 brne m_loop ;loop again to main loop if not 0

;LEDS OFF
000123 9897 cbi PORTD, 7
000124 98a8 cbi PORTC, 0
000125 98a9 cbi PORTC, 1

000126 e007 ldi r16, $07
000127 bb0b out PORTA, r16 ;start with dig0 turned on

000128 9508 ret ; one second delay is done

delay_50ms: ;50 ms delay for ATmega16 @ 1MHz
000129 e017 ldi r17, 7
outer_loop:
00012a ef0f ldi r16, $FF
inner_loop:
00012b 950a dec r16
00012c f7f1 brne inner_loop ;branch if r16 not equal 0
00012d 951a dec r17
00012e f7d9 brne outer_loop ;branch if r17 not equal 0
00012f 9508 ret



;********************************************************************
;*
;* "mpy16u" - 16x16 Bit Unsigned Multiplication
;*
;* This subroutine multiplies the two 16-bit register variables
;* mp16uH:mp16uL and mc16uH:mc16uL.
;* The result is placed in m16u3:m16u2:m16u1:m16u0.
;*
;* Number of words :14 + return
;* Number of cycles :153 + return
;* Low registers used :None
;* High registers used :7 (mp16uL,mp16uH,mc16uL/m16u0,mc16uH/m16u1,m16u2
;* m16u3,mcnt16u)
;*
;**********************************************************************

;***** Subroutine Register Variables

.def mc16uL =r16 ;multiplicand low byte
.def mc16uH =r17 ;multiplicand high byte
.def mp16uL =r18 ;multiplier low byte
.def mp16uH =r19 ;multiplier high byte
.def m16u0 =r18 ;result byte 0 (LSB)
.def m16u1 =r19 ;result byte 1
.def m16u2 =r20 ;result byte 2
.def m16u3 =r21 ;result byte 3 (MSB)
13 E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\Debug\AssemblerApplication1.lss
.def mcnt16u =r22 ;loop counter

;***** Code

000130 2755 mpy16u: clr m16u3 ;clear 2 highest bytes of result
000131 2744 clr m16u2
000132 e160 ldi mcnt16u,16 ;init loop counter
000133 9536 lsr mp16uH
000134 9527 ror mp16uL

000135 f410 m16u_1: brcc noad8 ;if bit 0 of multiplier set
000136 0f40 add m16u2,mc16uL ;add multiplicand Low to byte 2 of res
000137 1f51 adc m16u3,mc16uH ;add multiplicand high to byte 3 of res
000138 9557 noad8: ror m16u3 ;shift right result byte 3
000139 9547 ror m16u2 ;rotate right result byte 2
00013a 9537 ror m16u1 ;rotate result byte 1 and multiplier High
00013b 9527 ror m16u0 ;rotate result byte 0 and multiplier Low
00013c 956a dec mcnt16u ;decrement loop counter
00013d f7b9 brne m16u_1 ;if not done, loop more
00013e 9508 ret

;*********************************************************************
;*
;* "div16u" - 16/16 Bit Unsigned Division
;*
;* This subroutine divides the two 16-bit numbers
;* "dd8uH:dd8uL" (dividend) and "dv16uH:dv16uL" (divisor).
;* The result is placed in "dres16uH:dres16uL" and the remainder in
;* "drem16uH:drem16uL".
;*
;* Number of words :19
;* Number of cycles :235/251 (Min/Max)
;* Low registers used :2 (drem16uL,drem16uH)
;* High registers used :5 (dres16uL/dd16uL,dres16uH/dd16uH,dv16uL,dv16uH
;* dcnt16u)
;*
;**********************************************************************

;***** Subroutine Register Variables

.def drem16uL=r14
.def drem16uH=r15
.def dres16uL=r16
.def dres16uH=r17
.def dd16uL =r16
.def dd16uH =r17
.def dv16uL =r18
.def dv16uH =r19
.def dcnt16u =r20

;***** Code

00013f 24ee div16u: clr drem16uL ;clear remainder Low byte
000140 18ff sub drem16uH,drem16uH;clear remainder High byte and carry
000141 e141 ldi dcnt16u,17 ;init loop counter
000142 1f00 d16u_1: rol dd16uL ;shift left dividend
000143 1f11 rol dd16uH
000144 954a dec dcnt16u ;decrement counter
000145 f409 brne d16u_2 ;if done
000146 9508 ret ; return
000147 1cee d16u_2: rol drem16uL ;shift dividend into remainder
000148 1cff rol drem16uH
000149 1ae2 sub drem16uL,dv16uL ;remainder = remainder - divisor
00014a 0af3 sbc drem16uH,dv16uH ;
00014b f420 brcc d16u_3 ;if result negative
00014c 0ee2 add drem16uL,dv16uL ; restore remainder
14 E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\Debug\AssemblerApplication1.lss
00014d 1ef3 adc drem16uH,dv16uH
00014e 9488 clc ; clear carry to be shifted into result
00014f cff2 rjmp d16u_1 ;else
000150 9408 d16u_3: sec ; set carry to be shifted into result
000151 cff0 rjmp d16u_1


;*********************************************************************
;*
;* "bin2BCD16" - 16-bit Binary to BCD conversion
;*
;* This subroutine converts a 16-bit number (fbinH:fbinL) to a 5-digit
;* packed BCD number represented by 3 bytes (tBCD2:tBCD1:tBCD0).
;* MSD of the 5-digit number is placed in the lowermost nibble of tBCD2.
;*
;* Number of words :25
;* Number of cycles :751/768 (Min/Max)
;* Low registers used :3 (tBCD0,tBCD1,tBCD2)
;* High registers used :4(fbinL,fbinH,cnt16a,tmp16a)
;* Pointers used :Z
;*
;**********************************************************************

;***** Subroutine Register Variables
.
.equ AtBCD0 =13 ;address of tBCD0
.equ AtBCD2 =15 ;address of tBCD1

.def tBCD0 =r13 ;BCD value digits 1 and 0
.def tBCD1 =r14 ;BCD value digits 3 and 2
.def tBCD2 =r15 ;BCD value digit 4
.def fbinL =r16 ;binary value Low byte
.def fbinH =r17 ;binary value High byte
.def cnt16a =r18 ;loop counter
.def tmp16a =r19 ;temporary value

;***** Code

bin2BCD16:
000152 e120 ldi cnt16a,16 ;Init loop counter
000153 24ff clr tBCD2 ;clear result (3 bytes)
000154 24ee clr tBCD1
000155 24dd clr tBCD0
000156 27ff clr ZH ;clear ZH (not needed for AT90Sxx0x)
000157 0f00 bBCDx_1:lsl fbinL ;shift input value
000158 1f11 rol fbinH ;through all bytes
000159 1cdd rol tBCD0 ;
00015a 1cee rol tBCD1
00015b 1cff rol tBCD2
00015c 952a dec cnt16a ;decrement loop counter
00015d f409 brne bBCDx_2 ;if counter not zero
00015e 9508 ret ; return

00015f e1e0 bBCDx_2:ldi r30,AtBCD2+1 ;Z points to result MSB + 1
bBCDx_3:
000160 9132 ld tmp16a,-Z ;get (Z) with pre-decrement
;----------------------------------------------------------------
;For AT90Sxx0x, substitute the above line with:
;
; dec ZL
; ld tmp16a,Z
;
;----------------------------------------------------------------
000161 5f3d subi tmp16a,-$03 ;add 0x03
000162 fd33 sbrc tmp16a,3 ;if bit 3 not clear
000163 8330 st Z,tmp16a ; store back
15 E:\Documents\Atmel Studio\AssemblerApplication1\AssemblerApplication1\Debug\AssemblerApplication1.lss
000164 8130 ld tmp16a,Z ;get (Z)
000165 5d30 subi tmp16a,-$30 ;add 0x30
000166 fd37 sbrc tmp16a,7 ;if bit 7 not clear
000167 8330 st Z,tmp16a ; store back
000168 30ed cpi ZL,AtBCD0 ;done all three?
000169 f7b1 brne bBCDx_3 ;loop again if not
RESOURCE USE INFORMATION
------------------------
Notice:
The register and instruction counts are symbol table hit counts,
and hence implicitly used resources are not counted, eg, the
'lpm' instruction without operands implicitly uses r0 and z,
none of which are counted.
x,y,z are separate entities in the symbol table and are
counted separately from r26..r31 here.
.dseg memory usage only counts static data declared with .byte
"ATmega16" register use summary:
r0 : 5 r1 : 5 r2 : 4 r3 : 0 r4 : 0 r5 : 0 r6 : 0 r7 : 0
r8 : 0 r9 : 0 r10: 0 r11: 0 r12: 0 r13: 4 r14: 7 r15: 7
r16: 97 r17: 21 r18: 15 r19: 38 r20: 5 r21: 3 r22: 2 r23: 0
r24: 9 r25: 0 r26: 0 r27: 0 r28: 0 r29: 0 r30: 4 r31: 2
x : 0 y : 0 z : 5
Registers used: 17 out of 35 (48.6%)
"ATmega16" instruction use summary:
.lds : 0 .sts : 0 adc : 2 add : 3 adiw : 0 and : 0
andi : 7 asr : 0 bclr : 0 bld : 0 brbc : 0 brbs : 0
brcc : 2 brcs : 0 break : 0 breq : 6 brge : 0 brhc : 0
brhs : 0 brid : 0 brie : 0 brlo : 0 brlt : 0 brmi : 0
brne : 11 brpl : 0 brsh : 0 brtc : 0 brts : 0 brvc : 0
brvs : 0 bset : 0 bst : 0 call : 20 cbi : 16 cbr : 0
clc : 1 clh : 0 cli : 0 cln : 0 clr : 7 cls : 0
clt : 0 clv : 0 clz : 0 com : 0 cp : 2 cpc : 0
cpi : 7 cpse : 0 dec : 9 eor : 0 fmul : 0 fmuls : 0
fmulsu: 0 icall : 0 ijmp : 0 in : 10 inc : 1 jmp : 3
ld : 2 ldd : 0 ldi : 50 lds : 2 lpm : 2 lsl : 1
lsr : 5 mov : 17 movw : 0 mul : 0 muls : 0 mulsu : 0
neg : 0 nop : 5 or : 0 ori : 2 out : 33 pop : 7
push : 7 rcall : 3 ret : 11 reti : 2 rjmp : 12 rol : 8
ror : 5 sbc : 1 sbci : 0 sbi : 10 sbic : 2 sbis : 4
sbiw : 0 sbr : 0 sbrc : 2 sbrs : 0 sec : 1 seh : 0
sei : 2 sen : 0 ser : 0 ses : 0 set : 0 sev : 0
sez : 0 sleep : 0 spm : 0 st : 2 std : 0 sts : 4
sub : 2 subi : 2 swap : 0 tst : 0 wdr : 0
Instructions used: 45 out of 113 (39.8%)
"ATmega16" memory use summary [bytes]:
Segment Begin End Code Data Used Size Use%
---------------------------------------------------------------
[.cseg] 0x000000 0x0002d6 682 16 698 16384 4.3%
[.dseg] 0x000060 0x000062 0 2 2 1024 0.2%
[.eseg] 0x000000 0x000000 0 0 0 512 0.0%
Assembly complete, 0 errors, 15 warnings

Das könnte Ihnen auch gefallen