Commit 725477f0 authored by medlem's avatar medlem

Changed order of day 3 task 1 and 2. Fixed task 1 (spi)

parent 09f5388c

Microsoft Visual Studio Solution File, Format Version 12.00
# Atmel Studio Solution File, Format Version 11.00
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "Task2_LF", "Task2_LF\Task2_LF.cproj", "{DCE6C7E3-EE26-4D79-826B-08594B9AD897}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|AVR = Debug|AVR
Release|AVR = Release|AVR
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.ActiveCfg = Debug|AVR
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.Build.0 = Debug|AVR
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.ActiveCfg = Release|AVR
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.Build.0 = Release|AVR
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
<?xml version="1.0" encoding="utf-8"?>
<Store xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="AtmelPackComponentManagement">
<ProjectComponents>
<ProjectComponent z:Id="i1" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/">
<CApiVersion></CApiVersion>
<CBundle></CBundle>
<CClass>Device</CClass>
<CGroup>Startup</CGroup>
<CSub></CSub>
<CVariant></CVariant>
<CVendor>Atmel</CVendor>
<CVersion>1.2.0</CVersion>
<DefaultRepoPath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs</DefaultRepoPath>
<DependentComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
<Description></Description>
<Files xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include</AbsolutePath>
<Attribute></Attribute>
<Category>include</Category>
<Condition>C</Condition>
<FileContentHash i:nil="true" />
<FileVersion></FileVersion>
<Name>include</Name>
<SelectString></SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include\avr\iom4809.h</AbsolutePath>
<Attribute></Attribute>
<Category>header</Category>
<Condition>C</Condition>
<FileContentHash>mWiFIOAGwUPlW0rYsXcjkg==</FileContentHash>
<FileVersion></FileVersion>
<Name>include/avr/iom4809.h</Name>
<SelectString></SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\templates\main.c</AbsolutePath>
<Attribute>template</Attribute>
<Category>source</Category>
<Condition>C Exe</Condition>
<FileContentHash>GD1k8YYhulqRs6FD1B2Hog==</FileContentHash>
<FileVersion></FileVersion>
<Name>templates/main.c</Name>
<SelectString>Main file (.c)</SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\templates\main.cpp</AbsolutePath>
<Attribute>template</Attribute>
<Category>source</Category>
<Condition>C Exe</Condition>
<FileContentHash>YXFphlh0CtZJU+ebktABgQ==</FileContentHash>
<FileVersion></FileVersion>
<Name>templates/main.cpp</Name>
<SelectString>Main file (.cpp)</SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega4809</AbsolutePath>
<Attribute></Attribute>
<Category>libraryPrefix</Category>
<Condition>GCC</Condition>
<FileContentHash i:nil="true" />
<FileVersion></FileVersion>
<Name>gcc/dev/atmega4809</Name>
<SelectString></SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
</Files>
<PackName>ATmega_DFP</PackName>
<PackPath>C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.209/Atmel.ATmega_DFP.pdsc</PackPath>
<PackVersion>1.2.209</PackVersion>
<PresentInProject>true</PresentInProject>
<ReferenceConditionId>ATmega4809</ReferenceConditionId>
<RteComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d4p1:string></d4p1:string>
</RteComponents>
<Status>Resolved</Status>
<VersionMode>Fixed</VersionMode>
<IsComponentInAtProject>true</IsComponentInAtProject>
</ProjectComponent>
</ProjectComponents>
</Store>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
<ProjectVersion>7.0</ProjectVersion>
<ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
<ProjectGuid>dce6c7e3-ee26-4d79-826b-08594b9ad897</ProjectGuid>
<avrdevice>ATmega4809</avrdevice>
<avrdeviceseries>none</avrdeviceseries>
<OutputType>Executable</OutputType>
<Language>C</Language>
<OutputFileName>$(MSBuildProjectName)</OutputFileName>
<OutputFileExtension>.elf</OutputFileExtension>
<OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
<AssemblyName>Task2_LF</AssemblyName>
<Name>Task2_LF</Name>
<RootNamespace>Task2_LF</RootNamespace>
<ToolchainFlavour>Native</ToolchainFlavour>
<KeepTimersRunning>true</KeepTimersRunning>
<OverrideVtor>false</OverrideVtor>
<CacheFlash>true</CacheFlash>
<ProgFlashFromRam>true</ProgFlashFromRam>
<RamSnippetAddress>0x20000000</RamSnippetAddress>
<UncachedRange />
<preserveEEPROM>true</preserveEEPROM>
<OverrideVtorValue>exception_table</OverrideVtorValue>
<BootSegment>2</BootSegment>
<eraseonlaunchrule>0</eraseonlaunchrule>
<AsfFrameworkConfig>
<framework-data>
<options />
<configurations />
<files />
<documentation help="" />
<offline-documentation help="" />
<dependencies>
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.37" />
</dependencies>
</framework-data>
</AsfFrameworkConfig>
<ResetRule>0</ResetRule>
<EraseKey />
<avrtool>com.atmel.avrdbg.tool.nedbg</avrtool>
<avrtoolserialnumber>ATML3094051800000371</avrtoolserialnumber>
<avrdeviceexpectedsignature>0x1E9651</avrdeviceexpectedsignature>
<avrtoolinterface>UPDI</avrtoolinterface>
<com_atmel_avrdbg_tool_nedbg>
<ToolOptions>
<InterfaceProperties>
<UpdiClock>750000</UpdiClock>
</InterfaceProperties>
<InterfaceName>UPDI</InterfaceName>
</ToolOptions>
<ToolType>com.atmel.avrdbg.tool.nedbg</ToolType>
<ToolNumber>ATML3094051800000371</ToolNumber>
<ToolName>nEDBG</ToolName>
</com_atmel_avrdbg_tool_nedbg>
<avrtoolinterfaceclock>750000</avrtoolinterfaceclock>
<com_atmel_avrdbg_tool_simulator>
<ToolOptions xmlns="">
<InterfaceProperties>
</InterfaceProperties>
<InterfaceName>
</InterfaceName>
</ToolOptions>
<ToolType xmlns="">com.atmel.avrdbg.tool.simulator</ToolType>
<ToolNumber xmlns="">
</ToolNumber>
<ToolName xmlns="">Simulator</ToolName>
</com_atmel_avrdbg_tool_simulator>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<ToolchainSettings>
<AvrGcc>
<avrgcc.common.Device>-mmcu=atmega4809 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega4809"</avrgcc.common.Device>
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
<avrgcc.compiler.symbols.DefSymbols>
<ListValues>
<Value>NDEBUG</Value>
</ListValues>
</avrgcc.compiler.symbols.DefSymbols>
<avrgcc.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value>
</ListValues>
</avrgcc.compiler.directories.IncludePaths>
<avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
<avrgcc.linker.libraries.Libraries>
<ListValues>
<Value>libm</Value>
</ListValues>
</avrgcc.linker.libraries.Libraries>
<avrgcc.assembler.general.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value>
</ListValues>
</avrgcc.assembler.general.IncludePaths>
</AvrGcc>
</ToolchainSettings>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<ToolchainSettings>
<AvrGcc>
<avrgcc.common.Device>-mmcu=atmega4809 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega4809"</avrgcc.common.Device>
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
<avrgcc.compiler.symbols.DefSymbols>
<ListValues>
<Value>DEBUG</Value>
</ListValues>
</avrgcc.compiler.symbols.DefSymbols>
<avrgcc.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value>
</ListValues>
</avrgcc.compiler.directories.IncludePaths>
<avrgcc.compiler.optimization.level>Optimize most (-O3)</avrgcc.compiler.optimization.level>
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
<avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
<avrgcc.linker.libraries.Libraries>
<ListValues>
<Value>libm</Value>
</ListValues>
</avrgcc.linker.libraries.Libraries>
<avrgcc.assembler.general.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value>
</ListValues>
</avrgcc.assembler.general.IncludePaths>
<avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
</AvrGcc>
</ToolchainSettings>
</PropertyGroup>
<ItemGroup>
<Compile Include="oled.c">
<SubType>compile</SubType>
</Compile>
<Compile Include="oled.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="fonts.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="main.c">
<SubType>compile</SubType>
</Compile>
<Compile Include="graphics.c">
<SubType>compile</SubType>
</Compile>
<Compile Include="graphics.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="spi.c">
<SubType>compile</SubType>
</Compile>
<Compile Include="spi.h">
<SubType>compile</SubType>
</Compile>
</ItemGroup>
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
</Project>
\ No newline at end of file
This diff is collapsed.
#include "oled.h"
#include "graphics.h"
/* Draw the outline of the loading bar */
void graphics_loading_bar_init()
{
oled_pos(1,12);
oled_write_d(0xf8);
oled_pos(2,12);
oled_write_d(0x1f);
oled_pos(1,115);
oled_write_d(0xf8);
oled_pos(2,115);
oled_write_d(0x1f);
for(uint8_t i=0;i<101;i++)
{
oled_pos(1,13+i);
oled_write_d(0x08);
oled_pos(2,13+i);
oled_write_d(0x10);
}
}
/* Set length of loading bar. Between 0 and 1023 */
void graphics_loading_bar_set(uint16_t data)
{
if(data>1023){ //Highest data value
data=1023;
}
data=data/10; //convert data to percentages
for(int i=0; i<data;i++){
oled_pos(1,13+i);
oled_write_d(0xf8);
oled_pos(2,13+i);
oled_write_d(0x1f);
}
for(int i=data; i<102;i++){
oled_pos(1,13+i);
oled_write_d(0x08);
oled_pos(2,13+i);
oled_write_d(0x10);
}
}
/* Print bitmap to screen */
void graphics_print_bitmap(const uint8_t* bm)
{
for(uint8_t y = 0; y < 4; y++)
{
for(uint8_t x = 0; x < 16; x++)
{
uint8_t d[8] = {
pgm_read_byte(&(bm[(8 * y + 0) * 16 + x])),
pgm_read_byte(&(bm[(8 * y + 1) * 16 + x])),
pgm_read_byte(&(bm[(8 * y + 2) * 16 + x])),
pgm_read_byte(&(bm[(8 * y + 3) * 16 + x])),
pgm_read_byte(&(bm[(8 * y + 4) * 16 + x])),
pgm_read_byte(&(bm[(8 * y + 5) * 16 + x])),
pgm_read_byte(&(bm[(8 * y + 6) * 16 + x])),
pgm_read_byte(&(bm[(8 * y + 7) * 16 + x]))
};
for(uint8_t b = 0; b < 8; b++)
{
uint8_t db = 0;
db |= (((d[0] >> b) & 0x1) << 0);
db |= (((d[1] >> b) & 0x1) << 1);
db |= (((d[2] >> b) & 0x1) << 2);
db |= (((d[3] >> b) & 0x1) << 3);
db |= (((d[4] >> b) & 0x1) << 4);
db |= (((d[5] >> b) & 0x1) << 5);
db |= (((d[6] >> b) & 0x1) << 6);
db |= (((d[7] >> b) & 0x1) << 7);
oled_write_d(db);
}
}
}
}
\ No newline at end of file
#ifndef OLED_GRAPHIC_H_
#define OLED_GRAPHIC_H_
#include <avr/io.h>
#include <avr/pgmspace.h>
// This file contains a simple driver for the display so that one can print characters and strings,
// bitmaps and a simple figure.
// The graphics functions use oled.h to write to the screen. Remember to initialize the oled!
// You shouldn't need to edit/write 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.
/* Draw the outline of the loading bar */
void graphics_loading_bar_init();
/* Set length of loading bar. Between 0 and 1023 */
void graphics_loading_bar_set(uint16_t data);
/* Print a bitmap to the screen. See Graphics section under to find example bitmap. */
void graphics_print_bitmap(const uint8_t* bm);
//Graphics. Probably generated on the Internet.
static const uint8_t PROGMEM OV[512] =
{
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, 0x0F, 0x00, 0x00, 0x00, 0x8C, 0xD9, 0x8D, 0xA1, 0x33, 0x72, 0x00, 0x00,
0xE0, 0xFF, 0xC7, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0xD8, 0xD9, 0x8D, 0x31, 0x33, 0x63, 0x00, 0x00,
0xE0, 0xFF, 0xC7, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0xF8, 0xFC, 0xDE, 0x3F, 0x3F, 0xF7, 0x00, 0x00,
0xE0, 0xFF, 0xC7, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xE0, 0xFF, 0xC7, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xE0, 0xE1, 0x00, 0x0E, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xE0, 0xE1, 0x00, 0x0E, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xE0, 0xC1, 0x01, 0x07, 0x0F, 0x00, 0xC0, 0xF3, 0x7F, 0x3F, 0xBC, 0xE3, 0xFB, 0xF7, 0xEF, 0x07,
0xE0, 0xC1, 0x01, 0x07, 0x0F, 0x00, 0x80, 0x33, 0x67, 0x6E, 0x38, 0x33, 0xDB, 0xE7, 0xEC, 0x0F,
0xE0, 0x81, 0x83, 0x03, 0x0F, 0x00, 0x80, 0x33, 0x47, 0xC6, 0x18, 0x19, 0xCA, 0x64, 0xC8, 0x0C,
0xE0, 0x83, 0x83, 0x83, 0x0F, 0x00, 0x80, 0x13, 0x57, 0xC6, 0x98, 0x38, 0xCA, 0x64, 0xCA, 0x1C,
0xC0, 0x03, 0xC7, 0x81, 0x07, 0x00, 0x00, 0x13, 0x17, 0xC6, 0xD8, 0x70, 0xC0, 0x60, 0xC2, 0x1C,
0xC0, 0x07, 0xC7, 0xC1, 0x07, 0x00, 0x00, 0x13, 0x1F, 0x7E, 0xF8, 0xE0, 0xC1, 0xE0, 0xC3, 0x1C,
0x80, 0x0F, 0xEE, 0xE0, 0x03, 0x00, 0x00, 0x13, 0x17, 0x7E, 0xF8, 0xC0, 0xC3, 0xE0, 0xC2, 0x1C,
0x02, 0x1F, 0xFE, 0xF0, 0x83, 0x00, 0x00, 0x1F, 0x17, 0x66, 0xD8, 0x81, 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
};
#endif /* OLED_GRAPHIC_H_ */
\ No newline at end of file
#define F_CPU 3333333UL
#include <avr/io.h>
#include "oled.h"
#include "spi.h"
/*
In this exercise you will write a driver for the SPI module. You will connect the OLED1 Xplained Pro screen to the Xplained Pro Extension header.
and use your SPI driver to write bitmaps and text to the screen.
A finished driver for the screen is provided (graphics.c), as as a font for it. These build on the SPI driver.
You can read graphics.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 ATmega4809 datasheet
b) find out what pins of the ATmega4809 the screen is connected to
*/
int main(void)
{
//Here fprintf is used in stead of printf. If you want to know the difference, ask an assistant or use the internet.
//Look into the oled.h to see how we connect it to fprintf.
fprintf(FONT5,"Hello Screen \n");
//Code here
while (1)
{
//Code also here?
}
}
#define F_CPU 3333333ul
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include <stdbool.h>
#include "oled.h"
#include "fonts.h"
//#include "display.h"
static uint8_t oled_current_line_num;
#define OLED_MODE_bm (1 << 3)
#define OLED_MODE_PORT PORTC
#define OLED_RESET_bm (1 << 7)
#define OLED_RESET_PORT PORTC
#define DATA_MODE 1
#define COMMAND_MODE 0
//------------------------------------------------------------
uint8_t oled_get_current_line(){
return oled_current_line_num;
}
void oled_init() // Documentation on oled screen on: https://cdn-shop.adafruit.com/datasheets/SSD1306.pdf
{
OLED_RESET_PORT.DIRSET = OLED_RESET_bm;
OLED_MODE_PORT.DIRSET = OLED_MODE_bm;
oled_set_mode(1);
oled_reset();
oled_write_c(0xAE); // display off
// p32
oled_write_c(0xD5); // clock
oled_write_c(0xF0); // upper nibble is rate, lower nibble is divisor
// p31
oled_write_c(0xA8); // mux ratio p31
oled_write_c(0x20); // rtfm
// p31
oled_write_c(0xD3); // display offset
oled_write_c(0x00); // rtfm
// p3 (appendix)
oled_write_c(0x8D); // charge pump
oled_write_c(0x14); // enable
// p30, p34
oled_write_c(0x20); // memory addr mode
oled_write_c(0x00); // horizontal
// p31
oled_write_c(0xA1); // segment remap
oled_write_c(0xA5); // display on
// p31
oled_write_c(0xC8); // com scan direction
// p31
oled_write_c(0x7F); // display start line
// p31
oled_write_c(0x22); // set page address
oled_write_c(0x00);
oled_write_c(0x03);
// p31, p40
oled_write_c(0xDA); // com hardware cfg
oled_write_c(0x02); // com cfg
// p28
oled_write_c(0x81); // contrast aka current
oled_write_c(0xFF); // 128 is midpoint
// p32
oled_write_c(0xD9); // precharge
oled_write_c(0x11); // rtfm
// p32
oled_write_c(0xDB); // vcomh deselect level
oled_write_c(0x20); // rtfm
oled_write_c(0xA6); // non-inverted
oled_write_c(0xA4); // display scan on
oled_write_c(0xAF); // drivers on
oled_clear_screen();
}
/* Hardware reset the screen */
void oled_reset()
{
OLED_RESET_PORT.OUTCLR = OLED_RESET_bm;
_delay_ms(10);
OLED_RESET_PORT.OUTSET = OLED_RESET_bm;
_delay_ms(10);
}
/* Set data/command mode */
void oled_set_mode(uint8_t mode)
{
if (mode == DATA_MODE)
{
OLED_MODE_PORT.OUTSET=OLED_MODE_bm;
}
if (mode == COMMAND_MODE)
{
OLED_MODE_PORT.OUTCLR=OLED_MODE_bm;
}
}
/* Write command */
void oled_write_c(uint8_t command){
oled_set_mode(0);
spi_transmit(command);
}
/* Write data*/
void oled_write_d(uint8_t data){
oled_set_mode(1);
spi_transmit(data);
}
/* Clear the screen */
void oled_clear_screen(){
for(int line=0;line<4;line++){
oled_clear_line(line);
}
}
/* Clear one line */
void oled_clear_line(uint8_t line){
oled_write_c(0xb0 + line); // selects row/page
for(int byte=0;byte<128;byte++){
// Clear current column
oled_set_mode(1);
spi_transmit(0x00);
}
}
/* Go to given row*/
void oled_goto_line(uint8_t line){
oled_write_c(0xb0 + line);
oled_current_line_num = line;
}
/* Go to given row and column*/
void oled_pos(uint8_t row, uint8_t col){
oled_write_c(0xb0 + row); // Go to row/page
oled_current_line_num = row;
oled_write_c(0x00 + (col & 0x0F)); // Low column start address
oled_write_c(0x10 + ((col >> 4) & 0x0F)); // High column start address
}
/* Write a character to the screen with font 4 to current position*/
int oled_putchar4(char character, FILE *stream){ // Use ASCII code minus 32, Font4
if(character == '\n'){
oled_pos(oled_current_line_num +1, 8); // Next line with column margin of 8
return 0;
}
for(uint8_t i = 0; i < 4; ++i){
oled_write_d(pgm_read_word(&font4[character - 32][i]));
}
oled_write_d(0x00);
return 0;
}
/* Write a character to the screen with font 5 to current position */
int oled_putchar5(char character, FILE *stream){ // Use ASCII code minus 32, Font5
if(character == '\n'){
oled_pos(oled_current_line_num +1, 8);
return 0;
}
for(uint8_t i = 0; i < 5; ++i){
oled_write_d(pgm_read_word(&font5[character - 32][i]));
}
oled_write_d(0x00);
return 0;
}
/* Write a character to the screen with font 8 to current position */
int oled_putchar8(char character, FILE *stream){ // Use ASCII code minus 32, Font8
if(character == '\n'){
oled_pos(oled_current_line_num +1, 8);
return 0;
}
for(uint8_t i = 0; i < 4; ++i){
oled_write_d(pgm_read_word(&font8[character - 32][i]));
}
return 0;
}
/* Set brightness, 0-255 */
void oled_set_brightness(uint8_t lvl){
oled_write_c(0x81); // Set brightness command
oled_write_c(lvl); // Set brightness level
}
/*
* driv_OLED.h
*
* Created: 17.09.2015 12:23:50
* Author: helgeanl
*/
#ifndef DRIV_OLED_H_
#define DRIV_OLED_H_
#include <stdio.h>