//------------------------------------------------------------------------------------ // 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); } }
static int lcd_init(void) { int err = 0; shortp_base = base; if (err = register_chrdev(major,"lcd",&lcd_fops)) printk("*** unable to get major LCD_MAJOR for Lcd devices ***\n"); PORT_INIT(); tme_tempo(10); printk(KERN_ALERT "lcd_couscous:lcd_init\n"); printk(KERN_ALERT "lcd_couscous:basePortAddress is 0x%lx\n", shortp_base); return err; }
int main(void) { int value; uint8_t on_off; ADC_INIT(0); PORT_INIT(); while(1) { value = read_ADC() >> 7; on_off = 0; for(int i = 0; i <= value; i++){ on_off |= (0x01 << i); } PORTD = on_off; } }
//------------------------------------------------------------------------------------------- // 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); } } }
int main() { characters_init(); PORT_INIT(); LCD_INIT(); init_key(); //设定mah 2580 为3000mah 4b00 为6000 /*while(!ds_reset()); ds_write_byte(CMD_ONEWIRE_SKIP_ROM); ds_write_byte(CMD_ONEWIRE_WRITE); ds_write_byte(CMD_ADDR_ACR); ds_write_byte(0X4b); ds_write_byte(0X00);*/ int count = 5; char key; while(1) { key = get_key(); //switch mode and in edit edit. if(key==1) { //in mode 1 go to next cursor if(yes&&mode==1) { //go back to the begining of the line if(pos_mode1==4){LCD_WR_COM(0X02);} else { //cursor to the next LCD_WR_COM(0X14); } //the position of mode1 add pos_mode1 = (pos_mode1+1)%5; } else if(yes&&mode==2) { //go to the begining of the first line if(pos_mode2==4){LCD_WR_COM(0X02);} else { LCD_WR_COM(0x14); } pos_mode2 = (pos_mode2+1)%5; } else { switch_mode(1); mode = (mode+1)%3; } } if(key==3) { yes = ~yes; switch_mode(3); } if(key==2) { if(mode==1&&yes) { res[pos_mode1]=(res[pos_mode1]+1-'0')%10+'0'; LCD_WR_COM(0X80+pos_mode1); LCD_WR_DATA(res[pos_mode1]); LCD_WR_COM(0X10); } if(mode==2&&yes) { fullc[pos_mode2] = (fullc[pos_mode2]+1-'0')%10+'0'; LCD_WR_COM(0x80+pos_mode2); LCD_WR_DATA(fullc[pos_mode2]); LCD_WR_COM(0X10); } } if(mode==0) { if(count==0) { count=4; LCD_CLEAR(); } count--; } update(); mode_pro(); _delay_ms(50); } }
//------------------------------------------------------------------------------------ // MAIN Routine //------------------------------------------------------------------------------------ void main(void) { char input; char SFRPAGE_SAVE = SFRPAGE; WDTCN = 0xDE; // Disable the watchdog timer WDTCN = 0xAD; // Note: = "DEAD"! SYSCLK_INIT(); // Initialize the oscillator Timer_Init(); // Initialize timer UART_INIT(); // Initialize UARTs PORT_INIT(); // Initialize the Crossbar and GPIO SPI_Init(); SFRPAGE = UART0_PAGE; // Direct output to UART0 printf("\033[2J"); //clear screen printf("\033[2J"); //clear screen printf("\033[13;0H"); //print divider printf("--------------------------------------------------------------------------------"); //printf("\033[1;12r"); //define scrollable area //printf("\033[14;25r"); while(1) { if (RI0 == 1) { RI0 = 0; input = SBUF0; // If input from UART0, read SBUF0 if (input == 0x7F){ sendChars(); } else{ if (input == 'a') //228 { printf("i am a\n\r"); SPI0CKR += 5; printf("clock: %d\n\r", SPI0CKR); } else if (input == 'z') { SPI0CKR -= 5; printf("clock: %d\n\r", SPI0CKR); } //SFRPAGE_SAVE = SFRPAGE; //SFRPAGE = SPI0_PAGE; NSSMD0 = 0; //slave select SPIF = 0; //clear SPIF SPI0DAT = input; //send input while (!SPIF); //wait until sent NSSMD0 = 1; //release slave writeTop(input); //write to UART0 RI0 = 0; //Clear input flag overflows = 0; //wait while(overflows < 30000); NSSMD0 = 0; //slave select while (!SPIF); //wait until not busy SPIF = 0; //busy SPI0DAT = input; //write dummy character while (!SPIF); //wait until transfer is over NSSMD0 = 1; //release slave input = SPI0DAT; //read SPI0DAT writeBot(input); //SFRPAGE = SFRPAGE_SAVE; } } } }
//------------------------------------------------------------------------------------ // MAIN Routine //------------------------------------------------------------------------------------ void main(void) { unsigned char adcValH[3]; unsigned char adcValL[3]; unsigned int result; unsigned short int analogval; unsigned char analoghi, analoglow; float VREF = 3; WDTCN = 0xDE; // Disable the watchdog timer WDTCN = 0xAD; PORT_INIT(); // Initialize the Crossbar and GPIO SYSCLK_INIT(); // Initialize the oscillator ADC_INIT(); // Initialize ADC0 DAC_INIT(); MAC_INIT(); adcValH[2] = adcValH[1] = adcValL[2] = adcValL[1] = 0; result = 0; while(1) { 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 analogval = analoghi<<8 | analoglow; // Update the variables in the filter equation adcValH[2] = adcValH[1]; // x(k-2) high byte adcValH[1] = adcValH[0]; // x(k-1) high byte adcValL[2] = adcValL[1]; // x(k-2) low byte adcValL[1] = adcValL[0]; // x(k-1) low byte adcValH[0] = analoghi; // x(k) high and low bytes adcValL[0] = analoglow; SFRPAGE = MAC0_PAGE; MAC0CF |= 0x08; // Clear MAC // Load the MAC with the correct values and compute the filter equation MAC0AH = 0x28; MAC0AL = 0x00; MAC0BH = adcValH[0]; MAC0BL = adcValL[0]; MAC0BH = adcValH[2]; MAC0BL = adcValL[2]; MAC0AH = 0x1E; MAC0AL = 0xC4; MAC0BH = adcValH[1]; MAC0BL = adcValL[1]; MAC0AH = 0x26; MAC0AL = 0x00; SFRPAGE = MAC0_PAGE; // Delay with any dummy command result = (int)MAC0RNDH<<8 | MAC0RNDL; // Read the result from the rounding engine SFRPAGE = DAC0_PAGE; // Output the result through the DAC DAC0L = result; DAC0H = result>>8; } }
//------------------------------------------------------------------------------------ // 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); }