A twist to the computer that landed man on the moon. More information can be found at http://hackaday.io/project/294-Open-Source-DSKY

Dependencies:   DS1302 keypad mbed

Hardware

Files at this revision

API Documentation at this revision

Comitter:
VivaPenguinos
Date:
Wed Aug 20 00:44:49 2014 +0000
Parent:
5:5f08974ef8bb
Child:
7:3d06d866878c
Commit message:
Experimental Build. Entered in for HAD prize. NO_Light() improved, P00 Improvements, and P06 Completed. Contains Software Licenses in Comments.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Aug 15 20:27:26 2014 +0000
+++ b/main.cpp	Wed Aug 20 00:44:49 2014 +0000
@@ -1,24 +1,24 @@
 /* Introduction
 MBED DSKY
 This is a personal project used developed by penguinos to mix old school technology with a modern twist.
-Version 0.05: July. 24 2014
-    - Indicator lights added
-        - Included Comp ACTY light
-        - Added all indicator lights into Blink all. (Doesn't follow format correctly yet)
-    - R_GET() function now includes the Positive and negative indicator lights for the R rows. (Function has yet to be tested)
-    - GET_Config function during value checking now checks whether the indicator lights for Positive are on or off. (Has yet to be tested also)
-    - P00 - Idling Program Completed
-    - P01 - PreLaunch Initialization Program Completed
-    - P02 - PreLaunch Gyrocompassing Program Completed
-        - Prelaunch_Gyrocompassing_Configure Completed
-    - R1_Component Added
-    
+Version 0.06: August. 15 2014
+    NO_Light() function has now case 8 for Indicator lights
+    - P00 Improvements
+    - P06 CMC Power Down Completed
+        - CMC_Powerdown() Added
+        - CMC_PowerInput() Added
 Notable Credits:
 NASA! - Release of technical documentations regarding the AGC and DSKY
 Ron Burkley and Contributers of "Virtual AGC — AGS — LVDC — Gemini" - Providing Technical documentations, Source Code, explanations,
     and refrences on other sites to make this project successful
 Warning: This may contain author's crude language, and random thoughts.
 
+Software Licenses:
+Keypad.h - Author Copyrighted 2012 but it is under the Open Source License Agreement.
+    Source: http://mbed.org/cookbook/Keypad
+DS1302.h - Open Source License
+    Source: http://mbed.org/components/DS1302-Timekeeping-Chip/
+
 Pin Usage:
 
 Real Time Clock
@@ -56,6 +56,11 @@
     R2-             PTE31
     R3-             PTC6
     COMP ACTY       PTC7
+
+Push Button
+    PRO_BUTT             PTB1
+    CLR_BUTT             PTB2
+    KEYREL_BUTT          PTB3
     
 Shift Registers Data:
 Because the project contains 11 shift registers, All data must be properly formatted before shifting out. each shift register controls 2 7 segments.
@@ -80,6 +85,14 @@
 N_B
 P_A
 P_B
+
+Program Added:
+P01 - PRELAUNCH OR SERVICE - INITIALIZATION PROGRAM
+P02 - PRELAUNCH OR SERVICE - GYROCOMPASSING PROGRAM
+
+Program In Progress (Not completed)
+P00 - CMC IDLING PROGRAM
+P06 - CMC POWER DOWN PROGRAM
  */
  
 // For RTC 
@@ -193,6 +206,7 @@
 void N_GET();       // Grab inputs for Noun
 void NO_Light(int L); // Configures shift registers to 0
 void PreLaunch_Gyrocompassing_Configure(); // For the inputs of the PreLaunch_Gyrocompassing
+void CMC_PowerInput(); // For the Inputs of the CMC_Powerdown();
 int Button_Sort(int sort); // Function that sorts Verb Values
 int R_Concatenate(int C); // Used for concatenating information
 //void ShiftingOut(char myDataOut);
@@ -204,33 +218,52 @@
 void CMC_Idle();                    // P00 - CMC Idling Program
 void PreLaunch_Initialization();    // P01 - Prelaunch - Initialization Program
 void PreLaunch_Gyrocompassing();    // P02 - Prelaunch - Gyrocompassing Program
+void CMC_Powerdown();               // P06 - CMC Power Down Program
 int R1_Component();                // Load Component into R1
 
+// CMC_Idle Variables
+// Time of State Vector Being Integrated
+int ToSSeconds  = 0;
+int ToSMinutes  = 0;
+int ToSHours    = 0;
+
+// Temp Variables or functions. (This should generally have nothing every revision. Either remove or move the items)
+int PRO = 0;
+void CMC_Poweron();
+int Button_Detect = 0; // Used for detecting button presses.
+
 // Pin modes for each pins
-DigitalOut LatchPin(PTC6); //Pin for ST_CP of 74HC595 Pin # 12
-DigitalOut ClockPin(PTC10); //Pin for SH_CP of 74HC595 Pin # 11
-DigitalOut DataPin(PTC11);  //Pin for to DS of 74HC595 Pin # 14
+DigitalOut LatchPin     (PTC6); //Pin for ST_CP of 74HC595 Pin # 12
+DigitalOut ClockPin     (PTC10); //Pin for SH_CP of 74HC595 Pin # 11
+DigitalOut DataPin      (PTC11);  //Pin for to DS of 74HC595 Pin # 14
 
 // Indicator Lights
-DigitalOut UPLINK_ACTY(PTE5); 
-DigitalOut NO_ATT(PTE4);
-DigitalOut STBY(PTE3);
-DigitalOut KEY_REL(PTE2);
-DigitalOut OPP_ERR(PTB11);
-DigitalOut TEMP(PTB10);
-DigitalOut GIMBAL_LOCK(PTB9);
-DigitalOut PROG(PTB8);
-DigitalOut RESTART(PTC12);
-DigitalOut TRACKER(PTC13);
-DigitalOut R1_POS(PTC16);
-DigitalOut R2_POS(PTC17);
-DigitalOut R3_POS(PTA16);
-DigitalOut R1_NEG(PTA17);
-DigitalOut R2_NEG(PTE31);
-DigitalOut R3_NEG(PTD6);
-DigitalOut COMP_ACTY(PTD7);
+DigitalOut UPLINK_ACTY  (PTE5); 
+DigitalOut NO_ATT       (PTE4);
+DigitalOut STBY         (PTE3);
+DigitalOut KEY_REL      (PTE2);
+DigitalOut OPP_ERR      (PTB11);
+DigitalOut TEMP         (PTB10);
+DigitalOut GIMBAL_LOCK  (PTB9);
+DigitalOut PROG         (PTB8);
+DigitalOut RESTART      (PTC12);
+DigitalOut TRACKER      (PTC13);
+DigitalOut R1_POS       (PTC16);
+DigitalOut R2_POS       (PTC17);
+DigitalOut R3_POS       (PTA16);
+DigitalOut R1_NEG       (PTA17);
+DigitalOut R2_NEG       (PTE31);
+DigitalOut R3_NEG       (PTD6);
+DigitalOut COMP_ACTY    (PTD7);
 
+// Push Buttons
+DigitalIn PRO_BUTT      (PTB1);
+DigitalIn CLR_BUTT      (PTB2);
+DigitalIn KEYREL_BUTT   (PTB3);
+
+// LED
 DigitalOut myled(LED1);
+
 Serial pc(USBTX, USBRX); // tx, rx Serial Output to PC Enabling this WILL consume resources. Use only for debug
 
 unsigned concatenate(unsigned x, unsigned y);
@@ -265,6 +298,8 @@
     pc.printf("RTC: PASS \n");
     pc.printf("Welcome to DSKY!\n");
     while (1) {
+        // Input side
+        // Keypad:
         __wfi();
         if (Index >-1) {
             pc.printf("Interrupted");
@@ -280,6 +315,21 @@
             }
             Index = -1;
         }
+        // Button:
+        if ((Button_Detect == 0) && (PRO_BUTT == 0)){
+            wait_ms(25);
+            pc.printf("Pro Button Pressed\n");
+        }
+        else if (CLR_BUTT == 0){
+            wait_ms(25);
+            pc.printf("Clr Button Pressed\n");
+        }
+        else if (KEYREL_BUTT == 0){
+            wait_ms(25);
+            pc.printf("Key Rel Button Pressed\n");
+        }
+        
+        myled = PRO_BUTT;
         // Debug use only
         //pc.printf("%c", Keytable[Verb_Number1]);
         //pc.printf("%c", Keytable[Verb_Number2]);
@@ -378,9 +428,9 @@
         Enter_Number2 = Index;
         Button_Sort(Enter_Number2);
     }
-    // This is for P01
+    // This is for P00
     else if(Noun_Number1 == 0 && Noun_Number2 == 0 && Verb_Number1 == 2 && Verb_Number2 == 8){ //N00V37
-        pc.printf("This is the P01\n");
+        pc.printf("This is the P00 program \n");
         pc.printf("Please enter a Enter Number\n");
         //Noun_Number1 = 0x0f;
         //Noun_Number2 = 0x0f;
@@ -494,24 +544,28 @@
 {
     if (Verb_Number1 == 0 && Verb_Number2 == 6 && Noun_Number1 == 2 && Noun_Number2 == 6 && Enter_Number1 == 0 && Enter_Number2 == 0) {// Verb 16, Noun 36, Enter 00
         // Configure GET
-        pc.printf("Display GET");
+        pc.printf("Display GET\n");
         Ground_Elapse_Time();
     } else if (Verb_Number1 == 2 && Verb_Number2 == 5 && Noun_Number1 == 0 && Noun_Number2 == 0 && Enter_Number1 == 0 && Enter_Number2 == 0) { // Verb 35 Noun 00 Enter 00
         // Test Lights
-        pc.printf("Testing Lights");
+        pc.printf("Testing Lights\n");
         Test_Lights();
     } else if (Verb_Number1 == 1 && Verb_Number2 == 5 && Noun_Number1 == 2 && Noun_Number2 == 6 && Enter_Number1 == 0 && Enter_Number2 == 0) { // Verb 25, Noun 36, Enter 00
         // GET COnfiguration
-        pc.printf("GET configuration");
+        pc.printf("GET configuration\n");
         GET_Config();
     } else if (Verb_Number1 == 2 && Verb_Number2 == 8 && Noun_Number1 == 0 && Noun_Number2 == 0 && Enter_Number1 == 0 && Enter_Number2 == 0) { // Verb 37, Noun 00, Enter 00
         // CMC Idling Program
-        pc.printf("CMC Idling Program");
+        pc.printf("CMC Idling Program\n");
         CMC_Idle();
     } else if (Verb_Number1 == 2 && Verb_Number2 == 8 && Noun_Number1 == 0 && Noun_Number2 == 0 && Enter_Number1 == 0 && Enter_Number2 == 1) { // Verb 37, Noun 00, Enter 01
-        pc.printf("Prelaunch or Service - Initialization Program");
+        pc.printf("Prelaunch or Service - Initialization Program\n");
         PreLaunch_Initialization();
-    } //else if (Verb_Number1 == 1 && Verb_Number2 == 0 && Noun_Number1 == 0 && Noun_Number2 == 0 && Enter_Number1 == 0 && Enter_Number2 == 0) { // Verb 21, Noun 00, Enter 00
+    } else if (Verb_Number1 == 2 && Verb_Number2 == 8 && Noun_Number1 == 0 && Noun_Number2 == 0 && Enter_Number1 == 0 && Enter_Number2 == 6) {
+        pc.printf("CMC Power Down Program\n");
+        CMC_Powerdown(); 
+    }
+    //else if (Verb_Number1 == 1 && Verb_Number2 == 0 && Noun_Number1 == 0 && Noun_Number2 == 0 && Enter_Number1 == 0 && Enter_Number2 == 0) { // Verb 21, Noun 00, Enter 00
     //    R1_Component();
     //}
      else {
@@ -789,6 +843,24 @@
             P_A = 0x0f;
             P_B = 0x0f;
             Shift();
+        case 8:
+            UPLINK_ACTY     = 0;
+            NO_ATT          = 0;
+            STBY            = 0;
+            KEY_REL         = 0;
+            OPP_ERR         = 0;
+            TEMP            = 0;
+            GIMBAL_LOCK     = 0;
+            PROG            = 0;
+            RESTART         = 0;
+            TRACKER         = 0;
+            R1_POS          = 0;
+            R2_POS          = 0;
+            R3_POS          = 0;
+            R1_NEG          = 0;
+            R2_NEG          = 0;
+            R3_NEG          = 0;
+            COMP_ACTY       = 0;
     }
 }
     
@@ -952,35 +1024,81 @@
     //pc.printf("%d\n", GET_Seconds);
     Ground_Elapse_Time();
  }
-
-// This is the CMC Idling Program Page CM-39
-// This portion of code just turns off all of the display. Originally used to save power consumption.
-// Process:
-// Display PROG 00
-// Verb 37 Enter 00
-// Verb 06 Noun  38
-// Optional Display:
-// Verb 06 Noun 38 - 
-//      Time of State Vector being Integrated
-//          00xxx   hours
-//          000xx   minutes
-//          0xx.xx  seconds
+ 
+/*
+This is the CMC Idling Program Page CM-39
+P00 - CMC IDLING PROGRAM
+Purpose:
+    1. To maintain the CMC in a condition of readiness for entry into other programs
+    2. To update the CSM and LM state vectors every four time steps.
+Assumptions:
+    1. This program is automatially selected by V96E, which may be done during any program.
+       State vector integration is permanently inhibited following V96E.
+       Normal integration functions will resume after selection of any program or extented verb.
+       P00 Integration will resume when P00 is reselected.
+       Usage of V96 can cause incorrect W-matrix and state vector synchronication.
+    2. Program changes are inhibited during integration periods and program alarm 1520sub(8) will occur if a chance is attempted when inhibited.
+Process:
+1. User Input Verb 37 Enter 00
+2. Display P00
+3. Verb 06 Noun  38
+4. Optional Display:
+5. Verb 06 Noun 38 - 
+6. Time of State Vector being Integrated
+        00xxx   hours
+        000xx   minutes
+        0xx.xx  seconds
+*/
 void CMC_Idle()
 {
+    int CMC_Idle = 0;
     NO_Light(7);
     P_A = 0x00;
     P_B = 0x00;
     Shift();
-    while(1) {
+    do {
         __wfi();
-        if (Index >-1) {
-            Interruption();
-            break;
-        }
-            
-    }
-    
-}
+        if (Index == 12) { // Index 12 = Verb Button
+            Verb_Button(); // Goes to Verb_Button
+        }// Index == 12
+        if (Index == 14) { // Index 14 = Noun Button
+            Noun_Button(); // Goes to Noun_Button
+        }// Index == 14
+        if (Index == 11) { // Index 11 = Enter Button
+            if (Verb_Number1 == 13 && Verb_Number2 == 6 && Noun_Number1 == 2 && Noun_Number2 == 9 && Enter_Number1 == 0 && Enter_Number2 == 0) { //V06N38E00
+                while(1) {
+                    // Time of State Vector Data.
+                    //  Time of State Hours
+                    R3_E = ToSHours%10;
+                    R3_D = (ToSHours/10)%10;
+                    R3_C = (ToSHours/100)%10;
+                    R3_B = (ToSHours/1000)%10;
+                    R3_A = (ToSHours/10000)%10;
+
+                    // Time of State Minutes
+                    R2_E = ToSMinutes%10;
+                    R2_D = (ToSMinutes/10)%10;
+                    R2_C = (ToSMinutes/100)%10;
+                    R2_B = (ToSMinutes/1000)%10;
+                    R2_A = (ToSMinutes/10000)%10;
+
+                    // Time of State Seconds
+                    R3_E = ToSSeconds%10;
+                    R3_D = (ToSSeconds/10)%10;
+                    R3_C = (ToSSeconds/100)%10;
+                    R3_B = (ToSSeconds/1000)%10;
+                    R3_A = (ToSSeconds/10000)%10;
+                    
+                    wait(1);
+                }
+            } else {
+                Enter_Button(); // Goes to Enter_Button
+            }// Else statement
+        }// Index == 11
+        Index = -1;
+    } while(CMC_Idle == 0);
+
+}// void CMC_Idle()
 
 /*
 P01 - Prelaunch or Service - Initialization Program CM-39
@@ -1124,6 +1242,80 @@
     } // While(1)
 } // PreLaunh_Gyrocompassing_Configure(); 
 
+/*
+P06 - CMC Power Down Program
+Purpose: 
+    1. To transfer the CMC from the operate to the standby position
+Assumptions:
+    1. If the computer power is switched off, the AGC Update program (P27) would have to be done to update the state vector and computer clock time.
+    2. The AGC is capable of maintaining an accurate value of ground elapsed time (GET) for only 23 hours when in the standby mode. 
+       If the AGC is not brought out of the standby position to the running condition atleast once within 23 hours, the AGC value of get must be updated.
+    3. Once the program has been selected, the AGC must be put in standby. When P06 appears, the AGC will not honor a new program request (V37EXXE), 
+       a terminate (V34E), or an ENTER in response to the request for standby.
+Sequence of Events:
+    1. User Input V37E06
+    2. Flashing V50N25 R3 = 00062
+    3. PRO until standby light on
+    4. PRO until standby light off
+    5. Flashing V37
+    6. User input 00E (Select P00)
+        6.A No ATT Light of 90 Seconds
+    7. Go to P00
+*/
+void CMC_Powerdown()
+{
+    // Process 2
+    P_A = 0x00;
+    P_B = 0x06;
+    R3_E = 0x00;
+    R3_D = 0x00;
+    R3_C = 0x00;
+    R3_B = 0x06;
+    R3_A = 0x02;
+    Shift(); 
+    while(1) {
+    // Process 2
+    CMC_PowerInput();
+    V_A = 0x05;
+    V_B = 0x00;
+    N_A = 0x02;
+    N_B = 0x05;
+    Shift();
+    CMC_PowerInput();
+    wait(.5);
+    CMC_PowerInput();
+    NO_Light(4);
+    NO_Light(5);
+    CMC_PowerInput();
+    wait(.5);
+    }// While 1
+}// CMC_Powerdown()
+
+void CMC_PowerInput()
+{
+    int PowerInput = 0;
+    if(PRO == 1) {
+        NO_Light(7);
+        NO_Light(8);
+        // Process 3
+        STBY = 1;
+        PRO = 0;
+        do {
+            if(PRO == 1) {
+                // Process 4
+                STBY = 0;
+                //N00V37
+                Noun_Number1 = 0; 
+                Noun_Number2 = 0; 
+                Verb_Number1 = 2;
+                Verb_Number2 = 8;
+                // Process 5-7
+                Enter_Button();
+                PowerInput = 1;
+            }// 2nd PRO For turning on.
+        }while (PowerInput == 0);// While 1
+    }//PRO == 1
+}
 
 // Load Component 1 into R1
 int R1_Component()