Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of Lab_6_WaG by
display.cpp
00001 /****************************************************************************** 00002 * EECS 397 00003 * 00004 * Assignment Name: Lab 6: WaG 00005 * 00006 * Authors: Sam Morrison and Phong Nguyen 00007 * File name: display.cpp 00008 * Purpose: Contain function definitions 00009 * 00010 * Created: 03/01/2018 00011 * Last Modified: 03/29/2018 00012 * 00013 ******************************************************************************/ 00014 #include "mbed.h" 00015 #include "io_pins.h" 00016 #include "display.h" 00017 #include <stdlib.h> 00018 #include <stdio.h> 00019 #include <string.h> 00020 #include "spi.h" 00021 #include "utility.h" 00022 00023 //#define VERSION1 00024 #define VERSION2 00025 00026 extern SPI wag_spi; 00027 extern spi_cfg as1107; 00028 extern Serial pc; 00029 00030 /* 00031 * void initial_setup(struct spi_cfg spi_obj); 00032 * Description: setup spi data length (in bit), spi frequency, set LED 00033 * display to normal operation, and set all display numbers 00034 * to 0. 00035 * 00036 * Inputs: 00037 * Parameters: 00038 * struct spi_cfg spi_obj: spi_cfg object 00039 * 00040 * Outputs: 00041 * Returns: void 00042 */ 00043 void initial_setup(struct spi_cfg spi_obj) { 00044 spi_obj.spi_ncs = 1; 00045 00046 spi_send(spi_obj, 0x0C01); 00047 spi_send(spi_obj, 0x090F); 00048 spi_send(spi_obj, 0x0F00); 00049 spi_send(spi_obj, 0x0A0F); 00050 spi_send(spi_obj, 0x0B04); 00051 spi_send(spi_obj, 0x0100); 00052 spi_send(spi_obj, 0x0200); 00053 spi_send(spi_obj, 0x0300); 00054 spi_send(spi_obj, 0x0400); 00055 spi_send(spi_obj, 0x0500); 00056 } 00057 00058 00059 00060 00061 #ifdef VERSION1 00062 /* 00063 * void bin2bcd_array(int num); 00064 * Description: Converts to BCD array using modulo method. 00065 * 00066 * Inputs: 00067 * Parameters: 00068 * int num: number to push to display 00069 char bcd[]: BCD array that will be written to 00070 * Globals: 00071 * 00072 * Outputs: 00073 * Returns: void 00074 */ 00075 void bin2bcd_array(int num, char bcd[]) { 00076 int place = 0; 00077 while (num != 0) { //converts decimal input to decimal array using %mod 00078 int val = num % 10; 00079 bcd[place] = val; 00080 num = num/10; 00081 place++; 00082 } 00083 } 00084 #endif 00085 00086 #ifdef VERSION2 00087 /* 00088 * void bin2bcd_array(int num); 00089 * Description: converts a number from binary format to binary coded 00090 * decimal array using sprintf() method 00091 * 00092 * Inputs: 00093 * Parameters: 00094 * int num: number in binary format 00095 * char bcd[]: bcd (binary coded decimal) array 00096 * 00097 * Outputs: 00098 * Returns: void 00099 */ 00100 void bin2bcd_array(int num, char bcd[]) { 00101 char tmp_array[4]; 00102 char reverse_bcd[4]; 00103 int last_index = 0; 00104 int i = 0; 00105 00106 sprintf(tmp_array, "%d", num); 00107 for (i = 0; i < 4; i++) { 00108 bcd[i] = 0; 00109 reverse_bcd[i] = 0; 00110 } 00111 00112 while (last_index < 4 and tmp_array[last_index] != '\0') { 00113 reverse_bcd[last_index] = tmp_array[last_index] - '0'; 00114 last_index++; 00115 } 00116 00117 // reverse the order to fit binary coded decimal 00118 for (i = 0; i < last_index; i++) { 00119 bcd[i] = reverse_bcd[last_index - 1 - i]; 00120 } 00121 } 00122 #endif 00123 00124 /* 00125 * void send_command_to_display(char bcd[]); 00126 * Description: send bcd[] array to the display driver to display number 00127 * in the display 00128 * 00129 * Inputs: 00130 * Parameters: 00131 * char bcd[]: bcd (binary coded decimal) array 00132 * 00133 * Outputs: 00134 * Returns: void 00135 */ 00136 void send_command_to_display(char bcd[]) { 00137 int command; 00138 00139 00140 for (int i = 1; i <= 4; i++) { 00141 command = 0; 00142 // command has following form: 0x0[place]0[value] 00143 // the value converted to int is 16 * 16 * place + value 00144 command = 16 * 16 * i + bcd[i - 1]; 00145 spi_send(as1107, command); 00146 } 00147 } 00148 00149 /* 00150 * void test_target_leds(); 00151 * Description: test each LED on the target board 00152 * 00153 * Inputs: 00154 * None 00155 * 00156 * Outputs: 00157 * Returns: void 00158 */ 00159 void test_target_leds() { 00160 int led_command = 0; 00161 while (uti_chk_ubutton() == 0); 00162 pc.printf("test begin\n"); 00163 while (uti_chk_ubutton() == 0) { 00164 for (int i = 1; i <= 128; i = i * 2) { 00165 led_command = 0x0500 + i; 00166 pc.printf("led_command: %d\n", led_command); 00167 spi_send(as1107, led_command); //light up LED[i] 00168 wait(0.1); 00169 spi_send(as1107, 0x0500); //turn off LED[i] 00170 } 00171 } 00172 }
Generated on Mon Jul 18 2022 00:36:30 by
