Display_nums
Dependencies: mbed
Fork of Microprocessors_Template by
main.cpp
- Committer:
- anr41
- Date:
- 2018-02-19
- Revision:
- 1:b46d63943c99
- Parent:
- 0:24202d4eadef
- Child:
- 2:8412c8623314
File content as of revision 1:b46d63943c99:
/******************************************************************************* *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 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() { dsp_ncs = 1; display_ctr.format(16, 0); while(1) { dsp_ncs = 0; display_ctr.write(DSP_TST_OFF); //normal mode dsp_ncs = 1; wait(.5); dsp_ncs = 0; display_ctr.write(0x090F); //decode mode dsp_ncs = 1; wait(.5); dsp_ncs = 0; display_ctr.write(0x0b04); //display 5 digits dsp_ncs = 1; wait(.5); dsp_ncs = 0; display_ctr.write(0x0c01); //shutdown mode dsp_ncs = 1; wait(.5); dsp_ncs = 0; display_ctr.write(0x0104); dsp_ncs = 1; wait(0.5); dsp_ncs = 0; promptUser(); } } //Prompt User for Numbers void promptUser() { pc.printf("Please enter a number 1-9:\n"); input = pc.getc(); if (input < 49 || input > 57) { pc.printf("Invalid Number.\n"); promptUser(); } else { switch (input) { case ONE: display_ctr.write(0x0101); case TWO: display_ctr.write(0x0102); case THREE: display_ctr.write(0x0103); case FOUR: display_ctr.write(0x0104); case FIVE: display_ctr.write(0x0105); case SIX: display_ctr.write(0x0106); case SEVEN: display_ctr.write(0x0107); case EIGHT: display_ctr.write(0x0108); case NINE: display_ctr.write(0x0109); } dsp_ncs = 1; wait(0.5); } }