Commit 0f7bafcd authored by johanvaa's avatar johanvaa

Merge branch 'MCHP_review' into 'master'

Mchp review

See merge request !1
parents ac61bd30 e620a045
......@@ -15,21 +15,25 @@
#include <util/delay.h>
/*
* Check out the ATtiny4809 datasheet to find the correct ports and pins
*/
* Take a look at the Atmega4809 Curiosity Nano board and locate "SW0" and "LED0".
* Right below each of them you can see which pin they are connected to. For example, if it said PD5, this would mean Port D and Pin 5.
* This info can also be found in the ATmega4809 Curiosity Nano Hardware User Guide here: http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega4809-Curiosity-Nano-HW-UG-DS50002804A.pdf to find the correct ports and pins
*/
//Fill in the defines with the information you found on the board/in the user guide.
// LED
#define LED0 4 //On port D
#define LED0 5 //Fill in pin number
// Button
#define SW0 2 //On port C
#define SW0 6 //Fill in pin number
int main(void)
{
/*
* We want to send signals to the LEDs, in order to turn it off and on.
* We also want to be able to read the switches.
* This is done by setting bits in the PORTx.DIR register (in this case PORTD.DIR and PORTC.DIR)
* This is done by setting bits in the PORTx.DIR register (in this case PORTF.DIR)
* PORTx.DIR: 1 is output, 0 is input
* LED: 1 LED is off, 0 LED is on
* Button: 1 Button is open, 0 button is pressed
......@@ -41,7 +45,7 @@ int main(void)
/**
* In order to read from the switches, we need to give it a ground reference, via a pull-up resistor.
* If we don't, the switch will have a floating ground, and hence its value will be undefined.
* On the ATtiny4809, we enable pull-up by setting the "PORT_PULLUPEN" flag in "PORTx.PINnCTRL" high.
* On the ATmega4809, we enable pull-up by setting the "PORT_PULLUPEN" flag in "PORTx.PINnCTRL" high.
* See datasheet section 15 (I/O-ports).
*/
......@@ -49,14 +53,11 @@ int main(void)
* It's your time to do some stuff! Do the following:
* 1 - Set LED0 as output
* 2 - Set SW0 as input
* 3 - Enable pull-up on button SW0
* 3 - Enable pull-up on button SW0 (Not necessary here as we have an external pull-up, but in case you dont have one in the future, dont forget!).
*/
PORTD.DIR |= (1 << LED0); // Set LED0 as output
PORTC.DIR &= ~(1 << SW0); //Set SW0 as input
PORTB.PIN2CTRL |= (1 << PORT_PULLUPEN_bp); //Enable pull-up on button SW0 (pin5)
PORTF.DIRSET = (1 << LED0);
PORTF.DIRCLR = (1 << SW0);
//PORTF.PIN6CTRL |= (1<<PORT_PULLUPEN_bp); //Not necessary as the button already had an external pullup.
while (1)
{
/*
......@@ -76,13 +77,13 @@ int main(void)
* 2 - if so, turn the LED on
* 3 - if not, turn the LED off
*/
if(!(PORTC.IN & (1 << SW0))){ // If button is pressed (0 - LOW
PORTD.OUT &= ~(1 << LED0); // Sets output to 0, turns LED0 on
if(!(PORTF.IN & (1<<SW0)))//Check if SW0 is pressed
{
PORTF.OUTCLR = (1<<LED0);//Set LED0 high
}
else{
PORTD.OUT |= (1 << LED0); // Sets output to 1, turns LED off
else
{
PORTF.OUTSET = (1<<LED0);//Set LED0 low
}
}
......
......@@ -22,4 +22,4 @@ 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
Do something fun with the additional leds and buttons.
---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.
......@@ -15,7 +15,7 @@
<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>
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.2.272\include</AbsolutePath>
<Attribute></Attribute>
<Category>include</Category>
<Condition>C</Condition>
......@@ -26,18 +26,18 @@
<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>
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.2.272\include\avr\iom4809.h</AbsolutePath>
<Attribute></Attribute>
<Category>header</Category>
<Condition>C</Condition>
<FileContentHash>mWiFIOAGwUPlW0rYsXcjkg==</FileContentHash>
<FileContentHash>fQaG1DJ4X5qUUwRvErAbNQ==</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>
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.2.272\templates\main.c</AbsolutePath>
<Attribute>template</Attribute>
<Category>source</Category>
<Condition>C Exe</Condition>
......@@ -48,7 +48,7 @@
<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>
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.2.272\templates\main.cpp</AbsolutePath>
<Attribute>template</Attribute>
<Category>source</Category>
<Condition>C Exe</Condition>
......@@ -59,7 +59,7 @@
<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>
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.2.272\gcc\dev\atmega4809</AbsolutePath>
<Attribute></Attribute>
<Category>libraryPrefix</Category>
<Condition>GCC</Condition>
......@@ -71,8 +71,8 @@
</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>
<PackPath>C:/Program Files (x86)/Atmel/Studio/7.0/Packs/Atmel/ATmega_DFP/1.2.272/Atmel.ATmega_DFP.pdsc</PackPath>
<PackVersion>1.2.272</PackVersion>
<PresentInProject>true</PresentInProject>
<ReferenceConditionId>ATmega4809</ReferenceConditionId>
<RteComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
......
......@@ -28,15 +28,15 @@
<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.34.1" />
</dependencies>
</framework-data>
<options />
<configurations />
<files />
<documentation help="" />
<offline-documentation help="" />
<dependencies>
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.34.1" />
</dependencies>
</framework-data>
</AsfFrameworkConfig>
<ResetRule>0</ResetRule>
<EraseKey />
......@@ -84,7 +84,7 @@
<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.Device>-mmcu=atmega4809 -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.2.272\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>
......@@ -99,7 +99,7 @@
</avrgcc.compiler.symbols.DefSymbols>
<avrgcc.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value>
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.2.272\include</Value>
</ListValues>
</avrgcc.compiler.directories.IncludePaths>
<avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
......@@ -113,7 +113,7 @@
</avrgcc.linker.libraries.Libraries>
<avrgcc.assembler.general.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value>
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.2.272\include</Value>
</ListValues>
</avrgcc.assembler.general.IncludePaths>
</AvrGcc>
......@@ -122,7 +122,7 @@
<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.Device>-mmcu=atmega4809 -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.2.272\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>
......@@ -137,7 +137,7 @@
</avrgcc.compiler.symbols.DefSymbols>
<avrgcc.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value>
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.2.272\include</Value>
</ListValues>
</avrgcc.compiler.directories.IncludePaths>
<avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
......@@ -152,7 +152,7 @@
</avrgcc.linker.libraries.Libraries>
<avrgcc.assembler.general.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value>
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.2.272\include</Value>
</ListValues>
</avrgcc.assembler.general.IncludePaths>
<avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
......
......@@ -2,7 +2,7 @@
* Task1.c
*
* Created: 11.02.2017 23:37:53
* Author : Petter
* Author : Petter Breedveld
*/
......@@ -25,7 +25,7 @@
/**
* Define helpers for pin bit positions.
* The LED0 on the ATtiny4809 main board is connected to pin 4 on port D.
* The LED0 on the ATmega4809 main board is connected to pin 4 on port D.
* Check the datasheet to find out which pins on which ports the different LEDs and buttons are connected to.
*/
......@@ -39,17 +39,17 @@ int main(void){
/**
* We want to send signals to the LEDs, in order to turn the off and on.
* In the AVR world we have the following:
* PORTx.DIR: 1 is output, 0 is input
* LED: 1 LED is off, 0 LED is on, this is called active-low
* Button: 1 button is open, 0 button is pressed, this is called active-low
* PORTx.DIR: 1 is output, 0 is input.
* LED: 1 LED is off, 0 LED is on, this is called active-low.
* Button: 1 button is open, 0 button is pressed, this is called active-low.
*
* Remember bit set logic:
* Set to 1: FLAG |= ( 1 << BIT_POS ) - using 'or' so we only change the one we want and leave the others untouched
* Set to 0: FLAG &= ~( 1 << BIT_POS ) - same thing here but using 'and', find paper and a logic-table, and try it out if you want to know how it works
* Toogle bit: FLAG ^= ( 1 << BIT_POS ) - using bitwise xor, toogles the bit at BIT_POS
* Set to 1: Register |= ( 1 << BIT_POS ) - using the 'or'('|') operator so we only change the one we want and leave the others untouched.
* Set to 0: Register &= ~( 1 << BIT_POS ) - same thing here but using the 'and'('&') and 'not'('~') operators, find paper and a logic-table, and try it out if you want to know how it works.
* Toogle bit: Register ^= ( 1 << BIT_POS ) - using bitwise the 'xor'('^') operator, toogles the bit at BIT_POS.
*/
PORTD.DIR |= (1 << LED0); // Set LED0 as output - Using "D" in PORTx.DIR since the LED is connected to port D on the microcontroller
PORTD.DIR |= (1 << LED0); // Set LED0 as output - Using "D" in PORTx.DIR since the LED is connected to port D on the microcontroller.
/*
* The usual way to run microcontrollers is using a simple infinite loop
......
......@@ -15,7 +15,7 @@
<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>
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.2.272\include</AbsolutePath>
<Attribute></Attribute>
<Category>include</Category>
<Condition>C</Condition>
......@@ -26,18 +26,18 @@
<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>
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.2.272\include\avr\iom4809.h</AbsolutePath>
<Attribute></Attribute>
<Category>header</Category>
<Condition>C</Condition>
<FileContentHash>mWiFIOAGwUPlW0rYsXcjkg==</FileContentHash>
<FileContentHash>fQaG1DJ4X5qUUwRvErAbNQ==</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>
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.2.272\templates\main.c</AbsolutePath>
<Attribute>template</Attribute>
<Category>source</Category>
<Condition>C Exe</Condition>
......@@ -48,7 +48,7 @@
<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>
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.2.272\templates\main.cpp</AbsolutePath>
<Attribute>template</Attribute>
<Category>source</Category>
<Condition>C Exe</Condition>
......@@ -59,7 +59,7 @@
<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>
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.2.272\gcc\dev\atmega4809</AbsolutePath>
<Attribute></Attribute>
<Category>libraryPrefix</Category>
<Condition>GCC</Condition>
......@@ -71,8 +71,8 @@
</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>
<PackPath>C:/Program Files (x86)/Atmel/Studio/7.0/Packs/Atmel/ATmega_DFP/1.2.272/Atmel.ATmega_DFP.pdsc</PackPath>
<PackVersion>1.2.272</PackVersion>
<PresentInProject>true</PresentInProject>
<ReferenceConditionId>ATmega4809</ReferenceConditionId>
<RteComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
......
......@@ -15,21 +15,25 @@
#include <util/delay.h>
/*
* Check out the ATtiny4809 datasheet to find the correct ports and pins
*/
* Take a look at the Atmega4809 Curiosity Nano board and locate "SW0" and "LED0".
* Right below each of them you can see which pin they are connected to. For example, if it said PD5, this would mean Port D and Pin 5.
* This info can also be found in the ATmega4809 Curiosity Nano Hardware User Guide here: http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega4809-Curiosity-Nano-HW-UG-DS50002804A.pdf to find the correct ports and pins
*/
//Fill in the defines with the information you found on the board/in the user guide.
// LED
#define LED0 4 //On port D
#define LED0 //Fill in pin number
// Button
#define SW0 2 //On port C
#define SW0 //Fill in pin number
int main(void)
{
/*
* We want to send signals to the LEDs, in order to turn it off and on.
* We also want to be able to read the switches.
* This is done by setting bits in the PORTx.DIR register (in this case PORTD.DIR and PORTC.DIR)
* This is done by setting bits in the PORTx.DIR register (in this case PORTF.DIR)
* PORTx.DIR: 1 is output, 0 is input
* LED: 1 LED is off, 0 LED is on
* Button: 1 Button is open, 0 button is pressed
......@@ -41,7 +45,7 @@ int main(void)
/**
* In order to read from the switches, we need to give it a ground reference, via a pull-up resistor.
* If we don't, the switch will have a floating ground, and hence its value will be undefined.
* On the ATtiny4809, we enable pull-up by setting the "PORT_PULLUPEN" flag in "PORTx.PINnCTRL" high.
* On the ATmega4809, we enable pull-up by setting the "PORT_PULLUPEN" flag in "PORTx.PINnCTRL" high.
* See datasheet section 15 (I/O-ports).
*/
......
---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
---Session 3---
Task 1:
Use the ADC to read the value of the light sensor on I/O 1 and send it over uart.
Task 2:
Write an SPI driver and and test it with the OLED screen and provided image.
Task 3: (OPTIONAL)
Use the screen and buttons to make a game! (Suggestion: Simon says)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment