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 display_nums2 by
Diff: display.cpp
- Revision:
- 1:3d6796759d45
- Parent:
- 0:0f1c2bf6ab4e
- Child:
- 2:8a0f128f4be5
--- a/display.cpp Wed Feb 28 15:56:29 2018 +0000
+++ b/display.cpp Fri Mar 09 15:53:04 2018 +0000
@@ -1,33 +1,82 @@
#include <io_pins.h>
#include <display.h>
#include <mbed.h>
+#include <stdlib.h>
+#include <spi.h>
-SPI display_ctr(MOSI, MISO, SCLK);
-DigitalOut dsp_ncs(LOAD);
-Serial pc(USBTX, USBRX);
+
+spi_cfg as1107 = {
+
+ SPI_AS1107_ID,
+ DSP_AS1107_NCS,
+ AS1107_MODE, //mode
+ AS1107_FREQ, //frequency
+ AS1107_BITS //num of bits
+};
+//YOU JUST MOVED THE THING SO THIS PROBABLY WON'T WORK RN IF YOU COMPILE
+
+Serial pc_display(USBTX, USBRX);
-void send_data(int dat){
- dsp_ncs = 0;
- display_ctr.write(dat); //configures the decode register
- dsp_ncs = 1;
-}
-
void bin2bcd_array_mod(int *bcdArr, int num){
+ for(int i = 0; i < 4; i++){
+ bcdArr[i] = 0;
+ }
int i = 0;
while(num>0){
- bcdArr[i] = num%10;
+ bcdArr[3-i] = num%10;
num = num/10;
i = i+1;
}
+}
+
+void display_init(){
+ // Configuring the Controller
+ spi_send(as1107, 0x0f01);
+ wait(1.5);
+ spi_send(as1107, 0x0F00);
+ spi_send(as1107, 0x0A0F);
+ spi_send(as1107, 0x0B04);
+ spi_send(as1107, 0x0C01); //set to normal shutdown mode
+ spi_send(as1107, 0x090F); //configures the decode register
+ spi_send(as1107, DISPLAY_1); //Digit 1 is 0
+ spi_send(as1107, DISPLAY_2);
+ spi_send(as1107, DISPLAY_3);
+ spi_send(as1107, DISPLAY_4);
+ spi_send(as1107, LED_DISPLAY);
+}
+
+void bin2bcd_array_sprintf(int *bcdArr, int num){
+ for(int i = 0; i < 4; i++){
+ bcdArr[i] = 0;
+ }
+ char buffer[5];
+ sprintf(buffer, "%d", num);
+
+ if (num<10){
+ bcdArr[3] = buffer[0];
+
+ }
+ else if(num <100){
+ bcdArr[2] = buffer[0];
+ bcdArr[3] = buffer[1];
+
+ }
+ else if(num < 1000){
+ bcdArr[1] = buffer[0];
+ bcdArr[2] = buffer[1];
+ bcdArr[3] = buffer[2];
+
+
+ }
+ else{
+ for(int i = 0; i < 4; i++){
+ bcdArr[i] = buffer[i]-0x30;
+ }
+ }
-//void bin2bcd_array_sprintf(int *bcdArr, int num){
-// pc.printf("ahh");
-//
-//
-//}
-}
\ No newline at end of file
+}
