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
4581531c
Commit
4581531c
authored
Mar 15, 2017
by
Petter Breedveld
Browse files
flyttet OLED til EXT3
parent
54e2f77a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Debugger_Demo/Debugger_Demo/main.c
View file @
4581531c
...
...
@@ -4,13 +4,14 @@
*/
#define F_CPU 3333333UL
#define BAUD_9600 ((4UL*F_CPU)/9600)
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdio.h>
#define F_CPU 3333333UL
#define BAUD_9600 ((4UL*F_CPU)/9600)
#include <util/delay.h>
int
uart_transmit
(
char
data
,
FILE
*
stream
){
...
...
@@ -48,12 +49,13 @@ ISR(USART0_RXC_vect){
int
main
(
void
)
{
uart_init
(
BAUD_
9600
);
uart_init
(
9600
);
while
(
1
)
{
uart_transmit
(
'O'
,
NULL
);
_delay_ms
(
1000
);
}
}
Session3-LF/Task2_LF/Task2_LF/display.c
View file @
4581531c
...
...
@@ -5,11 +5,11 @@
#define F_CPU 3333333UL
#define DSP_MODE_bm 1<<
7
#define DSP_MODE_PORT PORT
B
#define DSP_MODE_bm 1<<
5
#define DSP_MODE_PORT PORT
C
#define DSP_RST_bm 1<<
4
#define DSP_RST_PORT PORT
A
#define DSP_RST_bm 1<<
5
#define DSP_RST_PORT PORT
B
// System headers
...
...
Session3-LF/Task2_LF/Task2_LF/main.c
View file @
4581531c
...
...
@@ -11,6 +11,19 @@
#include "display.h"
/*
In this exercise you will write a driver for the SPI module. You will connect the OLED screen to the EXT3 header
and use your SPI driver to write bitmaps and text to the screen.
A finished driver for the screen is provided (display.c), as as a font for it. These build uppon the SPI driver.
You can read display.h to see what functions you can use with the screen.
No help beyond the function headers is provided. To start, it's recommend you:
a) glance over the chapter on SPI in the ATtiny817 datasheet
b) find out what pins of the ATtiny the screen is connected to
*/
const
uint8_t
bitmap
[
512
]
PROGMEM
=
{
...
...
Session3-LF/Task2_LF/Task2_LF/spi.c
View file @
4581531c
...
...
@@ -9,18 +9,14 @@
// Project headers
#include "spi.h"
// In this file, you will need to write the contents of the SPI communication routines.
// You need to setup SPI communication in SPI_MasterInit() and
// transmit data in SPI_MasterTransmit(...).
//
// HINT: Check out the , and as always:
// RTFD
//Oled is connected to alternate SPI pins
#define MOSI_bm 1<<2 //on port C
#define SCK_bm 1<<0 //on port C
#define SS_bm 1<<3 //on port
C
#define SS_bm 1<<3 //on port
A
#define SPI_PORT PORTC //We can now use SPI_PORT.DIR, .OUT etc.
#define SS_PORT PORTA //SS is on a different port
//We could also have defined bit positions for MOSI, SCL and SS.
...
...
@@ -31,11 +27,14 @@ void SPI_MasterInit()
// Initialize the SPI port as master
// You will need to set MOSI, SCK, SS (slave select) as outputs
//Connect OLED to EXT3
PORTMUX
.
CTRLB
|=
PORTMUX_SPI0_bm
;
//To use alternative SPI pins
SPI_PORT
.
DIR
|=
MOSI_bm
|
SCK_bm
|
SS_bm
;
//Set pins as output
SPI_PORT
.
DIR
|=
MOSI_bm
|
SCK_bm
;
//Set pins as output
SS_PORT
.
DIR
|=
SS_bm
;
S
PI
_PORT
.
OUTSET
=
SS_bm
;
//Set SS high -> OLED inactive
S
S
_PORT
.
OUTSET
=
SS_bm
;
//Set SS high -> OLED inactive
// Now enable SPI, Master and set clock rate
...
...
@@ -52,7 +51,7 @@ void SPI_MasterInit()
void
SPI_MasterTransmit
(
char
cData
)
{
// First select the correct slave by setting its slave select (SS) LOW
S
PI
_PORT
.
OUTCLR
=
SS_bm
;
S
S
_PORT
.
OUTCLR
=
SS_bm
;
// Then start the transmission by assigning the data to the SPI data register
SPI0
.
DATA
=
cData
;
...
...
@@ -65,5 +64,5 @@ void SPI_MasterTransmit(char cData)
SPI0
.
DATA
;
//Dummy read to clear flag
// Finally set the slave select bit HIGH before leaving the function
S
PI
_PORT
.
OUTSET
=
SS_bm
;
S
S
_PORT
.
OUTSET
=
SS_bm
;
}
Session3/Task2/main.c
View file @
4581531c
...
...
@@ -12,7 +12,7 @@
#include "display.h"
/*
In this exercise you will write a driver for the SPI module. You will connect the OLED screen to the EXT
1
header
In this exercise you will write a driver for the SPI module. You will connect the OLED screen to the EXT
3
header
and use your SPI driver to write bitmaps and text to the screen.
A finished driver for the screen is provided (display.c), as as a font for it. These build uppon the SPI driver.
You can read display.h to see what functions you can use with the screen.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment