diff --git a/GccApplication3_6_2(1).atsln b/GccApplication3_6_2(1).atsln new file mode 100644 index 0000000..f1859a4 --- /dev/null +++ b/GccApplication3_6_2(1).atsln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Atmel Studio Solution File, Format Version 11.00 +Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "GccApplication3", "GccApplication3_6_2(1).cproj", "{94BBCABE-3E5B-448F-A40B-2B08DEF16444}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|AVR = Debug|AVR + Release|AVR = Release|AVR + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {94BBCABE-3E5B-448F-A40B-2B08DEF16444}.Debug|AVR.ActiveCfg = Debug|AVR + {94BBCABE-3E5B-448F-A40B-2B08DEF16444}.Debug|AVR.Build.0 = Debug|AVR + {94BBCABE-3E5B-448F-A40B-2B08DEF16444}.Release|AVR.ActiveCfg = Release|AVR + {94BBCABE-3E5B-448F-A40B-2B08DEF16444}.Release|AVR.Build.0 = Release|AVR + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/GccApplication3_6_2(1).cproj b/GccApplication3_6_2(1).cproj new file mode 100644 index 0000000..bc2853f --- /dev/null +++ b/GccApplication3_6_2(1).cproj @@ -0,0 +1,140 @@ + + + + 2.0 + 6.2 + com.Atmel.AVRGCC8.C + {94bbcabe-3e5b-448f-a40b-2b08def16444} + ATmega328P + none + Executable + C + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + GccApplication3 + GccApplication3 + GccApplication3 + Native + true + false + true + true + + + true + + 2 + 1 + + + + + + + + + + + + + + + + + True + True + True + True + False + True + True + + + NDEBUG + + + Optimize for size (-Os) + True + True + True + + + libm + + + + + + + + + True + True + True + True + False + True + True + + + DEBUG + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + compile + + + compile + + + compile + + + compile + + + compile + + + compile + + + compile + + + compile + + + compile + + + compile + + + compile + + + compile + + + compile + + + + \ No newline at end of file diff --git a/GccApplication3_6_2.componentinfo.xml b/GccApplication3_6_2.componentinfo.xml new file mode 100644 index 0000000..501d52b --- /dev/null +++ b/GccApplication3_6_2.componentinfo.xml @@ -0,0 +1,86 @@ + + + + + + + Device + Startup + + + Atmel + 1.2.0 + C:/Program Files (x86)\Atmel\Studio\7.0\Packs + + + + + C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include + + include + C + + + include + + + + + C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include\avr\iom328p.h + + header + C + UMk4QUzkkuShabuoYtNl/Q== + + include/avr/iom328p.h + + + + + C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\templates\main.c + template + source + C Exe + GD1k8YYhulqRs6FD1B2Hog== + + templates/main.c + Main file (.c) + + + + C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\templates\main.cpp + template + source + C Exe + YXFphlh0CtZJU+ebktABgQ== + + templates/main.cpp + Main file (.cpp) + + + + C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega328p + + libraryPrefix + GCC + + + gcc/dev/atmega328p + + + + + ATmega_DFP + C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.209/Atmel.ATmega_DFP.pdsc + 1.2.209 + true + ATmega328P + + + + Resolved + Fixed + true + + + \ No newline at end of file diff --git a/GccApplication3_6_2.cproj b/GccApplication3_6_2.cproj index bc2853f..e83d7fe 100644 --- a/GccApplication3_6_2.cproj +++ b/GccApplication3_6_2.cproj @@ -2,7 +2,7 @@ 2.0 - 6.2 + 7.0 com.Atmel.AVRGCC8.C {94bbcabe-3e5b-448f-a40b-2b08def16444} ATmega328P @@ -27,72 +27,96 @@ 2 1 - - - - - - - - - - + + + + + + + + + + + 0 + - True - True - True - True - False - True - True - - - NDEBUG - - - Optimize for size (-Os) - True - True - True - - - libm - - - + -mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega328p" + True + True + True + True + False + True + True + + + NDEBUG + + + + + %24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include + + + Optimize for size (-Os) + True + True + True + + + libm + + + + + %24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include + + + - True - True - True - True - False - True - True - - - DEBUG - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - + -mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega328p" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + + + %24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include + + + Default (-Wa,-g) + diff --git a/func.c b/func.c index b1ffda1..1be3994 100644 --- a/func.c +++ b/func.c @@ -50,16 +50,40 @@ void split_digits(long number, long* digits, int size) { } } -static char map(int digit) { - if (digit >= 0 && digit <= 9) - return digit + 0x09; - else - return 0x01; +static char map(char c) { + //if (c >= 0 && c <= 9) + //return c - 0x27; + //else + //return 0x01; + switch (c) { + case 0x30: + return 0x09; + case 0x31: + return 0x0a; + case 0x32: + return 0x0b; + case 0x33: + return 0x0c; + case 0x34: + return 0x0d; + case 0x35: + return 0x0e; + case 0x36: + return 0x0f; + case 0x37: + return 0x10; + case 0x38: + return 0x11; + case 0x39: + return 0x12; + case 0x2d: + return 0x06; + } } -void map_digits(char* arr, long *digits, int size) { +void map_digits(char* arr, char *digits, int size) { int idx = 0; - for (int i = size - 1; i >= 0; i--) { + for (int i = 0; i < size; i++) { arr[idx] = map(digits[i]); idx++; } diff --git a/func.h b/func.h index 69a57a2..dead4a3 100644 --- a/func.h +++ b/func.h @@ -9,5 +9,5 @@ void delay(); void split_digits(long number, long* digits, int size); int count_digits(long number); -void map_digits(char* arr, long *digits, int size); +void map_digits(char* arr, char *digits, int size); void prepare_data(char *arr, long number, int size); diff --git a/spi_master.c b/spi_master.c index bd487fb..e5edd3e 100644 --- a/spi_master.c +++ b/spi_master.c @@ -6,13 +6,13 @@ #include "func.h" #include -#define MAX_DIGITS 11 +#define MAX_DIGITS 12 #define F_CPU 16000000UL #define DELAY_MS 2000 void output_on_display(struct calculator *calc) { - char buffer[8]; + char buffer[32]; switch (calc->state) { case NUMBER_FIRST: @@ -23,13 +23,7 @@ void output_on_display(struct calculator *calc) b_size = display_set_page(0x01, buffer); SPI_MasterTransmit(buffer, b_size); - //int size = count_digits(calc->num1); - char mapped_digits[12]; - //prepare_data(mapped_digits, calc->num1, size); - ltoa(calc->num1 , mapped_digits, 10); - b_size = display_add_simbol(mapped_digits, 12, buffer); - SPI_MasterTransmit(buffer, b_size); - + transmit_num(calc->num1, buffer); break; } case NUMBER_SECOND: @@ -40,12 +34,47 @@ void output_on_display(struct calculator *calc) b_size = display_set_page(0x01, buffer); SPI_MasterTransmit(buffer, b_size); - int size = count_digits(calc->num1); - char mapped_digits[size]; - prepare_data(mapped_digits, calc->num1, size); - b_size = display_add_simbol(mapped_digits, size, buffer); + transmit_num(calc->num1, buffer); + + char symbol[] = {0x01}; + // Îïåðàöèÿ + switch (calc->operation) + { + case NO_OP: + break; + case ADD: + symbol[0] = 0x04; + break; + case SUB: + symbol[0] = 0x06; + break; + case DIV: + symbol[0] = 0x08; + break; + case MUL: + symbol[0] = 0x03; + break; + } + + b_size = display_add_simbol(symbol, 1, buffer); SPI_MasterTransmit(buffer, b_size); + b_size = display_set_page(0x02, buffer); + SPI_MasterTransmit(buffer, b_size); + + transmit_num(calc->num2, buffer); + break; + } + case RESULT: + { + size_t b_size = display_all_clear(0, buffer); + SPI_MasterTransmit(buffer, b_size); + + b_size = display_set_page(0x01, buffer); + SPI_MasterTransmit(buffer, b_size); + + transmit_num(calc->num1, buffer); + char symbol[] = {0x01}; // Îïåðàöèÿ switch (calc->operation) @@ -72,58 +101,7 @@ void output_on_display(struct calculator *calc) b_size = display_set_page(0x02, buffer); SPI_MasterTransmit(buffer, b_size); - size = count_digits(calc->num2); - char mapped_digits1[size]; - prepare_data(mapped_digits1, calc->num2, size); - b_size = display_add_simbol(mapped_digits1, size, buffer); - SPI_MasterTransmit(buffer, b_size); - break; - } - case RESULT: - { - size_t b_size = display_all_clear(0, buffer); - SPI_MasterTransmit(buffer, b_size); - - b_size = display_set_page(0x01, buffer); - SPI_MasterTransmit(buffer, b_size); - - int size = count_digits(calc->num1); - char mapped_digits[size]; - prepare_data(mapped_digits, calc->num1, size); - b_size = display_add_simbol(mapped_digits, size, buffer); - SPI_MasterTransmit(buffer, b_size); - - char symbol[] = {0x01}; - // îïåðàöèÿ - switch (calc->operation) - { - case NO_OP: - break; - case ADD: - symbol[0] = 0x04; - break; - case SUB: - symbol[0] = 0x06; - break; - case DIV: - symbol[0] = 0x08; - break; - case MUL: - symbol[0] = 0x03; - break; - } - - b_size = display_add_simbol(symbol, 1, buffer); - SPI_MasterTransmit(buffer, b_size); - - b_size = display_set_page(0x02, buffer); - SPI_MasterTransmit(buffer, b_size); - - size = count_digits(calc->num2); - char mapped_digits1[size]; - prepare_data(mapped_digits1, calc->num2, size); - b_size = display_add_simbol(mapped_digits1, size, buffer); - SPI_MasterTransmit(buffer, b_size); + transmit_num(calc->num2, buffer); // ðåçóëüòàò b_size = display_set_page(0x03, buffer); @@ -133,11 +111,7 @@ void output_on_display(struct calculator *calc) b_size = display_add_simbol(symbol, 1, buffer); SPI_MasterTransmit(buffer, b_size); - size = count_digits(calc->result); - char mapped_digits2[size]; - prepare_data(mapped_digits2, calc->result, size); - b_size = display_add_simbol(mapped_digits2, size, buffer); - SPI_MasterTransmit(buffer, b_size); + transmit_num(calc->result, buffer); break; } @@ -146,6 +120,15 @@ void output_on_display(struct calculator *calc) } } +void transmit_num(long number, char *buffer) { + char number_buffer[MAX_DIGITS]; + char mapped_digits[MAX_DIGITS]; + ltoa(number, number_buffer, 10); + map_digits(mapped_digits, number_buffer, strlen(number_buffer)); + size_t b_size = display_add_simbol(mapped_digits, strlen(number_buffer), buffer); + SPI_MasterTransmit(buffer, b_size); +} + void SPI_MasterInit(void) { /* Íàñòðîéêà MOSI è SCK êàê âûõîä, diff --git a/spi_master.h b/spi_master.h index 3826c9b..00a900b 100644 --- a/spi_master.h +++ b/spi_master.h @@ -10,9 +10,7 @@ void output_on_display(struct calculator *calc); void SPI_MasterInit(void); void SPI_MasterTransmit(char *buffer, size_t length); -void transmit_first_num(struct calculator *calc, char *buffer); -void transmit_second_num(struct calculator *calc, char *buffer); -void transmit_result(struct calculator *calc, char *buffer, char *symblo); +void transmit_num(long number, char *buffer); size_t display_all_clear(char color, char *buffer); size_t display_add_simbol(char *str, size_t str_len, char *buffer); size_t display_draw_line(char x1, char y1, char x2, char y2, char color, char *buffer);