//------------------------------------------------------------------------------------ // 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); } }
//------------------------------------------------------------------------------------------- // 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; } } }