Commit ac66b8f1 authored by BuildTools's avatar BuildTools
Browse files

Added interrup on pin

parent c359fc4b
usart_basic.d usart_basic.o: .././usart_basic.c \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\io.h \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\sfr_defs.h \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\inttypes.h \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\lib\gcc\avr\5.4.0\include\stdint.h \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\stdint.h \
C:\Program\ Files\ (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\include/avr/iom4809.h \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\portpins.h \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\common.h \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\version.h \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\xmega.h \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\fuse.h \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\lock.h \
.././usart_basic.h \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\lib\gcc\avr\5.4.0\include\stdbool.h \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\stdio.h \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\lib\gcc\avr\5.4.0\include\stdarg.h \
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\lib\gcc\avr\5.4.0\include\stddef.h
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\io.h:
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\sfr_defs.h:
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\inttypes.h:
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\lib\gcc\avr\5.4.0\include\stdint.h:
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\stdint.h:
C:\Program\ Files\ (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\include/avr/iom4809.h:
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\portpins.h:
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\common.h:
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\version.h:
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\xmega.h:
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\fuse.h:
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\avr\lock.h:
.././usart_basic.h:
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\lib\gcc\avr\5.4.0\include\stdbool.h:
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\stdio.h:
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\lib\gcc\avr\5.4.0\include\stdarg.h:
c:\program\ files\ (x86)\atmel\studio\7.0\toolchain\avr8\avr8-gnu-toolchain\lib\gcc\avr\5.4.0\include\stddef.h:
......@@ -139,12 +139,6 @@
<Compile Include="main.c">
<SubType>compile</SubType>
</Compile>
<Compile Include="usart_basic.c">
<SubType>compile</SubType>
</Compile>
<Compile Include="usart_basic.h">
<SubType>compile</SubType>
</Compile>
</ItemGroup>
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
</Project>
\ No newline at end of file
......@@ -8,8 +8,8 @@
#include <avr/io.h>
#include <stdint.h>
#include <stdio.h>
#include <avr/interrupt.h>
#include "usart_basic.h"
#define F_CPU 3333333
......@@ -24,6 +24,11 @@
#define SHIFT_LEFT_14BIT(reg, input) reg = (((reg << 1) | input) & 0x3fff)
uint16_t data_memory [100] = {0};
volatile uint8_t address;
volatile uint16_t address_shift_reg_units = 0;
volatile uint16_t address_shift_reg_tens = 0;
volatile| data_register = 0;
typedef enum
{
......@@ -96,79 +101,81 @@ uint8_t convert_address(uint16_t tens, uint16_t units)
return address;
}
ISR(PORTD_PORT_vect) {
//uint8_t pin_input = wait_rising_clk();
uint8_t pin_input = 0;
uint8_t data_in = (pin_input & PIN_DATA_IN_bm) >> PIN_DATA_IN_bp;
// Invert as the original circuit inverted these values
ctrl_mode_t ctrl_inst = (ctrl_mode_t) (~pin_input) & PIN_CTRL_bm;
switch (ctrl_inst)
{
case CTRL_STANDBY :
set_data_out(0);
break;
case CTRL_READ :
address = convert_address(address_shift_reg_tens, address_shift_reg_units);
data_register = data_memory[address];
break;
case CTRL_ERASE :
address = convert_address(address_shift_reg_tens, address_shift_reg_units);
data_memory[address] = 0;
break;
case CTRL_WRITE :
address = convert_address(address_shift_reg_tens, address_shift_reg_units);
data_memory[address] = data_register;
break;
case CTRL_NOT_USED :
break;
case CTRL_SHIFT_OUT :
// Shift out msp first
{
uint8_t data_out = ( (data_register & 0x200) ? 1 : 0);
SHIFT_LEFT_14BIT(data_register, 0);
set_data_out(data_out);
}
break;
case CTRL_ADDRESS :
// Shift tens register to make space in lsb. Add top bit from units and limit to 10 bits
address_shift_reg_tens = ((address_shift_reg_units << 1) | ((address_shift_reg_units & 0x200) >> 10)) & 0x3ff;
address_shift_reg_units = ((address_shift_reg_units << 1) | data_in) & 0x3ff;
break;
case CTRL_SHIFT_IN :
SHIFT_LEFT_14BIT(data_register, data_in);
break;
}
}
int main(void)
{
PORTD.DIR |= PIN_DATA_OUT_bm;
USART_0_init();
// Enable interrupt on ckl pin
PORTD.PIN3CTRL = PORT_ISC_BOTHEDGES_gc;
printf("hello TEST");
/* Replace with your application code */
while (1)
{
USART_0_write('T');
printf("hello TEST");
uint8_t address;
uint16_t address_shift_reg_units = 0;
uint16_t address_shift_reg_tens = 0;
uint16_t data_register = 0;
//uint8_t pin_input = wait_rising_clk();
uint8_t pin_input = 0;
uint8_t data_in = (pin_input & PIN_DATA_IN_bm) >> PIN_DATA_IN_bp;
// Invert as the original circuit inverted these values
ctrl_mode_t ctrl_inst = (ctrl_mode_t) (~pin_input) & PIN_CTRL_bm;
switch (ctrl_inst)
{
case CTRL_STANDBY :
set_data_out(0);
break;
case CTRL_READ :
address = convert_address(address_shift_reg_tens, address_shift_reg_units);
data_register = data_memory[address];
break;
case CTRL_ERASE :
address = convert_address(address_shift_reg_tens, address_shift_reg_units);
data_memory[address] = 0;
break;
case CTRL_WRITE :
address = convert_address(address_shift_reg_tens, address_shift_reg_units);
data_memory[address] = data_register;
break;
case CTRL_NOT_USED :
break;
case CTRL_SHIFT_OUT :
// Shift out msp first
{
uint8_t data_out = ( (data_register & 0x200) ? 1 : 0);
SHIFT_LEFT_14BIT(data_register, 0);
set_data_out(data_out);
}
break;
case CTRL_ADDRESS :
// Shift tens register to make space in lsb. Add top bit from units and limit to 10 bits
address_shift_reg_tens = ((address_shift_reg_units << 1) | ((address_shift_reg_units & 0x200) >> 10)) & 0x3ff;
address_shift_reg_units = ((address_shift_reg_units << 1) | data_in) & 0x3ff;
break;
case CTRL_SHIFT_IN :
SHIFT_LEFT_14BIT(data_register, data_in);
break;
}
}
}
......
Supports Markdown
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