//------------------------------------------------------------------------------------ // MAIN Routine //------------------------------------------------------------------------------------ void main(void) { char high=0; char low = 0; WDTCN = 0xDE; // Disable the watchdog timer WDTCN = 0xAD; // Note: = "DEAD"! SYSCLK_INIT(); // Initialize the oscillator PORT_INIT(); // Initialize the Crossbar and GPIO UART0_INIT(); // Initialize UART0 ADC_Init(); // Initialize ADC0 DAC_Init(); SFRPAGE = UART0_PAGE; // Direct output to UART0 //initialize ADC converter //select 00 on AD0CM mux ADC0CN &= ~0x0C; //clear AD0INT AD0INT = 0; //AD0BUSY = 1 to start conversion AD0BUSY = 1; //while AD0INT != 0 while(AD0INT != 0); printf("\033[2J"); //clear screen printf("Fire and blood. \n\r"); //running while(1) { //clear AD0INT AD0INT = 0; //AD0BUSY = 1 to start conversion AD0BUSY = 1; //while AD0INT != 0 while(AD0INT == 0); AD0BUSY = 0; //read A/D conversion value from ADC0H/L high = ADC0H; low = ADC0L; DAC0L = low; DAC0H = high; //printf("ADCH: %x ADCL: %x DACH: %x DACL: %x\n\r", high, low, DAC0H, DAC0L); } }
//------------------------------------------------------------------------------------ // MAIN Routine //------------------------------------------------------------------------------------ void main(void) { unsigned short int analogval; unsigned char *analoghi, *analoglow; float VREF = 3; //Voltage reference float result; // ADC voltage result short int result_high = 0; short int result_low = 4095; char samples = 0; short int accum[16] = {0}; // Still compute the average char i; unsigned long int sum = 0; unsigned int avg; float result_dec1; // Need 2 variables to hold the decimal value to prevent overflow float result_dec2; analoglow = (char *) &analogval; analoghi = analoglow + 1; WDTCN = 0xDE; // Disable the watchdog timer WDTCN = 0xAD; PORT_INIT(); // Initialize the Crossbar and GPIO SYSCLK_INIT(); // Initialize the oscillator UART0_INIT(); // Initialize UART0 ADC_INIT(); // Initialize ADC0 INTERRUPT_INIT(); DAC_INIT(); while(1) { //dig_val = dig_val + 50; // Generate the sawtooth SFRPAGE = ADC0_PAGE; AD0INT = 0; // Clear the "conversion done" flag AD0BUSY = 1; // Start A/D Conversion while (AD0INT == 0); // Wait for the conversion to finish *analoglow = ADC0L; // Read the low byte *analoghi = ADC0H; // Read the high byte SFRPAGE = DAC0_PAGE; // Output the digital value through the DAC DAC0L = analogval << 0; //digval; DAC0H = analogval >> 8; //digval >> 8; SFRPAGE = UART0_PAGE; //result = analogval*2.4/(float)4095; // Compute the average //result_dec1 = (1000*result-1000*(int)result); //result_dec2 = (1000*(result_dec1-(int)result_dec1)); // Erase screen and move cursor to home position //printf("Voltage reading: %d.%03d%03d\n\r", (int)result, (int)result_dec1, (int)result_dec2); } }
//FIRST DIES AT 5000 Hz //------------------------------------------------------------------------------------ // MAIN Routine //------------------------------------------------------------------------------------ void main(void) { char high=0; char low = 0; WDTCN = 0xDE; // Disable the watchdog timer WDTCN = 0xAD; // Note: = "DEAD"! SYSCLK_INIT(); // Initialize the oscillator PORT_INIT(); // Initialize the Crossbar and GPIO UART0_INIT(); // Initialize UART0 ADC_Init(); // Initialize ADC0 DAC_Init(); // Initialize DAC0 MAC_Init(); // Initialize MAC0 SFRPAGE = UART0_PAGE; // Direct output to UART0 //initialize ADC converter //select 00 on AD0CM mux ADC0CN &= ~0x0C; //clear AD0INT AD0INT = 0; //AD0BUSY = 1 to start conversion AD0BUSY = 1; //while AD0INT != 0 while(AD0INT != 0); printf("\033[2J"); //clear screen printf("We will not sow. \n\r"); //running while(1) { //printf("Still running. \n\r"); olderIn = oldIn; oldIn = input; input = do_ADC(); oldOut = output; output = do_MAC(); do_DAC(); // printf("I: %d I1: %d I2: %d O: %d O2: %d \n\r", input, oldIn, olderIn, output, oldOut); } }
//------------------------------------------------------------------------------------------- // MAIN Routine //------------------------------------------------------------------------------------------- void main (void) { bit restart = 0; unsigned int randnum = 0; WDTCN = 0xDE; // Disable the watchdog timer WDTCN = 0xAD; // Note: = "DEAD"! SYSCLK_INIT(); // Initialize the oscillator. PORT_INIT(); // Configure the Crossbar and GPIO. UART0_INIT(); // Initialize UART0. INTERRUPT_INIT(); // Initialize Interrupts TIMER_INIT(); SFRPAGE = LEGACY_PAGE; IT0 = 1; // /INT0 is edge triggered, falling-edge. SFRPAGE = UART0_PAGE; // Direct output to UART0 printf("\033[2J"); // Erase screen and move cursor to the home posiiton. printf("MPS Interrupt Switch Test\n\n\r"); printf("Ground /INT0 on P0.2 to generate an interrupt.\n\n\r"); SFRPAGE = CONFIG_PAGE; EX0 = 1; // Enable Ext Int 0 only after everything is settled. SFRPAGE = UART0_PAGE; while (1) { if (count > 340) { count = 0; sec_elapsed++; printf("Seconds Elapsed: %d\r\n", sec_elapsed); } if(pbFlag){ // If interrupt flag is set to 1 printf("PB Pressed!\r\n"); pbFlag = 0; } } }
//------------------------------------------------------------------------------------------- // MAIN Routine //------------------------------------------------------------------------------------------- void main (void) { bit restart = 0; unsigned int randnum = 0; WDTCN = 0xDE; // Disable the watchdog timer WDTCN = 0xAD; // Note: = "DEAD"! SYSCLK_INIT(); // Initialize the oscillator. PORT_INIT(); // Configure the Crossbar and GPIO. UART0_INIT(); // Initialize UART0. SFRPAGE = LEGACY_PAGE; IT0 = 1; // /INT0 is edge triggered, falling-edge. SFRPAGE = CONFIG_PAGE; EX0 = 1; // Enable Ext Int 0 only after everything is settled. SFRPAGE = UART0_PAGE; // Direct output to UART0 printf("\033[2J"); // Erase screen and move cursor to the home posiiton. Timer2_Init(); TR2 = 1; //enable timer2 printf("I am running :D \n\r"); while (1) { if (printTime) //if 1 second, print. { printf("Time = %d\n\r", time); printTime = 0; } } }
//------------------------------------------------------------------------------------------- // MAIN Routine //------------------------------------------------------------------------------------------- void main (void) { bit restart = 0; unsigned int randnum = 0; WDTCN = 0xDE; // Disable the watchdog timer WDTCN = 0xAD; // Note: = "DEAD"! SYSCLK_INIT(); // Initialize the oscillator. PORT_INIT(); // Configure the Crossbar and GPIO. UART0_INIT(); // Initialize UART0. SFRPAGE = LEGACY_PAGE; IT0 = 1; // /INT0 is edge triggered, falling-edge. IT1 = 1; // INT1 falling-edge-triggered SFRPAGE = CONFIG_PAGE; EX0 = 1; // Enable Ext Int 0 only after everything is settled. EX1 = 1; // Enable External Interrupt 2 SFRPAGE = UART0_PAGE; // Direct output to UART0 printf("\033[2J"); // Erase screen and move cursor to the home posiiton. Timer0_Init(); //enable timer0 TR0 = 1; Timer2_Init(); TR2 = 1; //enable timer2 // printf("I am running :D \n\r"); while (1) playGame(); }
//------------------------------------------------------------------------------------------- // MAIN Routine //------------------------------------------------------------------------------------------- void main (void) { __bit restart = 0; char character; unsigned int delay1, delay2 = 0; unsigned int randnum = 0; unsigned int ones, tenths = 0; unsigned char tenths_seconds = 0; unsigned int seconds = 0; unsigned int delay; unsigned int times[5]; unsigned int time; unsigned char started = 0; unsigned int avg; char i; char grace; SFRPAGE = CONFIG_PAGE; PORT_INIT(); // Configure the Crossbar and GPIO. SYSCLK_INIT(); // Initialize the oscillator. UART0_INIT(); // Initialize UART0. SFRPAGE = LEGACY_PAGE; IT0 = 1; // /INT0 is edge triggered, falling-edge. SFRPAGE = CONFIG_PAGE; EX0 = 1; // Enable Ext Int 0 only after everything is settled SFRPAGE = UART0_PAGE; // Direct output to UART0 printf("\033[2J"); // Erase screen and move cursor to the home posiiton. printf("MPS Timer Game\n\n\r"); printf("Press button 8 ASAP on GO.\n\n\r"); SFRPAGE = UART0_PAGE; delay = rand() % 50 + 10; while (1) { if (interrupt_count == 404) { // Count each .1 seconds tenths_seconds = tenths_seconds + 1; interrupt_count = 0; if (tenths_seconds % 10 == 0 && tenths_seconds != 0) { tenths_seconds = 0; seconds = seconds + 1; if(seconds < 1 && !started) // Don't count quick double presses before the start of the next trial grace = 1; else grace = 0; } } if(seconds >= delay/10 && tenths_seconds >= delay-delay/10*10 && !started) // Flash GO and restart the timer { seconds = 0; tenths_seconds = 0; started = 1; printf("\033[16;26HGO"); printf("\033[5;0H"); } if(press > 0 && !grace) // The user has pressed the button { printf("\033[16;26H "); delay = rand() % 50 + 10; // Gererate a new random delay between 1 and 5 seconds. press = 0; // Reset interrupt variable if(started == 1) { time = seconds*10 + tenths_seconds; // Reaction time for this trial } else { time = 50; // False button press (GO not flashed on screen). Penalize 5 seconds } seconds = 0; tenths_seconds = 0; started = 0; // Shift 5 most recent times times[0] = times[1]; times[1] = times[2]; times[2] = times[3]; times[3] = times[4]; times[4] = time; avg = (times[0] + times[1] + times[2] + times[3] + times[4])/5; // Calculate running average of 5 printf("\033[6;0H"); //Move cursor position for (i = 0; i <= 4; i++) { printf("Trial %d: %d.%d seconds\r\n", (5-i), times[i]/10, times[i]-times[i]/10*10); } printf("Avg: %d.%d seconds", avg/10, avg-avg/10*10); } } }
//------------------------------------------------------------------------------------ // MAIN Routine //------------------------------------------------------------------------------------ void main(void) { char choice; char choice2; int printOnThisLine = 11; WDTCN = 0xDE; // Disable the watchdog timer WDTCN = 0xAD; // Note: = "DEAD"! SYSCLK_INIT(); // Initialize the oscillator PORT_INIT(); // Initialize the Crossbar and GPIO UART0_INIT(); // Initialize UART0 SFRPAGE = UART0_PAGE; // Direct output to UART0 printf("\033[2J"); // Erase ANSI terminal & move cursor to home position printf("\033[33m\033[1B\033[21C"); // makes text yellow, pushes cursor down a line //print the program info printf("Returns input char. To exit hit ESC.\n\n\r"); //define scrollable area printf("\033[12;24r"); while(1) { choice=getchar(); if (choice >= 32 && choice <= 126) { //reset attributes printf("\033[0m"); //reapply attributes printf("\033[44;33m"); //put cursor over line 6 printf("\033[6;0H"); //print printf("\n\rThe keyboard character is \033[37m%c\033[33m.\n\r", choice); } else { if(choice ==27){ //exitprogram printf("\033[m"); printf("\033[24;0H"); printf("\033[44;33m"); printf("Program exit \n\r"); return; } //check which line we want to print to if(printOnThisLine == 24) { //scroll up printf("\033[m"); //setbackground color printf("\033[44;33m"); } else { printOnThisLine++; } //go to scrollable area printf("\033[%d;0H", printOnThisLine); //enable blinking text printf("\033[5m"); //print printf("The character $%X is '\033[4mnot printable'\033[0m\033[5;44;33m.\n\r", choice); //beep putchar(7); } } }
//------------------------------------------------------------------------------------ // MAIN Routine //------------------------------------------------------------------------------------ void main(void) { unsigned int i; volatile __xdata unsigned char *ext_ram; volatile __xdata unsigned char *ext_ram2; unsigned static int __xdata failure[512]; unsigned int count; ext_ram = (__xdata unsigned char *)(0x1FF0); ext_ram2 = (__xdata unsigned char *)(0x2800); SYSCLK_INIT(); // Initialize the oscillator PORT_INIT(); // Initialize the Crossbar and GPIO UART0_INIT(); // Initialize UART0 SFRPAGE = UART0_PAGE; // Direct output to UART0 printf("\033[2J"); // Erase ANSI terminal & move cursor to home position printf("Memory test\n\n\r"); count = 0; for(i=0; i<2064; i++) { ext_ram[i] = 0xAA; } for(i=0; i<2064; i++) { printf("%2X", ext_ram[i]); if(ext_ram[i] != 0xAA) { failure[count] = i+8176; count++; if(count == 512) { for(count=0; count<512; count++) { if(failure[count] != 0) printf("%4X\r\n", failure[count]); } count = 0; } } } for(i=0; i<2048; i++) { ext_ram2[i] = 0xAA; } for(i=0; i<2048; i++) { printf("%2X", ext_ram2[i]); if(ext_ram2[i] != 0xAA) { failure[count] = i+10240; count++; if(count == 512) { for(count=0; count<512; count++) { if(failure[count] != 0) printf("%4X\r\n", failure[count]); } count = 0; } } } for(i=0; i<2048; i++) { ext_ram2[i] = 0x55; } for(i=0; i<2048; i++) { printf("%2X", ext_ram2[i]); if(ext_ram2[i] != 0x55) { failure[count] = i+10240; count++; if(count == 512) { for(count=0; count<512; count++) { if(failure[count] != 0) printf("%4X\r\n", failure[count]); } count = 0; } } } for(count=0; count<512; count++) { if(failure[count] != 0) printf("%4X\r\n", failure[count]); } printf("Memory Test Completed"); while(1); }