Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
avrkurs
avrkurs
Commits
a0533b93
Commit
a0533b93
authored
Apr 21, 2021
by
kaspems
Browse files
stappet adc inn i session2 og kuttet uart. har ikke testet LF
parent
330aa4c5
Changes
31
Hide whitespace changes
Inline
Side-by-side
Session1-LF/Task1-LF.c
View file @
a0533b93
...
...
@@ -58,7 +58,7 @@ int main(void){
while
(
1
)
{
PORTF
.
OUT
^
=
(
1
<<
LED0
);
// Changes the state of LED0 by XOR-ing the last state. Check the XOR-table to find out how this works.
PORTF
.
OUT
|
=
(
1
<<
LED0
);
// Changes the state of LED0 by XOR-ing the last state. Check the XOR-table to find out how this works.
// Non-compressed: PORTF.OUT = PORTF.OUT ^ (1 << LED0);
//Can also refer to toogle register: PORTF.OUTTGL = (1 << LED0). IMPORTANT: only use equal sign here (=)
_delay_ms
(
500
);
...
...
Session2-LF/
UART/UART
-LF.c
→
Session2-LF/
ADC/ADC
-LF.c
View file @
a0533b93
/*
* UART-LF.c
*
* Created: 29.01.2017 23:43:39
* Author : Petter
* ADC-LF.c
*/
#define F_CPU 3333333
#define BAUD_9600 4*F_CPU/9600
char
uart_str
[
64
];
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
/*
In this exercise we will set up and use UART communication.
The embedded debugger has a virtual com port that we will use to communicate with the computer.
In this exercise we will set up and use the ADC (analog-digital converter). We will output the voltage over UART.
*/
#define TX_PORT PORTB
#define TX_PIN 0
#define KLAKK 0x00
void
uart_init
(
unsigned
long
baud
){
//From chapter 22.3.1 in datasheet
//Sets up registers for UART
TX_PORT
.
OUTSET
=
(
1
<<
TX_PIN
);
//Setting up TX pin as output
TX_PORT
.
DIRSET
=
(
1
<<
TX_PIN
);
//Setting up TX pin as output
...
...
@@ -44,10 +41,8 @@ void uart_init(unsigned long baud){
USART3
.
CTRLA
|=
(
1
<<
USART_RXCIE_bp
);
}
// function to transmit data
void
uart_transmit
(
char
data
){
//In this function we will be send data.
void
uart_transmit
(
char
data
){
//Sends a character over UART
//First we should check that there isn't already data being sent
// if there is, we should probably wait for it to finish first
...
...
@@ -68,26 +63,61 @@ void uart_transmit_string(char* data) {
}
}
//helper function for converting data from adc into a nice readable format, and sending it over UART
void
uart_print_voltage
(
uint16_t
data
)
{
uint16_t
data2
=
data
/
4
;
//yes
uint8_t
voltage_integer
=
data2
*
323ul
/
100000ul
;
//This is a lot faster than floats. Compiler magic
uint8_t
voltage_fraction
=
(
data2
*
323ul
%
100000ul
)
/
1000
;
sprintf
(
uart_str
,
"Voltage: %u.%02u V
\n
"
,
voltage_integer
,
voltage_fraction
);
//format string and put voltage
uart_transmit_string
(
uart_str
);
}
void
adc_init
()
{
ADC0
.
CTRLA
|=
(
ADC_RESSEL_10BIT_gc
);
//Set resolution, we choose 10 bits
ADC0
.
CTRLB
|=
(
ADC_SAMPNUM_ACC4_gc
);
//OPTIONAL: We can use multiple samples if we like, example here with 4
//More samples gives a better result but takes longer.
ADC0
.
CTRLC
|=
(
ADC_REFSEL_VDDREF_gc
);
//We select to use the supply voltage (VDD) as voltage reference
ADC0
.
CTRLC
|=
(
ADC_PRESC_DIV2_gc
);
//ADC clock prescaler, best accuracy when run below 2MHz. (Here div2 ~1.46 MHz)
ADC0
.
CTRLA
|=
(
ADC_ENABLE_bm
);
//Enable the ADC
}
uint16_t
adc_read
(
uint8_t
channel
){
ADC0
.
MUXPOS
=
channel
;
//Select input on the ADC mux
//NOTE: We can use = here because this is the only thing the register holds. Neat!
ADC0
.
INTFLAGS
|=
(
ADC_RESRDY_bm
);
//Clear the results ready flag
ADC0
.
COMMAND
|=
(
ADC_STCONV_bm
);
//Start a conversion
while
(
!
(
ADC0
.
INTFLAGS
&
ADC_RESRDY_bm
)){
//Wait for the results ready flag to be set
}
return
ADC0
.
RES
;
//Return 10 bit result
}
int
main
(
void
)
{
//Initialize the UART with our function.
//We will be using a baudrate of 9600 (defined as BAUD_9600 at the top of the file)
uart_init
(
BAUD_9600
);
adc_init
();
sei
();
//Enable inerrupt, important for anything here to work
uint16_t
data
;
while
(
1
)
{
//We don't really need to do anything here.
//the ISR will handle receiving.
uart_transmit_string
(
"Dette er en test
\n
"
);
_delay_ms
(
200
);
//get voltage from adc_read and send it over UART
data
=
adc_read
(
KLAKK
);
//update data each loop using polling.
uart_print_voltage
(
data
);
//print voltage over UART
}
}
//Interrupt service routine for the receiver.
//Interrupt service routine for the
UART
receiver.
Doesn't actually do anything with the received data.
ISR
(
USART3_RXC_vect
)
{
//In the interrupt we will read the data in the receive buffer
...
...
Session2-LF/UART/.vs/UART/v14/.atsuo
deleted
100644 → 0
View file @
330aa4c5
File deleted
Session2-LF/UART/Debug/Makefile
deleted
100644 → 0
View file @
330aa4c5
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
SHELL
:=
cmd.exe
RM
:=
rm
-rf
USER_OBJS
:=
LIBS
:=
PROJ
:=
O_SRCS
:=
C_SRCS
:=
S_SRCS
:=
S_UPPER_SRCS
:=
OBJ_SRCS
:=
ASM_SRCS
:=
PREPROCESSING_SRCS
:=
OBJS
:=
OBJS_AS_ARGS
:=
C_DEPS
:=
C_DEPS_AS_ARGS
:=
EXECUTABLES
:=
OUTPUT_FILE_PATH
:=
OUTPUT_FILE_PATH_AS_ARGS
:=
AVR_APP_PATH
:=
$$$AVR_APP_PATH$$
$
QUOTE
:=
"
ADDITIONAL_DEPENDENCIES
:=
OUTPUT_FILE_DEP
:=
LIB_DEP
:=
LINKER_SCRIPT_DEP
:=
# Every subdirectory with source files must be described here
SUBDIRS
:=
# Add inputs and outputs from these tool invocations to the build variables
C_SRCS
+=
\
../UART-LF.c
PREPROCESSING_SRCS
+=
ASM_SRCS
+=
OBJS
+=
\
UART-LF.o
OBJS_AS_ARGS
+=
\
UART-LF.o
C_DEPS
+=
\
UART-LF.d
C_DEPS_AS_ARGS
+=
\
UART-LF.d
OUTPUT_FILE_PATH
+=
UART.elf
OUTPUT_FILE_PATH_AS_ARGS
+=
UART.elf
ADDITIONAL_DEPENDENCIES
:=
OUTPUT_FILE_DEP
:=
./makedep.mk
LIB_DEP
+=
LINKER_SCRIPT_DEP
+=
# AVR32/GNU C Compiler
./%.o
:
.././%.c
@
echo Building file:
$<
@
echo Invoking: AVR/GNU C Compiler : 5.4.0
$(QUOTE)
C:
\P
rogram Files (x86)
\A
tmel
\S
tudio
\7
.0
\t
oolchain
\a
vr8
\a
vr8-gnu-toolchain
\b
in
\a
vr-gcc.exe
$(QUOTE)
-x c -funsigned-char -funsigned-bitfields -DDEBUG -I"
C:
\P
rogram Files
(
x86
)
\A
tmel
\S
tudio
\7
.0
\P
acks
\a
tmel
\A
Tmega_DFP
\1
.2.150
\i
nclude
" -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega4809 -B "
C:
\P
rogram Files
(
x86
)
\A
tmel
\S
tudio
\7
.0
\P
acks
\a
tmel
\A
Tmega_DFP
\1
.2.150
\g
cc
\d
ev
\a
tmega4809
" -c -std=gnu99 -MD -MP -MF "
$
(
@:%.o
=
%.d
)
" -MT"
$
(
@:%.o
=
%.d
)
" -MT"
$
(
@:%.o
=
%.o
)
" -o "
$@
" "
$<
"
@
echo Finished building:
$<
# AVR32/GNU Preprocessing Assembler
# AVR32/GNU Assembler
ifneq
($(MAKECMDGOALS),clean)
ifneq
($(strip $(C_DEPS)),)
-include
$(C_DEPS)
endif
endif
# Add inputs and outputs from these tool invocations to the build variables
# All Target
all
:
$(OUTPUT_FILE_PATH) $(ADDITIONAL_DEPENDENCIES)
$(OUTPUT_FILE_PATH)
:
$(OBJS) $(USER_OBJS) $(OUTPUT_FILE_DEP) $(LIB_DEP) $(LINKER_SCRIPT_DEP)
@
echo
Building target:
$@
@
echo
Invoking: AVR/GNU Linker : 5.4.0
$(QUOTE)
C:
\P
rogram Files
(
x86
)
\A
tmel
\S
tudio
\7
.0
\t
oolchain
\a
vr8
\a
vr8-gnu-toolchain
\b
in
\a
vr-gcc.exe
$(QUOTE)
-o
$(OUTPUT_FILE_PATH_AS_ARGS)
$(OBJS_AS_ARGS)
$(USER_OBJS)
$(LIBS)
-Wl
,-Map
=
"UART.map"
-Wl
,--start-group
-Wl
,-lm
-Wl
,--end-group
-Wl
,--gc-sections
-mmcu
=
atmega4809
-B
"C:
\P
rogram Files (x86)
\A
tmel
\S
tudio
\7
.0
\P
acks
\a
tmel
\A
Tmega_DFP
\1
.2.150
\g
cc
\d
ev
\a
tmega4809"
@
echo
Finished building target:
$@
"C:
\P
rogram Files (x86)
\A
tmel
\S
tudio
\7
.0
\t
oolchain
\a
vr8
\a
vr8-gnu-toolchain
\b
in
\a
vr-objcopy.exe"
-O
ihex
-R
.eeprom
-R
.fuse
-R
.lock
-R
.signature
-R
.user_signatures
"UART.elf"
"UART.hex"
"C:
\P
rogram Files (x86)
\A
tmel
\S
tudio
\7
.0
\t
oolchain
\a
vr8
\a
vr8-gnu-toolchain
\b
in
\a
vr-objcopy.exe"
-j
.eeprom
--set-section-flags
=
.eeprom
=
alloc,load
--change-section-lma
.eeprom
=
0
--no-change-warnings
-O
ihex
"UART.elf"
"UART.eep"
||
exit
0
"C:
\P
rogram Files (x86)
\A
tmel
\S
tudio
\7
.0
\t
oolchain
\a
vr8
\a
vr8-gnu-toolchain
\b
in
\a
vr-objdump.exe"
-h
-S
"UART.elf"
>
"UART.lss"
"C:
\P
rogram Files (x86)
\A
tmel
\S
tudio
\7
.0
\t
oolchain
\a
vr8
\a
vr8-gnu-toolchain
\b
in
\a
vr-objcopy.exe"
-O
srec
-R
.eeprom
-R
.fuse
-R
.lock
-R
.signature
-R
.user_signatures
"UART.elf"
"UART.srec"
"C:
\P
rogram Files (x86)
\A
tmel
\S
tudio
\7
.0
\t
oolchain
\a
vr8
\a
vr8-gnu-toolchain
\b
in
\a
vr-size.exe"
"UART.elf"
# Other Targets
clean
:
-
$(RM)
$(OBJS_AS_ARGS)
$(EXECUTABLES)
-
$(RM)
$(C_DEPS_AS_ARGS)
rm
-rf
"UART.elf"
"UART.a"
"UART.hex"
"UART.lss"
"UART.eep"
"UART.map"
"UART.srec"
"UART.usersignatures"
\ No newline at end of file
Session2-LF/UART/Debug/UART-LF.d
deleted
100644 → 0
View file @
330aa4c5
UART
-
LF
.
d
UART
-
LF
.
o
:
.././
UART
-
LF
.
c
\
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\a
vr
\
include
\a
vr
\
io
.
h
\
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\a
vr
\
include
\a
vr
\
sfr_defs
.
h
\
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\a
vr
\
include
\
inttypes
.
h
\
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\
lib
\
gcc
\a
vr
\5
.4.0
\
include
\
stdint
.
h
\
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\a
vr
\
include
\
stdint
.
h
\
C
:
\
Program
\
Files
\
(
x86
)
\
Atmel
\
Studio
\7
.0
\
Packs
\a
tmel
\
ATmega_DFP
\1
.2.150
\
include
/
avr
/
iom4809
.
h
\
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\a
vr
\
include
\a
vr
\
portpins
.
h
\
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\a
vr
\
include
\a
vr
\
common
.
h
\
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\a
vr
\
include
\a
vr
\v
ersion
.
h
\
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\a
vr
\
include
\a
vr
\
xmega
.
h
\
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\a
vr
\
include
\a
vr
\f
use
.
h
\
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\a
vr
\
include
\a
vr
\
lock
.
h
\
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\a
vr
\
include
\a
vr
\
interrupt
.
h
\
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\a
vr
\
include
\
util
\
delay
.
h
\
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\a
vr
\
include
\
util
\
delay_basic
.
h
\
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\a
vr
\
include
\
math
.
h
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\a
vr
\
include
\a
vr
\
io
.
h
:
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\a
vr
\
include
\a
vr
\
sfr_defs
.
h
:
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\a
vr
\
include
\
inttypes
.
h
:
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\
lib
\
gcc
\a
vr
\5
.4.0
\
include
\
stdint
.
h
:
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\a
vr
\
include
\
stdint
.
h
:
C
:
\
Program
\
Files
\
(
x86
)
\
Atmel
\
Studio
\7
.0
\
Packs
\a
tmel
\
ATmega_DFP
\1
.2.150
\
include
/
avr
/
iom4809
.
h
:
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\a
vr
\
include
\a
vr
\
portpins
.
h
:
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\a
vr
\
include
\a
vr
\
common
.
h
:
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\a
vr
\
include
\a
vr
\v
ersion
.
h
:
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\a
vr
\
include
\a
vr
\
xmega
.
h
:
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\a
vr
\
include
\a
vr
\f
use
.
h
:
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\a
vr
\
include
\a
vr
\
lock
.
h
:
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\a
vr
\
include
\a
vr
\
interrupt
.
h
:
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\a
vr
\
include
\
util
\
delay
.
h
:
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\a
vr
\
include
\
util
\
delay_basic
.
h
:
c
:
\
program
\
files
\
(
x86
)
\a
tmel
\
studio
\7
.0
\t
oolchain
\a
vr8
\a
vr8
-
gnu
-
toolchain
\a
vr
\
include
\
math
.
h
:
Session2-LF/UART/Debug/UART-LF.o
deleted
100644 → 0
View file @
330aa4c5
File deleted
Session2-LF/UART/Debug/UART.eep
deleted
100644 → 0
View file @
330aa4c5
:00000001FF
Session2-LF/UART/Debug/UART.elf
deleted
100644 → 0
View file @
330aa4c5
File deleted
Session2-LF/UART/Debug/UART.hex
deleted
100644 → 0
View file @
330aa4c5
:100000000C9450000C945A000C945A000C945A0012
:100010000C945A000C945A000C945A000C945A00F8
:100020000C945A000C945A000C945A000C945A00E8
:100030000C945A000C945A000C945A000C945A00D8
:100040000C945A000C945A000C945A000C945A00C8
:100050000C945A000C945A000C945A000C945A00B8
:100060000C945A000C945A000C945A000C945A00A8
:100070000C945A000C945A000C945A000C945A0098
:100080000C945A000C945A000C945A000C945A0088
:100090000C945A000C945A000C949B000C945A0037
:1000A00011241FBECFEFCDBFDFE3DEBF0E9488006B
:1000B0000C94B2000C940000E0E2F4E021E025830F
:1000C0002183E0E6F8E06087BB27A92F982F872FD0
:1000D000818783E0878380EC868385818068858340
:1000E0000895E0E6F8E0948195FFFDCF80936208E3
:1000F0000895CF93DF93EC018881882331F0219616
:100100000E94710089918111FBCFDF91CF910895F9
:100110006CE675E080E090E00E945C00789488E6F0
:1001200091E40E94790025ED88E092E02150804022
:100130009040E1F7F4CF1F920F920FB60F92112467
:100140008F93EF93FF93E0E6F8E084818823ECF748
:1001500080916008FF91EF918F910F900FBE0F90EB
:080160001F901895F894FFCFE1
:10016800446574746520657220656E2074657374C7
:020178000A007B
:00000001FF
Session2-LF/UART/Debug/UART.lss
deleted
100644 → 0
View file @
330aa4c5
UART.elf: file format elf32-avr
Sections:
Idx Name Size VMA LMA File off Algn
0 .data 00000000 00802800 00802800 000001ee 2**0
CONTENTS, ALLOC, LOAD, DATA
1 .text 00000168 00000000 00000000 00000074 2**1
CONTENTS, ALLOC, LOAD, READONLY, CODE
2 .rodata 00000012 00004168 00000168 000001dc 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
3 .comment 00000030 00000000 00000000 000001ee 2**0
CONTENTS, READONLY
4 .note.gnu.avr.deviceinfo 00000040 00000000 00000000 00000220 2**2
CONTENTS, READONLY
5 .debug_aranges 00000040 00000000 00000000 00000260 2**0
CONTENTS, READONLY, DEBUGGING
6 .debug_info 00002823 00000000 00000000 000002a0 2**0
CONTENTS, READONLY, DEBUGGING
7 .debug_abbrev 000022d2 00000000 00000000 00002ac3 2**0
CONTENTS, READONLY, DEBUGGING
8 .debug_line 000003c8 00000000 00000000 00004d95 2**0
CONTENTS, READONLY, DEBUGGING
9 .debug_frame 0000008c 00000000 00000000 00005160 2**2
CONTENTS, READONLY, DEBUGGING
10 .debug_str 00001211 00000000 00000000 000051ec 2**0
CONTENTS, READONLY, DEBUGGING
11 .debug_loc 000000d7 00000000 00000000 000063fd 2**0
CONTENTS, READONLY, DEBUGGING
12 .debug_ranges 00000030 00000000 00000000 000064d4 2**0
CONTENTS, READONLY, DEBUGGING
Disassembly of section .text:
00000000 <__vectors>:
0: 0c 94 50 00 jmp 0xa0 ; 0xa0 <__ctors_end>
4: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
8: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
c: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
10: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
14: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
18: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
1c: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
20: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
24: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
28: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
2c: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
30: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
34: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
38: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
3c: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
40: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
44: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
48: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
4c: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
50: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
54: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
58: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
5c: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
60: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
64: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
68: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
6c: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
70: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
74: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
78: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
7c: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
80: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
84: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
88: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
8c: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
90: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
94: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
98: 0c 94 9b 00 jmp 0x136 ; 0x136 <__vector_38>
9c: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
000000a0 <__ctors_end>:
a0: 11 24 eor r1, r1
a2: 1f be out 0x3f, r1 ; 63
a4: cf ef ldi r28, 0xFF ; 255
a6: cd bf out 0x3d, r28 ; 61
a8: df e3 ldi r29, 0x3F ; 63
aa: de bf out 0x3e, r29 ; 62
ac: 0e 94 88 00 call 0x110 ; 0x110 <main>
b0: 0c 94 b2 00 jmp 0x164 ; 0x164 <_exit>
000000b4 <__bad_interrupt>:
b4: 0c 94 00 00 jmp 0 ; 0x0 <__vectors>
000000b8 <uart_init>:
void uart_init(unsigned long baud){
//From chapter 22.3.1 in datasheet
TX_PORT.OUTSET = (1 << TX_PIN); //Setting up TX pin as output
b8: e0 e2 ldi r30, 0x20 ; 32
ba: f4 e0 ldi r31, 0x04 ; 4
bc: 21 e0 ldi r18, 0x01 ; 1
be: 25 83 std Z+5, r18 ; 0x05
TX_PORT.DIRSET = (1 << TX_PIN); //Setting up TX pin as output
c0: 21 83 std Z+1, r18 ; 0x01
//Set baud rate register
USART3.BAUDL = (uint8_t) baud; //Set baud rate without shifting to get the 8 low bits
c2: e0 e6 ldi r30, 0x60 ; 96
c4: f8 e0 ldi r31, 0x08 ; 8
c6: 60 87 std Z+8, r22 ; 0x08
USART3.BAUDH = (uint8_t)(baud >> 8); //Shift register right by 8 bits to get the 8 high bits
c8: bb 27 eor r27, r27
ca: a9 2f mov r26, r25
cc: 98 2f mov r25, r24
ce: 87 2f mov r24, r23
d0: 81 87 std Z+9, r24 ; 0x09
//USART.CTRLC CMODE bits default to async, 1 stop bit, 8 bit character size
//Since all bits are default 0 we only need to change the character size part
USART3.CTRLC = (0x3 << USART_CHSIZE0_bp);
d2: 83 e0 ldi r24, 0x03 ; 3
d4: 87 83 std Z+7, r24 ; 0x07
//Enable RX and TX
USART3.CTRLB = (1 << USART_RXEN_bp) | (1 << USART_TXEN_bp);
d6: 80 ec ldi r24, 0xC0 ; 192
d8: 86 83 std Z+6, r24 ; 0x06
//Enable interrupts on incoming data
USART3.CTRLA |= (1 << USART_RXCIE_bp);
da: 85 81 ldd r24, Z+5 ; 0x05
dc: 80 68 ori r24, 0x80 ; 128
de: 85 83 std Z+5, r24 ; 0x05
e0: 08 95 ret
000000e2 <uart_transmit>:
//In this function we will be send data.
//First we should check that there isn't already data being sent
// if there is, we should probably wait for it to finish first
while (!(USART3.STATUS & (1 << USART_DREIF_bp))){
e2: e0 e6 ldi r30, 0x60 ; 96
e4: f8 e0 ldi r31, 0x08 ; 8
e6: 94 81 ldd r25, Z+4 ; 0x04
e8: 95 ff sbrs r25, 5
ea: fd cf rjmp .-6 ; 0xe6 <uart_transmit+0x4>
//wait for previous transmit to finish
};
//Put our new data into tx data register
USART3.TXDATAL = data;
ec: 80 93 62 08 sts 0x0862, r24 ; 0x800862 <__TEXT_REGION_LENGTH__+0x700862>
f0: 08 95 ret
000000f2 <uart_transmit_string>:
}
//To send a string we can do this
void uart_transmit_string(char* data) {
f2: cf 93 push r28
f4: df 93 push r29
f6: ec 01 movw r28, r24
while (*data != '\0') {
f8: 88 81 ld r24, Y
fa: 88 23 and r24, r24
fc: 31 f0 breq .+12 ; 0x10a <uart_transmit_string+0x18>
fe: 21 96 adiw r28, 0x01 ; 1
uart_transmit(*data);
100: 0e 94 71 00 call 0xe2 ; 0xe2 <uart_transmit>
}
//To send a string we can do this
void uart_transmit_string(char* data) {
while (*data != '\0') {
104: 89 91 ld r24, Y+
106: 81 11 cpse r24, r1
108: fb cf rjmp .-10 ; 0x100 <uart_transmit_string+0xe>
uart_transmit(*data);
data++;
}
}
10a: df 91 pop r29
10c: cf 91 pop r28
10e: 08 95 ret
00000110 <main>:
int main(void)
{
//Initialize the UART with our function.
//We will be using a baudrate of 9600 (defined as BAUD_9600 at the top of the file)
uart_init(BAUD_9600);
110: 6c e6 ldi r22, 0x6C ; 108
112: 75 e0 ldi r23, 0x05 ; 5
114: 80 e0 ldi r24, 0x00 ; 0
116: 90 e0 ldi r25, 0x00 ; 0
118: 0e 94 5c 00 call 0xb8 ; 0xb8 <uart_init>
sei(); //Enable inerrupt, important for anything here to work
11c: 78 94 sei
while (1)
{
//We don't really need to do anything here.
//the ISR will handle receiving.
uart_transmit_string("Dette er en test\n");
11e: 88 e6 ldi r24, 0x68 ; 104
120: 91 e4 ldi r25, 0x41 ; 65
122: 0e 94 79 00 call 0xf2 ; 0xf2 <uart_transmit_string>
#else
//round up by default
__ticks_dc = (uint32_t)(ceil(fabs(__tmp)));
#endif
__builtin_avr_delay_cycles(__ticks_dc);
126: 25 ed ldi r18, 0xD5 ; 213
128: 88 e0 ldi r24, 0x08 ; 8
12a: 92 e0 ldi r25, 0x02 ; 2
12c: 21 50 subi r18, 0x01 ; 1
12e: 80 40 sbci r24, 0x00 ; 0
130: 90 40 sbci r25, 0x00 ; 0
132: e1 f7 brne .-8 ; 0x12c <main+0x1c>
134: f4 cf rjmp .-24 ; 0x11e <main+0xe>
00000136 <__vector_38>:
}
}
//Interrupt service routine for the receiver.
ISR (USART3_RXC_vect) {
136: 1f 92 push r1
138: 0f 92 push r0
13a: 0f b6 in r0, 0x3f ; 63
13c: 0f 92 push r0
13e: 11 24 eor r1, r1
140: 8f 93 push r24
142: ef 93 push r30
144: ff 93 push r31
//In the interrupt we will read the data in the receive buffer
//First we should check that new data has arrived the receive buffer
while (!(USART3.STATUS & (1 << USART_RXCIF_bp))){
146: e0 e6 ldi r30, 0x60 ; 96
148: f8 e0 ldi r31, 0x08 ; 8
14a: 84 81 ldd r24, Z+4 ; 0x04
14c: 88 23 and r24, r24
14e: ec f7 brge .-6 ; 0x14a <__vector_38+0x14>
//wait for previous transmit to finish
};
//Store the data in a temporarily variable
uint8_t tmp = USART3.RXDATAL;
150: 80 91 60 08 lds r24, 0x0860 ; 0x800860 <__TEXT_REGION_LENGTH__+0x700860>
154: ff 91 pop r31
156: ef 91 pop r30
158: 8f 91 pop r24
15a: 0f 90 pop r0
15c: 0f be out 0x3f, r0 ; 63
15e: 0f 90 pop r0
160: 1f 90 pop r1
162: 18 95 reti
00000164 <_exit>:
164: f8 94 cli
00000166 <__stop_program>:
166: ff cf rjmp .-2 ; 0x166 <__stop_program>
Session2-LF/UART/Debug/UART.map
deleted
100644 → 0
View file @
330aa4c5
Archive member included to satisfy reference by file (symbol)
c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avrxmega3\libgcc.a(_exit.o)
C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.150/gcc/dev/atmega4809/avrxmega3/crtatmega4809.o (exit)