summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Keithley179.c195
-rw-r--r--Keithley179.cproj132
2 files changed, 327 insertions, 0 deletions
diff --git a/Keithley179.c b/Keithley179.c
new file mode 100644
index 0000000..734336c
--- /dev/null
+++ b/Keithley179.c
@@ -0,0 +1,195 @@
+
+#ifndef F_CPU
+#define F_CPU 4000000UL
+#endif
+
+#include <avr/io.h>
+#include <avr/interrupt.h>
+
+#define UART_BAUDRATE 9600
+
+#define UBRR_VAL (F_CPU / UART_BAUDRATE * 16) - 1
+
+#define b1 PC0
+#define b2 PC1
+#define b3 PC2
+#define b4 PC3
+
+#define d1 PD7
+#define d2 PD4
+#define d3 PD5
+#define d4 PD6
+#define d5 PC3
+
+#define busy PB7 //Busy not Used
+
+//Status
+uint8_t UART_RX;
+uint8_t UART_RX_END;
+uint8_t UART_isInit;
+
+//Buffers
+char out[5]; //Buffer for ADC Input
+char in[16]; //UART Input Buffer
+uint8_t in_cntr; //Counter for UART Input Buffer
+
+ISR(USART_RXC_vect)
+{
+ cli();
+ in[in_cntr] = UDR;
+ if(in[in_cntr] == '\n')
+ UART_RX_END = 1; //Set RX End Flag
+
+ //Check if Buffer is full
+ if(in_cntr < 15)
+ in_cntr ++;
+ else
+ {
+ in_cntr = 0;
+ UART_RX_END = 1; //Set RX End Flag
+ }
+ sei();
+}//USART_RXC_vect
+
+void UART_Init();
+/*
+*Initializes the UART Interface
+*/
+
+void UART_Handle();
+/*
+* should be called on Interrupt of UART
+* Handles UART Communication
+*/
+
+void UART_Send(char *_cSend);
+/*
+*Sends String over UART
+*/
+
+int main(void)
+{
+ //clear Buffers
+ for(int i = 0; i < 5;i++)
+ {
+ out[i] = 0;
+ }
+
+ for(int i = 0; i < 16;i++)
+ {
+ in[i] = 0;
+ }
+
+
+ char temp = 0;
+ in_cntr = 0;
+
+ UART_RX = 0;
+ UART_RX_END = 0;
+ UART_isInit = 0;
+
+ //Set DDRD as Input
+ DDRD = 0;
+ DDRC = 0;
+
+ DDRD |= (1<<PD1); //TX Pin
+
+ sei();
+
+ //INIT UART Interface
+ UART_Init();
+ UART_Send("Hello World!");
+
+ //main loop
+ while(1)
+ {
+ while(!(PORTD & (1<<d1)));
+ temp = PINB << 4;
+ out[4] = temp >> 4;
+ temp = 0;
+
+ while(!(PORTD & (1<<d2)));
+ temp = PINB << 4;
+ out[3] = temp >> 4;
+ temp = 0;
+
+ while(!(PORTD & (1<<d3)));
+ temp = PINB << 4;
+ out[2] = temp >> 4;
+ temp = 0;
+
+ while(!(PORTD & (1<<d4)));
+ temp = PINB << 4;
+ out[1] = temp >> 4;
+ temp = 0;
+
+ while(!(PORTC & (1<<d5)));
+ temp = PINB << 4;
+ out[0] = temp >> 4;
+ temp = 0;
+
+
+ //Convert to ASCII
+ for(int i = 0; i < 5;i++)
+ {
+ out[i] = out[i] + 48;
+ }
+
+ UART_Send(out);
+ //Handle UART
+ //UART_Handle();
+
+ //Reset Buffer
+ for(int i = 0; i < 5;i++)
+ {
+ out[i] = 0;
+ }
+
+ }
+
+ return 0;
+}//main
+
+
+
+void UART_Init()
+{
+ if(UART_isInit == 0)
+ {
+ //Calculate Value for Register
+ uint16_t baudrate = (4000000 / (9600 * 16)) - 1;
+
+ //Set Baudrate
+ UBRRL = baudrate;
+ UBRRH = (baudrate >> 8);
+
+ UCSRB |= (1<<RXEN) | (1<<TXEN); //Enable Reciever and Transmitter
+ UCSRB |= (1<<RXCIE); //Enable Recieve Complete Interrupt
+
+ UART_isInit = 1;
+ }
+
+}//UART_Init
+
+
+
+void UART_Handle()
+{
+ if(UART_isInit == 1)
+ {
+
+ }
+}//UART_Handle
+
+void UART_Send(char *_cSend)
+{
+ if(UART_isInit == 1)
+ {
+ while(*_cSend)
+ {
+ while (!(UCSRA & (1<<UDRE)));
+ UDR = _cSend;
+ _cSend++;
+ }
+ }
+}//UART_send \ No newline at end of file
diff --git a/Keithley179.cproj b/Keithley179.cproj
new file mode 100644
index 0000000..5fe8330
--- /dev/null
+++ b/Keithley179.cproj
@@ -0,0 +1,132 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectVersion>6.2</ProjectVersion>
+ <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
+ <ProjectGuid>{a92aedb3-f7af-427a-b816-80c012deb17d}</ProjectGuid>
+ <avrdevice>ATmega8</avrdevice>
+ <avrdeviceseries>none</avrdeviceseries>
+ <OutputType>Executable</OutputType>
+ <Language>C</Language>
+ <OutputFileName>$(MSBuildProjectName)</OutputFileName>
+ <OutputFileExtension>.elf</OutputFileExtension>
+ <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
+ <AssemblyName>Keithley179</AssemblyName>
+ <Name>Keithley179</Name>
+ <RootNamespace>Keithley179</RootNamespace>
+ <ToolchainFlavour>Native</ToolchainFlavour>
+ <KeepTimersRunning>true</KeepTimersRunning>
+ <OverrideVtor>false</OverrideVtor>
+ <CacheFlash>true</CacheFlash>
+ <ProgFlashFromRam>true</ProgFlashFromRam>
+ <RamSnippetAddress>0x20000000</RamSnippetAddress>
+ <UncachedRange />
+ <OverrideVtorValue>exception_table</OverrideVtorValue>
+ <BootSegment>2</BootSegment>
+ <eraseonlaunchrule>0</eraseonlaunchrule>
+ <AsfFrameworkConfig>
+ <framework-data xmlns="">
+ <options />
+ <configurations />
+ <files />
+ <documentation help="" />
+ <offline-documentation help="" />
+ <dependencies>
+ <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.11.0" />
+ </dependencies>
+ </framework-data>
+ </AsfFrameworkConfig>
+ <avrtool>com.atmel.avrdbg.tool.ispmk2</avrtool>
+ <avrtoolinterface>ISP</avrtoolinterface>
+ <com_atmel_avrdbg_tool_ispmk2>
+ <ToolOptions>
+ <InterfaceProperties>
+ <JtagEnableExtResetOnStartSession>false</JtagEnableExtResetOnStartSession>
+ <IspClock>500000</IspClock>
+ </InterfaceProperties>
+ <InterfaceName>ISP</InterfaceName>
+ </ToolOptions>
+ <ToolType>com.atmel.avrdbg.tool.ispmk2</ToolType>
+ <ToolNumber>000200185657</ToolNumber>
+ <ToolName>AVRISP mkII</ToolName>
+ </com_atmel_avrdbg_tool_ispmk2>
+ <preserveEEPROM>true</preserveEEPROM>
+ <com_atmel_avrdbg_tool_simulator>
+ <ToolOptions xmlns="">
+ <InterfaceProperties>
+ </InterfaceProperties>
+ <InterfaceName>ISP</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.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.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.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>
+ </ToolchainSettings>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
+ <ToolchainSettings>
+ <AvrGcc>
+ <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.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.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>
+ <avrgcc.linker.libraries.Libraries>
+ <ListValues>
+ <Value>libm</Value>
+ </ListValues>
+ </avrgcc.linker.libraries.Libraries>
+ <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
+ </AvrGcc>
+ </ToolchainSettings>
+ </PropertyGroup>
+ <ItemGroup>
+ <Compile Include="Keithley179.c">
+ <SubType>compile</SubType>
+ </Compile>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="TODO.txt">
+ <SubType>compile</SubType>
+ </None>
+ </ItemGroup>
+ <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
+</Project> \ No newline at end of file