Camino Version 1.3 b00005
Schematic und Layout auf Eagle Version 7.2 migriert Einige Testprogramme für das Board geadded (Atmel Studio 7)
This commit is contained in:
20
cpp/tests/adc_test/adc_test.atsln
Normal file
20
cpp/tests/adc_test/adc_test.atsln
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Atmel Studio Solution File, Format Version 11.00
|
||||
Project("{E66E83B9-2572-4076-B26E-6BE79FF3018A}") = "adc_test", "adc_test\adc_test.cppproj", "{B83DAF80-E747-47FD-8AD7-6DAD72B329EC}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|AVR = Debug|AVR
|
||||
Release|AVR = Release|AVR
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{B83DAF80-E747-47FD-8AD7-6DAD72B329EC}.Debug|AVR.ActiveCfg = Debug|AVR
|
||||
{B83DAF80-E747-47FD-8AD7-6DAD72B329EC}.Debug|AVR.Build.0 = Debug|AVR
|
||||
{B83DAF80-E747-47FD-8AD7-6DAD72B329EC}.Release|AVR.ActiveCfg = Release|AVR
|
||||
{B83DAF80-E747-47FD-8AD7-6DAD72B329EC}.Release|AVR.Build.0 = Release|AVR
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
55
cpp/tests/adc_test/adc_test/adc_test.cpp
Normal file
55
cpp/tests/adc_test/adc_test/adc_test.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* adc_test.cpp
|
||||
*
|
||||
* Created: 03.06.2015 17:52:29
|
||||
* Author: Zephram
|
||||
*/
|
||||
|
||||
#define F_CPU 16000000
|
||||
|
||||
#include <stdio.h>
|
||||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
#include "lcd-routines.h"
|
||||
#include "lcd-routines.c"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ADMUX |= (1<<REFS0); // Set Reference to AVCC and input to ADC0 (single)
|
||||
|
||||
ADCSRA |= (1<<ADEN)|(1<<ADPS2 | ADPS1 | ADPS0); // Enable ADC, set prescaler to 16
|
||||
// Fadc=Fcpu/prescaler=16.000.000/128=125kHz
|
||||
// Fadc should be between 50kHz and 200kHz
|
||||
|
||||
lcd_init();
|
||||
|
||||
lcd_clear();
|
||||
|
||||
lcd_string("adc test");
|
||||
|
||||
_delay_ms(1000);
|
||||
|
||||
lcd_clear();
|
||||
|
||||
char szText[9];
|
||||
double fValue;
|
||||
|
||||
while(1)
|
||||
{
|
||||
ADCSRA |= (1<<ADSC); // Start a conversion
|
||||
|
||||
while(ADCSRA & (1<<ADSC)); // What until the bit is reset by the
|
||||
// CPU after the conversion is finished
|
||||
|
||||
fValue = (double)ADC * 5.0 / 1024.0;
|
||||
|
||||
sprintf(szText,"U = %.2f V",fValue);
|
||||
|
||||
lcd_clear();
|
||||
lcd_string(szText);
|
||||
|
||||
_delay_ms(1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
157
cpp/tests/adc_test/adc_test/adc_test.cppproj
Normal file
157
cpp/tests/adc_test/adc_test/adc_test.cppproj
Normal file
@@ -0,0 +1,157 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectVersion>7.0</ProjectVersion>
|
||||
<ToolchainName>com.Atmel.AVRGCC8.CPP</ToolchainName>
|
||||
<ProjectGuid>{b83daf80-e747-47fd-8ad7-6dad72b329ec}</ProjectGuid>
|
||||
<avrdevice>ATmega32</avrdevice>
|
||||
<avrdeviceseries>none</avrdeviceseries>
|
||||
<OutputType>Executable</OutputType>
|
||||
<Language>CPP</Language>
|
||||
<OutputFileName>$(MSBuildProjectName)</OutputFileName>
|
||||
<OutputFileExtension>.elf</OutputFileExtension>
|
||||
<OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
|
||||
<AssemblyName>adc_test</AssemblyName>
|
||||
<Name>adc_test</Name>
|
||||
<RootNamespace>adc_test</RootNamespace>
|
||||
<ToolchainFlavour>Native</ToolchainFlavour>
|
||||
<KeepTimersRunning>true</KeepTimersRunning>
|
||||
<OverrideVtor>false</OverrideVtor>
|
||||
<CacheFlash>true</CacheFlash>
|
||||
<ProgFlashFromRam>true</ProgFlashFromRam>
|
||||
<RamSnippetAddress />
|
||||
<UncachedRange />
|
||||
<preserveEEPROM>true</preserveEEPROM>
|
||||
<OverrideVtorValue />
|
||||
<BootSegment>2</BootSegment>
|
||||
<eraseonlaunchrule>1</eraseonlaunchrule>
|
||||
<AsfFrameworkConfig>
|
||||
<framework-data xmlns="">
|
||||
<options />
|
||||
<configurations />
|
||||
<files />
|
||||
<documentation help="" />
|
||||
<offline-documentation help="" />
|
||||
<dependencies>
|
||||
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.22.0" />
|
||||
</dependencies>
|
||||
</framework-data>
|
||||
</AsfFrameworkConfig>
|
||||
<ExternalProgrammingToolCommand />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<ToolchainSettings>
|
||||
<AvrGccCpp>
|
||||
<avrgcc.common.Device>-mmcu=atmega32 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.0.90\gcc\dev\atmega32"</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.0.90\include</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.directories.IncludePaths>
|
||||
<avrgcc.compiler.optimization.level>Optimize (-O1)</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>
|
||||
<avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<avrgcccpp.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>DEBUG</Value>
|
||||
</ListValues>
|
||||
</avrgcccpp.compiler.symbols.DefSymbols>
|
||||
<avrgcccpp.compiler.directories.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.0.90\include</Value>
|
||||
</ListValues>
|
||||
</avrgcccpp.compiler.directories.IncludePaths>
|
||||
<avrgcccpp.compiler.optimization.level>Optimize (-O1)</avrgcccpp.compiler.optimization.level>
|
||||
<avrgcccpp.compiler.optimization.PackStructureMembers>True</avrgcccpp.compiler.optimization.PackStructureMembers>
|
||||
<avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>
|
||||
<avrgcccpp.compiler.optimization.DebugLevel>Default (-g2)</avrgcccpp.compiler.optimization.DebugLevel>
|
||||
<avrgcccpp.compiler.warnings.AllWarnings>True</avrgcccpp.compiler.warnings.AllWarnings>
|
||||
<avrgcccpp.linker.general.UseVprintfLibrary>True</avrgcccpp.linker.general.UseVprintfLibrary>
|
||||
<avrgcccpp.linker.libraries.Libraries>
|
||||
<ListValues>
|
||||
<Value>libm</Value>
|
||||
<Value>printf_flt.a</Value>
|
||||
</ListValues>
|
||||
</avrgcccpp.linker.libraries.Libraries>
|
||||
<avrgcccpp.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcccpp.assembler.debugging.DebugLevel>
|
||||
</AvrGccCpp>
|
||||
</ToolchainSettings>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<ToolchainSettings>
|
||||
<AvrGccCpp>
|
||||
<avrgcc.common.Device>-mmcu=atmega32 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.0.90\gcc\dev\atmega32"</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.0.90\include</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.directories.IncludePaths>
|
||||
<avrgcc.compiler.optimization.level>Optimize (-O1)</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>
|
||||
<avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<avrgcccpp.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>DEBUG</Value>
|
||||
</ListValues>
|
||||
</avrgcccpp.compiler.symbols.DefSymbols>
|
||||
<avrgcccpp.compiler.directories.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.0.90\include</Value>
|
||||
</ListValues>
|
||||
</avrgcccpp.compiler.directories.IncludePaths>
|
||||
<avrgcccpp.compiler.optimization.level>Optimize (-O1)</avrgcccpp.compiler.optimization.level>
|
||||
<avrgcccpp.compiler.optimization.PackStructureMembers>True</avrgcccpp.compiler.optimization.PackStructureMembers>
|
||||
<avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>
|
||||
<avrgcccpp.compiler.optimization.DebugLevel>Default (-g2)</avrgcccpp.compiler.optimization.DebugLevel>
|
||||
<avrgcccpp.compiler.warnings.AllWarnings>True</avrgcccpp.compiler.warnings.AllWarnings>
|
||||
<avrgcccpp.linker.general.UseVprintfLibrary>True</avrgcccpp.linker.general.UseVprintfLibrary>
|
||||
<avrgcccpp.linker.libraries.Libraries>
|
||||
<ListValues>
|
||||
<Value>libm</Value>
|
||||
<Value>printf_flt.a</Value>
|
||||
</ListValues>
|
||||
</avrgcccpp.linker.libraries.Libraries>
|
||||
<avrgcccpp.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcccpp.assembler.debugging.DebugLevel>
|
||||
</AvrGccCpp>
|
||||
</ToolchainSettings>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="adc_test.cpp">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
|
||||
</Project>
|
||||
176
cpp/tests/adc_test/adc_test/lcd-routines.c
Normal file
176
cpp/tests/adc_test/adc_test/lcd-routines.c
Normal file
@@ -0,0 +1,176 @@
|
||||
// Ansteuerung eines HD44780 kompatiblen LCD im 4-Bit-Interfacemodus
|
||||
// http://www.mikrocontroller.net/articles/HD44780
|
||||
// http://www.mikrocontroller.net/articles/AVR-GCC-Tutorial/LCD-Ansteuerung
|
||||
//
|
||||
// Die Pinbelegung ist über defines in lcd-routines.h einstellbar
|
||||
|
||||
#include <avr/io.h>
|
||||
#include "lcd-routines.h"
|
||||
#include <util/delay.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Erzeugt einen Enable-Puls
|
||||
static void lcd_enable( void )
|
||||
{
|
||||
LCD_PORT |= (1<<LCD_EN); // Enable auf 1 setzen
|
||||
_delay_us( LCD_ENABLE_US ); // kurze Pause
|
||||
LCD_PORT &= ~(1<<LCD_EN); // Enable auf 0 setzen
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Sendet eine 4-bit Ausgabeoperation an das LCD
|
||||
static void lcd_out( uint8_t data )
|
||||
{
|
||||
data &= 0xF0; // obere 4 Bit maskieren
|
||||
|
||||
LCD_PORT &= ~(0xF0>>(4-LCD_DB)); // Maske löschen
|
||||
LCD_PORT |= (data>>(4-LCD_DB)); // Bits setzen
|
||||
lcd_enable();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Initialisierung: muss ganz am Anfang des Programms aufgerufen werden.
|
||||
void lcd_init( void )
|
||||
{
|
||||
// verwendete Pins auf Ausgang schalten
|
||||
uint8_t pins = (0x0F << LCD_DB) | // 4 Datenleitungen
|
||||
(1<<LCD_RS) | // R/S Leitung
|
||||
(1<<LCD_EN); // Enable Leitung
|
||||
LCD_DDR |= pins;
|
||||
|
||||
// initial alle Ausgänge auf Null
|
||||
LCD_PORT &= ~pins;
|
||||
|
||||
// warten auf die Bereitschaft des LCD
|
||||
_delay_ms( LCD_BOOTUP_MS );
|
||||
|
||||
// Soft-Reset muss 3mal hintereinander gesendet werden zur Initialisierung
|
||||
lcd_out( LCD_SOFT_RESET );
|
||||
_delay_ms( LCD_SOFT_RESET_MS1 );
|
||||
|
||||
lcd_enable();
|
||||
_delay_ms( LCD_SOFT_RESET_MS2 );
|
||||
|
||||
lcd_enable();
|
||||
_delay_ms( LCD_SOFT_RESET_MS3 );
|
||||
|
||||
// 4-bit Modus aktivieren
|
||||
lcd_out( LCD_SET_FUNCTION |
|
||||
LCD_FUNCTION_4BIT );
|
||||
_delay_ms( LCD_SET_4BITMODE_MS );
|
||||
|
||||
// 4-bit Modus / 2 Zeilen / 5x7
|
||||
lcd_command( LCD_SET_FUNCTION |
|
||||
LCD_FUNCTION_4BIT |
|
||||
LCD_FUNCTION_2LINE |
|
||||
LCD_FUNCTION_5X7 );
|
||||
|
||||
// Display ein / Cursor aus / Blinken aus
|
||||
lcd_command( LCD_SET_DISPLAY |
|
||||
LCD_DISPLAY_ON |
|
||||
LCD_CURSOR_OFF |
|
||||
LCD_BLINKING_OFF);
|
||||
|
||||
// Cursor inkrement / kein Scrollen
|
||||
lcd_command( LCD_SET_ENTRY |
|
||||
LCD_ENTRY_INCREASE |
|
||||
LCD_ENTRY_NOSHIFT );
|
||||
|
||||
lcd_clear();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Sendet ein Datenbyte an das LCD
|
||||
void lcd_data( uint8_t data )
|
||||
{
|
||||
LCD_PORT |= (1<<LCD_RS); // RS auf 1 setzen
|
||||
|
||||
lcd_out( data ); // zuerst die oberen,
|
||||
lcd_out( data<<4 ); // dann die unteren 4 Bit senden
|
||||
|
||||
_delay_us( LCD_WRITEDATA_US );
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Sendet einen Befehl an das LCD
|
||||
void lcd_command( uint8_t data )
|
||||
{
|
||||
LCD_PORT &= ~(1<<LCD_RS); // RS auf 0 setzen
|
||||
|
||||
lcd_out( data ); // zuerst die oberen,
|
||||
lcd_out( data<<4 ); // dann die unteren 4 Bit senden
|
||||
|
||||
_delay_us( LCD_COMMAND_US );
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Sendet den Befehl zur Löschung des Displays
|
||||
void lcd_clear( void )
|
||||
{
|
||||
lcd_command( LCD_CLEAR_DISPLAY );
|
||||
_delay_ms( LCD_CLEAR_DISPLAY_MS );
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Sendet den Befehl: Cursor Home
|
||||
void lcd_home( void )
|
||||
{
|
||||
lcd_command( LCD_CURSOR_HOME );
|
||||
_delay_ms( LCD_CURSOR_HOME_MS );
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Setzt den Cursor in Spalte x (0..15) Zeile y (1..4)
|
||||
|
||||
void lcd_setcursor( uint8_t x, uint8_t y )
|
||||
{
|
||||
uint8_t data;
|
||||
|
||||
switch (y)
|
||||
{
|
||||
case 1: // 1. Zeile
|
||||
data = LCD_SET_DDADR + LCD_DDADR_LINE1 + x;
|
||||
break;
|
||||
|
||||
case 2: // 2. Zeile
|
||||
data = LCD_SET_DDADR + LCD_DDADR_LINE2 + x;
|
||||
break;
|
||||
|
||||
case 3: // 3. Zeile
|
||||
data = LCD_SET_DDADR + LCD_DDADR_LINE3 + x;
|
||||
break;
|
||||
|
||||
case 4: // 4. Zeile
|
||||
data = LCD_SET_DDADR + LCD_DDADR_LINE4 + x;
|
||||
break;
|
||||
|
||||
default:
|
||||
return; // für den Fall einer falschen Zeile
|
||||
}
|
||||
|
||||
lcd_command( data );
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Schreibt einen String auf das LCD
|
||||
|
||||
void lcd_string( const char *data )
|
||||
{
|
||||
while( *data != '\0' )
|
||||
lcd_data( *data++ );
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Schreibt ein Zeichen in den Character Generator RAM
|
||||
|
||||
void lcd_generatechar( uint8_t code, const uint8_t *data )
|
||||
{
|
||||
// Startposition des Zeichens einstellen
|
||||
lcd_command( LCD_SET_CGADR | (code<<3) );
|
||||
|
||||
// Bitmuster übertragen
|
||||
for ( uint8_t i=0; i<8; i++ )
|
||||
{
|
||||
lcd_data( data[i] );
|
||||
}
|
||||
}
|
||||
155
cpp/tests/adc_test/adc_test/lcd-routines.h
Normal file
155
cpp/tests/adc_test/adc_test/lcd-routines.h
Normal file
@@ -0,0 +1,155 @@
|
||||
// Ansteuerung eines HD44780 kompatiblen LCD im 4-Bit-Interfacemodus
|
||||
// http://www.mikrocontroller.net/articles/AVR-GCC-Tutorial/LCD-Ansteuerung
|
||||
//
|
||||
|
||||
#ifndef LCD_ROUTINES_H
|
||||
#define LCD_ROUTINES_H
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Hier die verwendete Taktfrequenz in Hz eintragen, wichtig!
|
||||
|
||||
#ifndef F_CPU
|
||||
#define F_CPU 16000000
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Pinbelegung für das LCD, an verwendete Pins anpassen
|
||||
// Alle LCD Pins müssen an einem Port angeschlossen sein und die 4
|
||||
// Datenleitungen müssen auf aufeinanderfolgenden Pins liegen
|
||||
|
||||
// LCD DB4-DB7 <--> PORTC Bit PC2-PD5
|
||||
#define LCD_PORT PORTC
|
||||
#define LCD_DDR DDRC
|
||||
#define LCD_DB PC2
|
||||
|
||||
// LCD RS <--> PORTD Bit PD4 (RS: 1=Data, 0=Command)
|
||||
#define LCD_RS PC6
|
||||
|
||||
// LCD EN <--> PORTD Bit PD5 (EN: 1-Impuls für Daten)
|
||||
#define LCD_EN PC7
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// LCD Ausführungszeiten (MS=Millisekunden, US=Mikrosekunden)
|
||||
|
||||
#define LCD_BOOTUP_MS 15
|
||||
#define LCD_ENABLE_US 20
|
||||
#define LCD_WRITEDATA_US 46
|
||||
#define LCD_COMMAND_US 42
|
||||
|
||||
#define LCD_SOFT_RESET_MS1 5
|
||||
#define LCD_SOFT_RESET_MS2 1
|
||||
#define LCD_SOFT_RESET_MS3 1
|
||||
#define LCD_SET_4BITMODE_MS 5
|
||||
|
||||
#define LCD_CLEAR_DISPLAY_MS 2
|
||||
#define LCD_CURSOR_HOME_MS 2
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Zeilendefinitionen des verwendeten LCD
|
||||
// Die Einträge hier sollten für ein LCD mit einer Zeilenlänge von 16 Zeichen passen
|
||||
// Bei anderen Zeilenlängen müssen diese Einträge angepasst werden
|
||||
|
||||
#define LCD_DDADR_LINE1 0x00
|
||||
#define LCD_DDADR_LINE2 0x40
|
||||
#define LCD_DDADR_LINE3 0x10
|
||||
#define LCD_DDADR_LINE4 0x50
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Initialisierung: muss ganz am Anfang des Programms aufgerufen werden.
|
||||
void lcd_init( void );
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// LCD löschen
|
||||
void lcd_clear( void );
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Cursor in die 1. Zeile, 0-te Spalte
|
||||
void lcd_home( void );
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Cursor an eine beliebige Position
|
||||
void lcd_setcursor( uint8_t spalte, uint8_t zeile );
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Ausgabe eines einzelnen Zeichens an der aktuellen Cursorposition
|
||||
void lcd_data( uint8_t data );
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Ausgabe eines Strings an der aktuellen Cursorposition
|
||||
void lcd_string( const char *data );
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Definition eines benutzerdefinierten Sonderzeichens.
|
||||
// data muss auf ein Array[8] mit den Zeilencodes des zu definierenden Zeichens
|
||||
// zeigen
|
||||
void lcd_generatechar( uint8_t code, const uint8_t *data );
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Ausgabe eines Kommandos an das LCD.
|
||||
void lcd_command( uint8_t data );
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// LCD Befehle und Argumente.
|
||||
// Zur Verwendung in lcd_command
|
||||
|
||||
// Clear Display -------------- 0b00000001
|
||||
#define LCD_CLEAR_DISPLAY 0x01
|
||||
|
||||
// Cursor Home ---------------- 0b0000001x
|
||||
#define LCD_CURSOR_HOME 0x02
|
||||
|
||||
// Set Entry Mode ------------- 0b000001xx
|
||||
#define LCD_SET_ENTRY 0x04
|
||||
|
||||
#define LCD_ENTRY_DECREASE 0x00
|
||||
#define LCD_ENTRY_INCREASE 0x02
|
||||
#define LCD_ENTRY_NOSHIFT 0x00
|
||||
#define LCD_ENTRY_SHIFT 0x01
|
||||
|
||||
// Set Display ---------------- 0b00001xxx
|
||||
#define LCD_SET_DISPLAY 0x08
|
||||
|
||||
#define LCD_DISPLAY_OFF 0x00
|
||||
#define LCD_DISPLAY_ON 0x04
|
||||
#define LCD_CURSOR_OFF 0x00
|
||||
#define LCD_CURSOR_ON 0x02
|
||||
#define LCD_BLINKING_OFF 0x00
|
||||
#define LCD_BLINKING_ON 0x01
|
||||
|
||||
// Set Shift ------------------ 0b0001xxxx
|
||||
#define LCD_SET_SHIFT 0x10
|
||||
|
||||
#define LCD_CURSOR_MOVE 0x00
|
||||
#define LCD_DISPLAY_SHIFT 0x08
|
||||
#define LCD_SHIFT_LEFT 0x00
|
||||
#define LCD_SHIFT_RIGHT 0x04
|
||||
|
||||
// Set Function --------------- 0b001xxxxx
|
||||
#define LCD_SET_FUNCTION 0x20
|
||||
|
||||
#define LCD_FUNCTION_4BIT 0x00
|
||||
#define LCD_FUNCTION_8BIT 0x10
|
||||
#define LCD_FUNCTION_1LINE 0x00
|
||||
#define LCD_FUNCTION_2LINE 0x08
|
||||
#define LCD_FUNCTION_5X7 0x00
|
||||
#define LCD_FUNCTION_5X10 0x04
|
||||
|
||||
#define LCD_SOFT_RESET 0x30
|
||||
|
||||
// Set CG RAM Address --------- 0b01xxxxxx (Character Generator RAM)
|
||||
#define LCD_SET_CGADR 0x40
|
||||
|
||||
#define LCD_GC_CHAR0 0
|
||||
#define LCD_GC_CHAR1 1
|
||||
#define LCD_GC_CHAR2 2
|
||||
#define LCD_GC_CHAR3 3
|
||||
#define LCD_GC_CHAR4 4
|
||||
#define LCD_GC_CHAR5 5
|
||||
#define LCD_GC_CHAR6 6
|
||||
#define LCD_GC_CHAR7 7
|
||||
|
||||
// Set DD RAM Address --------- 0b1xxxxxxx (Display Data RAM)
|
||||
#define LCD_SET_DDADR 0x80
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user