Display_nums
Dependencies: mbed
Fork of Microprocessors_Template by
main.cpp
- Committer:
- michaelccodega
- Date:
- 2018-02-22
- Revision:
- 2:8412c8623314
- Parent:
- 1:b46d63943c99
- Child:
- 3:48be985187c6
File content as of revision 2:8412c8623314:
/******************************************************************************* *EECS397 * *Assignment Name: Lab 4 Part 1; Display_nums * *Author(s): Ashley Roberson, Michael Codega * *Purpose: * *Last Modified: February 15, 2018 * *******************************************************************************/ #include "mbed.h" #define DSP_TST_ON 0x0f01 #define DSP_TST_OFF 0x0f00 //ASCII character values of decimal numbers #define ZERO 48 #define ONE 49 #define TWO 50 #define THREE 51 #define FOUR 52 #define FIVE 53 #define SIX 54 #define SEVEN 55 #define EIGHT 56 #define NINE 57 SPI display_ctr(PA_7, PA_6, PA_5); DigitalOut dsp_ncs(PC_7); Serial pc(USBTX, USBRX); char input; void promptUser(); int main() { // Setting the formal of display_ctr dsp_ncs = 1; display_ctr.format(16, 0); // Setting to Normal Mode dsp_ncs = 0; display_ctr.write(DSP_TST_OFF); //normal mode dsp_ncs = 1; wait(.5); // Setting it to display 5 digits dsp_ncs = 0; display_ctr.write(0x0b04); //display 5 digits dsp_ncs = 1; wait(.5); /* Setting decode mode */ // This means it only looks at the lower nibble of data, ignoring the // first portion of data dsp_ncs = 0; display_ctr.write(0x090F); //decode mode dsp_ncs = 1; wait(.5); // Setting it to shutdown mode dsp_ncs = 0; display_ctr.write(0x0c01); //shutdown mode dsp_ncs = 1; wait(.5); //dsp_ncs = 0; //display_ctr.write(0x0104); // write a 4 //dsp_ncs = 1; //wait(0.5); // Sets the display to full brightness dsp_ncs = 0; display_ctr.write(0x0A); dsp_ncs = 1; wait(.5); dsp_ncs = 0; while (1) { promptUser(); } }// pcw //Prompt User for Numbers void promptUser() { pc.printf("Please enter a number 0-9:\n"); input = pc.getc(); if (input < 48 || input > 57) { pc.printf("Invalid Number.\n"); promptUser(); } else { switch (input) { case ZERO: pc.printf("You typed 0\n"); display_ctr.write(0x0100); break; case ONE: pc.printf("You typed 1\n"); display_ctr.write(0x0101); break; case TWO: pc.printf("You typed 2\n"); display_ctr.write(0x0102); break; case THREE: pc.printf("You typed 3\n"); display_ctr.write(0x0103); break; case FOUR: pc.printf("You typed 4\n"); display_ctr.write(0x0104); break; case FIVE: pc.printf("You typed 5\n"); display_ctr.write(0x0105); break; case SIX: pc.printf("You typed 6\n"); display_ctr.write(0x0106); break; case SEVEN: pc.printf("You typed 7\n"); display_ctr.write(0x0107); break; case EIGHT: pc.printf("You typed 8\n"); display_ctr.write(0x0108); break; case NINE: display_ctr.write(0x0109); pc.printf("You typed 9\n"); break; } dsp_ncs = 1; wait(0.5); dsp_ncs = 0; } }