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
424ddd91
Commit
424ddd91
authored
Feb 13, 2017
by
Petter Breedveld
Browse files
All LF done
parent
9e82acec
Changes
36
Hide whitespace changes
Inline
Side-by-side
Session1-LF/Tasks_session1.txt
0 → 100644
View file @
424ddd91
---Session 1---
Task 1:
Learn how to open Atmel Studio.
Read the code, what do you think it does?
Learn how to upload code.
Task 2:
Set up a button with pullup. Use this to control the led.
Task 3:
Add aditional logic so that the button toggles the led.
Task 4: (OPTIONAL)
Add the OLED board.
Find out where the buttons and LEDs connect.
Do something fun with the additional leds and buttons.
\ No newline at end of file
Session2-LF/PWM-LF.c
0 → 100644
View file @
424ddd91
/*
* PWM.c
*
* Created: 29.01.2017 23:43:39
* Author : Petter
*/
#define F_CPU 3333333UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <stdbool.h>
#define LED1 0 // port B, connected to WO0
#define LED2 1 // port B, connected to WO1
#define LED3 4 // Port B
#define SW1 5 // Port A
#define SW2 6 // Port A
#define SW3 7 // Port A
bool
SW1_pressed
,
SW2_pressed
;
//Keeping track of button status
int
main
(
void
)
{
//Set LED pins as output
PORTB_DIR
|=
(
1
<<
LED1
)
|
(
1
<<
LED2
)
|
(
1
<<
LED3
);
//Because the LEDs are active low, we invert the output
PORTB_PIN0CTRL
|=
(
1
<<
PORT_INVEN_bp
);
PORTB_PIN1CTRL
|=
(
1
<<
PORT_INVEN_bp
);
PORTB_PIN4CTRL
|=
(
1
<<
PORT_INVEN_bp
);
//Pullups
PORTA_PIN5CTRL
|=
(
1
<<
PORT_PULLUPEN_bp
);
PORTA_PIN6CTRL
|=
(
1
<<
PORT_PULLUPEN_bp
);
PORTA_PIN7CTRL
|=
(
1
<<
PORT_PULLUPEN_bp
);
//Set clock prescaler div256
TCA0_SINGLE_CTRLA
|=
(
TCA_SINGLE_ENABLE_bm
);
//Enable timer
TCA0_SINGLE_CTRLB
|=
(
0x05
<<
TCA_SINGLE_WGMODE0_bp
);
//Set mode to single slope
TCA0_SINGLE_CTRLB
|=
(
TCA_SINGLE_CMP0EN_bm
)
|
(
TCA_SINGLE_CMP1EN_bm
);
TCA0_SINGLE_PER
=
0x0fff
;
//We set our top to have a sufficiently high frequency (Top at 16 bit (0xffff) ~25Hz, 12 bit (0x0fff) ~400Hz)
TCA0_SINGLE_CMP0
=
0x0000
;
TCA0_SINGLE_CMP1
=
0x0fff
;
while
(
1
){
if
(
!
(
PORTA_IN
&
(
1
<<
SW1
))){
if
(
!
SW1_pressed
){
TCA0_SINGLE_CMP0
=
(((
TCA0_SINGLE_CMP0
<<
1
)
+
1
)
&
(
0x0fff
));
//Shift in a 1, and cut off excess to 12 bit
TCA0_SINGLE_CMP1
>>=
1
;
SW1_pressed
=
true
;
}
}
else
{
SW1_pressed
=
false
;
}
if
(
!
(
PORTA_IN
&
(
1
<<
SW2
))){
if
(
!
SW2_pressed
){
TCA0_SINGLE_CMP1
=
(((
TCA0_SINGLE_CMP1
<<
1
)
+
1
)
&
(
0x0fff
));
//Shift in a 1, and cut off excess to 12 bit
TCA0_SINGLE_CMP0
>>=
1
;
SW2_pressed
=
true
;
}
}
else
{
SW2_pressed
=
false
;
}
}
}
Session2-LF/TIMER-LF.c
View file @
424ddd91
/*
*
Initial_test
.c
*
TIMER
.c
*
* Created: 29.01.2017 23:43:39
* Author : Petter
...
...
@@ -9,7 +9,7 @@
#include <avr/io.h>
#include <
avr
/delay.h>
#include <
util
/delay.h>
#include <avr/interrupt.h>
#define LED1 0 // port B, connected to WO0
...
...
@@ -19,18 +19,27 @@
int
main
(
void
)
{
PORTB_DIR
|=
(
1
<<
LED1
)
|
(
1
<<
LED2
)
|
(
1
<<
LED3
);
PORTB_OUT
|=
(
1
<<
LED1
)
|
(
1
<<
LED2
)
|
(
1
<<
LED3
);
/* In this exercise we will get LEDs to blink at even intervals using interrupts
First set up the LEDs like in the previous exercise. You can either copy paste from the previous exercise or start fresh.
*/
PORTB_DIR
|=
(
1
<<
LED1
)
|
(
1
<<
LED2
);
PORTB_OUT
|=
(
1
<<
LED1
);
//Only to start with LEDs off
//Set clock prescaler div256
//We will be using a timer overflow interupt with timer A
//We set the prescaler to clk=clk/256
TCA0_SINGLE_CTRLA
|=
(
TCA_SINGLE_CLKSEL_DIV256_gc
)
|
(
TCA_SINGLE_ENABLE_bm
);
//Next we Enable timer interupts on overflow
TCA0_SINGLE_INTCTRL
|=
(
TCA_SINGLE_OVF_bm
);
uint16_t
counterTop
=
0x4000
;
TCA0_SINGLE_PER
=
counterTop
;
//Enable global interrupts
sei
();
while
(
1
){
...
...
@@ -39,14 +48,10 @@ int main(void)
}
ISR
(
TCA0_OVF_vect
){
cli
();
PORTB_OUT
^=
(
1
<<
LED1
);
_delay_ms
(
100
);
PORTB_OUT
^=
(
1
<<
LED2
);
_delay_ms
(
100
);
PORTB_OUT
^=
(
1
<<
LED3
);
TCA0_SINGLE_INTFLAGS
|=
(
TCA_SINGLE_OVF_bm
);
sei
();
TCA0_SINGLE_INTFLAGS
|=
(
TCA_SINGLE_OVF_bm
);
//Clear the interupt flag
}
\ No newline at end of file
Session2-LF/Tasks_session2.txt
0 → 100644
View file @
424ddd91
---Session 2---
Task 1: Timer
Get hands on with timers and interupts to toggle a led at exact times.
Task 2: PWM
Continuing with timers, use them for pulse width modulation of LEDs
Task 3: UART
Write a UART driver to communicate with the PC.
Preferably interrupt based.
\ No newline at end of file
Session2-LF/UART-LF.c
View file @
424ddd91
/*
*
Initial_test
.c
*
UART-LF
.c
*
* Created: 29.01.2017 23:43:39
* Author : Petter
...
...
@@ -24,35 +24,36 @@ void uart_init(int baud){
USART0_BAUDL
=
baudRate
;
//Set baud rate
//USART_CTRLC CMODE bits default async, 1 stop bit, 8 bit character size
USART0_CTRLB
|=
(
1
<<
USART_RXEN_bp
)
|
(
1
<<
USART_TXEN_bp
);
//Enable RX and TX
}
// function to recieve data
unsigned
char
uart_recieve
(
void
){
while
(
!
(
USART0_STATUS
&
(
1
<<
USART_RXCIF_bp
)));
return
USART0_RXDATAL
;
USART0_CTRLA
|=
(
1
<<
USART_RXCIE_bp
);
//Enable interrupts on incomming data
}
// function to transmit data
void
uart_transmit
(
unsigned
char
data
){
while
(
!
(
USART0_STATUS
&
(
1
<<
USART_DREIF_bp
)));
USART0_TXDATAH
=
0x00
;
//Is needed!
USART0_TXDATAL
=
data
;
}
int
main
(
void
)
{
unsigned
char
a
;
// to hold the data
uart_init
(
9600
);
//start uart with baudrate of 9600
PORTB_DIR
|=
(
1
<<
PIN4_bp
);
//Setup onboard led for signaling
PORTB_OUT
|=
(
1
<<
PIN4_bp
);
sei
();
//Important for anything here to work
while
(
1
)
{
a
=
uart_recieve
();
// save the recieved data in varible a
PORTB_OUT
&=
~
(
1
<<
PIN4_bp
);
uart_transmit
(
a
);
// transmit the recieved data back
_delay_ms
(
100
);
PORTB_OUT
|=
(
1
<<
PIN4_bp
);
}
}
//Interrupt service routine for the receiver.
ISR
(
USART0_RXC_vect
){
uart_transmit
(
USART0_RXDATAL
);
USART0_STATUS
|=
(
1
<<
USART_RXCIF_bp
);
}
\ No newline at end of file
Session3-LF/Task1/adc.c
0 → 100644
View file @
424ddd91
/*
* adc.c
*
* Created: 13.02.2017 02:04:10
* Author: Petter
*/
#include <avr/io.h>
void
adc_init
(){
ADC0_CTRLA
|=
(
ADC_RESSEL_8BIT_gc
);
//Set resolution, we choose 8 bits
ADC0_CTRLB
|=
(
ADC_SAMPLNUM_ACC4_gc
);
//OPTIONAL: We can use multiple samples if we like, example here with 4
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
}
uint8_t
adc_read
(
uint8_t
channel
){
ADC0_MUXPOS
=
channel
;
//Select input on the ADC mux
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_RESL
;
//Return 8 bit result
}
Session3-LF/Task1/main.c
View file @
424ddd91
/*
*
Initial_test
.c
*
Task1_ADC
.c
*
* Created: 29.01.2017 23:43:39
* Author : Petter
...
...
@@ -9,55 +9,41 @@
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include "display.h"
#include "adc.h"
#include "uart.h"
const
uint8_t
bitmap
[
512
]
PROGMEM
=
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0xFF
,
0x01
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0xE0
,
0xFF
,
0x0F
,
0x00
,
0x00
,
0x00
,
0x00
,
0x70
,
0x38
,
0xDE
,
0x3F
,
0x3E
,
0x18
,
0x00
,
0x00
,
0x00
,
0xF0
,
0xFF
,
0x1F
,
0x00
,
0x00
,
0x00
,
0x00
,
0xD8
,
0x78
,
0xDE
,
0x3B
,
0x33
,
0x1C
,
0x00
,
0x00
,
0x00
,
0xFC
,
0xFF
,
0x7F
,
0x00
,
0x00
,
0x00
,
0x00
,
0x8C
,
0x79
,
0x8E
,
0x21
,
0x23
,
0x1C
,
0x00
,
0x00
,
0x00
,
0xFE
,
0x00
,
0xFE
,
0x00
,
0x00
,
0x00
,
0x00
,
0x8C
,
0x79
,
0x8E
,
0xA9
,
0x23
,
0x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
0xC3
,
0x60
,
0xC2
,
0x1C
,
0x1E
,
0x3F
,
0x7C
,
0xF8
,
0xF1
,
0x00
,
0x00
,
0x0F
,
0x47
,
0x66
,
0x98
,
0x19
,
0xC3
,
0x60
,
0xC8
,
0x1C
,
0xFE
,
0x7F
,
0xFE
,
0xFD
,
0xFF
,
0x00
,
0x00
,
0x0E
,
0x47
,
0x66
,
0x98
,
0x1B
,
0xC2
,
0x60
,
0xC8
,
0x0C
,
0xFE
,
0x7F
,
0xFE
,
0xFD
,
0xFF
,
0x00
,
0x00
,
0x0E
,
0x47
,
0x6E
,
0x99
,
0x1B
,
0xC3
,
0x61
,
0xCC
,
0x0C
,
0xFE
,
0x7F
,
0xFE
,
0xFD
,
0xFF
,
0x00
,
0x00
,
0x8E
,
0x7F
,
0xFF
,
0xBD
,
0xFF
,
0xE3
,
0xF3
,
0xEF
,
0x07
,
0xFE
,
0x7F
,
0xFE
,
0xFD
,
0xFF
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
};
//Remember to remove the UART jumper on the I/O 1 board to prevent loopback
#define LIGHT 6 // Port A - Lysensor er koblet på her
uint8_t
data
,
ones
,
tens
,
hundreds
;
int
main
(
void
)
{
uart_init
(
9600
);
DISP
_init
();
DISP_write_bitmap
(
bitmap
);
while
(
1
)
adc
_init
();
sei
(
);
while
(
1
)
{
data
=
adc_read
(
6
);
data
=
0xff
-
data
;
ones
=
(
data
%
10
);
data
/=
10
;
tens
=
(
data
%
10
);
data
/=
10
;
hundreds
=
(
data
%
10
);
uart_transmit
(
hundreds
+
48
);
uart_transmit
(
tens
+
48
);
uart_transmit
(
ones
+
48
);
uart_transmit
(
0x20
);
//Space
_delay_ms
(
1000
);
}
}
Session3-LF/Task1/uart.c
0 → 100644
View file @
424ddd91
/*
* uart.c
*
* Created: 13.02.2017 04:55:46
* Author: Petter
*/
#define F_CPU 3333333UL
#include <avr/io.h>
#include <avr/interrupt.h>
void
uart_init
(
int
baud
){
int
baudRate
=
((
4UL
*
F_CPU
)
/
baud
);
//CLK_PER = CLK_CPU, see 10.2.1
//From chapter 24.3 in datasheet
PORTB_OUT
|=
(
1
<<
PIN2_bp
);
PORTB_DIR
|=
(
1
<<
PIN2_bp
);
//Setting up TX pin as output
USART0_BAUDH
=
(
baudRate
>>
8
);
//Shift register right by 8 bits
USART0_BAUDL
=
baudRate
;
//Set baud rate
//USART_CTRLC CMODE bits default async, 1 stop bit, 8 bit character size
USART0_CTRLB
|=
(
1
<<
USART_RXEN_bp
)
|
(
1
<<
USART_TXEN_bp
);
//Enable RX and TX
USART0_CTRLA
|=
(
1
<<
USART_RXCIE_bp
);
//Enable interupts on RX
}
// function to transmit data
void
uart_transmit
(
unsigned
char
data
){
while
(
!
(
USART0_STATUS
&
(
1
<<
USART_DREIF_bp
)));
USART0_TXDATAH
=
0x00
;
//Is required!
Snorre Nilssen Vestli
@snorrenv
·
Feb 13, 2017
Maintainer
No, it isn't.
(Med mindre man har skrudd på 9-bit character size)
No, it isn't. (Med mindre man har skrudd på 9-bit character size)
Please
register
or
sign in
to reply
USART0_TXDATAL
=
data
;
}
//Interrupt service routine for the receiver.
ISR
(
USART0_RXC_vect
){
uart_transmit
(
USART0_RXDATAL
);
}
\ No newline at end of file
Session3-LF/Task2/main.c
0 → 100644
View file @
424ddd91
/*
* OLED.c
*
* Created: 29.01.2017 23:43:39
* Author : Petter
*/
#define F_CPU 3333333UL
#include <avr/io.h>
#include <avr/pgmspace.h>
#include "display.h"
const
uint8_t
bitmap
[
512
]
PROGMEM
=
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0xFF
,
0x01
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0xE0
,
0xFF
,
0x0F
,
0x00
,
0x00
,
0x00
,
0x00
,
0x70
,
0x38
,
0xDE
,
0x3F
,
0x3E
,
0x18
,
0x00
,
0x00
,
0x00
,
0xF0
,
0xFF
,
0x1F
,
0x00
,
0x00
,
0x00
,
0x00
,
0xD8
,
0x78
,
0xDE
,
0x3B
,
0x33
,
0x1C
,
0x00
,
0x00
,
0x00
,
0xFC
,
0xFF
,
0x7F
,
0x00
,
0x00
,
0x00
,
0x00
,
0x8C
,
0x79
,
0x8E
,
0x21
,
0x23
,
0x1C
,
0x00
,
0x00
,
0x00
,
0xFE
,
0x00
,
0xFE
,
0x00
,
0x00
,
0x00
,
0x00
,
0x8C
,
0x79
,
0x8E
,
0xA9
,
0x23
,
0x3C
,
0x00
,
0x00
,
0x00
,
0x3F
,
0x00
,
0xF8
,
0x01
,
0x00
,
0x00
,
0x00
,
0x8C
,
0x79
,
0x8F
,
0x89
,
0x03
,
0x3C
,
0x00
,
0x00
,
0x00
,
0x1F
,
0x00
,
0xF0
,
0x01
,
0x00
,
0x00
,
0x00
,
0x8C
,
0x79
,
0x8D
,
0x8F
,
0x03
,
0x36
,
0x00
,
0x00
,
0x80
,
0x0F
,
0x00
,
0xE0
,
0x03
,
0x00
,
0x00
,
0x00
,
0x8C
,
0xF9
,
0x8D
,
0x8B
,
0x7B
,
0x32
,
0x00
,
0x00
,
0xC0
,
0x07
,
0x00
,
0xC0
,
0x07
,
0x00
,
0x00
,
0x00
,
0x8C
,
0xD9
,
0x8D
,
0x89
,
0x33
,
0x3E
,
0x00
,
0x00
,
0xC0
,
0x03
,
0x00
,
0x80
,
0x07
,
0x00
,
0x00
,
0x00
,
0x8C
,
0xD9
,
0x8D
,
0xA1
,
0x33
,
0x72
,
0x00
,
0x00
,
0xE0
,
0x03
,
0x00
,
0x80
,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
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
};
int
main
(
void
)
{
DISP_init
();
DISP_write_bitmap
(
bitmap
);
while
(
1
)
{
}
}
Session3-LF/Task
1
/spi.c
→
Session3-LF/Task
2
/spi.c
View file @
424ddd91
//
// spi.c
//
// Created: 07.04.2016
// Author: Asbjørn Espe
// Edited: 10.02.2017
// Created: 10.02.2017
// Author: Petter
// System headers
...
...
Session3-LF/Task3/display_withTab.c
deleted
100644 → 0
View file @
9e82acec
//
// display.c
//
// Created: 07.04.2016
// Author: Asbjørn Espe
//
#define F_CPU 3333333UL
#define DSP_MODE_BIT 7 //Port B
#define DSP_MODE_DIR PORTB_DIR
#define DSP_MODE_PORT PORTB_OUT
#define DSP_RST_BIT 4 //Port A
#define DSP_RST_DIR PORTA_DIR
#define DSP_RST_PORT PORTA_OUT
// System headers
#include <avr/io.h>
#include <util/delay.h>
#include <stdbool.h>
// Project headers
#include "display.h"
#include "spi.h"
#include "font8x8.h"
// This file contains a simple driver for the display so that one can print characters and strings.
// You shouldn't need to do anything in this file for things to work.
// Of course, you're welcome to check it out if you want to see how things work under the hood.
void
DISP_rst
();
void
DISP_transmit_cmd
(
uint8_t
cmd
);
void
DISP_transmit_data
(
uint8_t
data
);
void
DISP_set_mode
(
bool
mode
);
int
cursor_row
=
0
;
int
cursor_col
=
0
;
void
DISP_print
(
const
char
*
str
)
{
while
(
*
str
!=
'\0'
)
{
DISP_putc
(
*
str
);
str
++
;
}
}
void
DISP_putc
(
char
c
)
{
if
(
c
==
'\n'
)
{
if
(
cursor_col
==
0
)
{
DISP_putc
(
' '
);
}
while
(
cursor_col
!=
0
)
{
DISP_putc
(
' '
);
}
return
;
}
/**
* ---For tab character---
*/
else
if
(
c
==
'\t'
)
{
int
count
=
3
-
(
cursor_col
%
4
);
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
DISP_putc
(
' '
);
}
return
;
}
/**
* ---end tab character---
*/
else
if
(
c
<
0x20
)
{
return
;
}
else
if
(
c
<
0x7F
)
{
uint8_t
d
[
8
]
=
{
pgm_read_byte
(
&
(
font8x8_basic
[(
int
)
c
-
0x20
][
0
])),
pgm_read_byte
(
&
(
font8x8_basic
[(
int
)
c
-
0x20
][
1
])),
pgm_read_byte
(
&
(
font8x8_basic
[(
int
)
c
-
0x20
][
2
])),
pgm_read_byte
(
&
(
font8x8_basic
[(
int
)
c
-
0x20
][
3
])),
pgm_read_byte
(
&
(
font8x8_basic
[(
int
)
c
-
0x20
][
4
])),
pgm_read_byte
(
&
(
font8x8_basic
[(
int
)
c
-
0x20
][
5
])),
pgm_read_byte
(
&
(
font8x8_basic
[(
int
)
c
-
0x20
][
6
])),
pgm_read_byte
(
&
(
font8x8_basic
[(
int
)
c
-
0x20
][
7
]))
};
for
(
uint8_t
b
=
0
;
b
<
8
;
b
++
)
{
uint8_t
db
=
0
;
db
|=
(((
d
[
0
]
>>
b
)
&
0x1
)
<<
0
);
db
|=
(((
d
[
1
]
>>
b
)
&
0x1
)
<<
1
);