int main() { uint32_t *fbase, *imageaddr, *graybuffer; uint32_t i, j, k; float time, fps; clock_t t1, t2; cp_en(); /* Enable the coprocessor */ fbase = svga_enable(); /* Configure and enable the svga controller */ imageaddr = (uint32_t*)STARTADDR; /* Set the address of the first image */ t1 = clock(); /* Get the start time */ for (i = 0; i < NFRAMES-1; i++) { switch(MODE) { default: case 1: /* Copy images to framebuffer */ mode1(fbase, imageaddr); break; case 2: /* Floating point grayscale conversion in software */ mode2(fbase, imageaddr); break; /* Add more cases for new modes */ case 3: /* Fixed point grayscale conversion in software */ mode3(fbase, imageaddr); break; case 4: /* Mode to use the fixed point grayscale coprocessor */ mode4(fbase, imageaddr); break; case 5: /* Mode to do the Laplacian edge detection in software */ mode5(fbase, imageaddr); break; case 6: mode6(fbase, imageaddr); // case 7: /* "Hack" the screen! */ // hackmode(fbase, imageaddr); // break; } imageaddr += f->hactive_video*f->vactive_video/2; /* Move to the next image */ } /* Report the time to process the frames */ t2 = clock(); time = (t2 - t1) / CLOCKS_PER_SEC; fps = NFRAMES / time; printf("FPS: %f\n", fps); t1 = t2; return 0; }
int main(void) { SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); //Configure System Clock //SSD SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); //Enable Port D SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); //Enable Port B GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE,0x0F); GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE,0xFF); //S1 and S2 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //Enable Port F //Mode 1 SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); //Enable ADC0 Module SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); //Enable Port E GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1); //Select ADC Function of PE 1 ADCSequenceConfigure(ADC0_BASE, 2, ADC_TRIGGER_PROCESSOR, 0); //Configure ADC0 Sequencer ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_CH2 | ADC_CTL_IE | ADC_CTL_END); //Configure the step of the sequencer //Mode 2 SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); //Enable TIMER1 Module GPIOPinTypeGPIOInput(GPIO_PORTF_BASE,GPIO_PIN_4); //Set PF4 as Input GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU); //Configuring the PF4 GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_BOTH_EDGES); //Setting Interrupt to trigger on both edges TimerConfigure(TIMER1_BASE,TIMER_CFG_PERIODIC); //Configure TIMER1 into a Continuous Mode TimerIntRegister(TIMER1_BASE, TIMER_A, fast); //Register interrupt if PF4 pressed for more than 1s //Mode 3 SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER4); //Enable TIMER4 Module SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER0); //Enable WTIMER0 Module SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); //Enable Port C GPIOPinConfigure(GPIO_PC4_WT0CCP0); GPIOPinTypeTimer(GPIO_PORTC_BASE,GPIO_PIN_4); //Set PC4 as a Timer Capture pin TimerIntRegister(TIMER4_BASE,TIMER_A,freqfind); //Register a timer interrupt for TIMER4 TimerConfigure(TIMER4_BASE,TIMER_CFG_PERIODIC); //Configure Timer4 in continuous mode TimerConfigure(WTIMER0_BASE,TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_CAP_COUNT); TimerControlEvent(WTIMER0_BASE,TIMER_A,TIMER_EVENT_POS_EDGE); //Configure WTIMER0 for Positive Edge Capture IntMasterEnable(); GPIOPinWrite(GPIO_PORTB_BASE,0xFF,0x00); //Initialize SSD to 0x00 GPIOPinWrite(GPIO_PORTD_BASE, 0x0F, 0x00); //Turn off all the digits of the SSD SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); //Enable TIMER0 Module TimerConfigure(TIMER0_BASE,TIMER_CFG_PERIODIC); //Configure TIMER0 into a Continuous Mode TimerIntRegister(TIMER0_BASE, TIMER_A, ssdmux); //Register ISR for TIMER0 Interrupt to update SSD TimerLoadSet(TIMER0_BASE, TIMER_A,SysCtlClockGet()/3000); //Set the refresh rate of the SSD IntEnable(INT_TIMER0A); TimerIntEnable(TIMER0_BASE,TIMER_TIMA_TIMEOUT); //Enable the timer interrupt TimerEnable(TIMER0_BASE,TIMER_A); //Start the timer HWREG(GPIO_PORTF_BASE|GPIO_O_LOCK) = GPIO_LOCK_KEY; HWREG(GPIO_PORTF_BASE|GPIO_O_CR) = GPIO_PIN_0; //Unlock PF0 from the NMI mode HWREG(GPIO_PORTF_BASE|GPIO_O_LOCK) = 0; ssdset(0); mode1set(); GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0); //Setting PF0 to Input GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU); //Configuring the pins GPIOIntRegister(GPIO_PORTF_BASE, modeselect); //Register Interrupt for Port F with ISR modeselect() GPIOIntClear(GPIO_PORTF_BASE, GPIO_PIN_0); //Clear any existing interrupts GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_FALLING_EDGE); //Setting Interrupt to trigger on falling edges GPIOIntEnable(GPIO_PORTF_BASE, GPIO_PIN_0); //Enable the GPIO Interrupts on Port F IntEnable(INT_GPIOF); //Enable Interrupts on Port F while(1){ switch(mode) //Select operation according to mode { case 1: mode1(); break; case 2: ssdsetHex(hex_count); if(fast_flag) { mode2(); SysCtlDelay(SysCtlClockGet()/300); } break; case 3: mode3(); break; case 4: mode1(); break; case 5: ssdsetHex(hex_count); if(fast_flag) { mode2(); SysCtlDelay(SysCtlClockGet()/300); } break; } SysCtlDelay(SysCtlClockGet()/3000); } return 0; }
int main(void) { // init hardware setup init(); // setup temperature resolution // write temperature register pointer i2c_start(TEMPSENS_ADDRESS, I2C_WRITE); i2c_write(0x01); i2c_write(0b01100000); i2c_stop(); while(1) { // change mode by pressed button if (button1Pressed()) { mode = MODE_1; } else if (button2Pressed()) { mode = MODE_2; } else if (button3Pressed()) { mode = MODE_3; } // mode1 if (mode == MODE_1) { // read analog value from potentiometer uint32_t pot = readAnalog(POT_CHANNEL); pot *= 4888; pot += 500; pot /= 1000; if (++mydelay >= 10) { writeDisplayNumber(pot, 0); mydelay = 0; } // led1 on sbit(OUTPORT(LED1_PORT), LED1_BIT); } else { // led1 off cbit(OUTPORT(LED1_PORT), LED1_BIT); } // mode2 if (mode == MODE_2) { int16_t temp = readTemperature(); writeDisplayTemp(temp, 2); // led2 on sbit(OUTPORT(LED2_PORT), LED2_BIT); } else { // led2 off cbit(OUTPORT(LED2_PORT), LED2_BIT); } // show potentiometer value if (mode == MODE_3) { // led3 on sbit(OUTPORT(LED3_PORT), LED3_BIT); mode3(); /* if (mydelay < 12) { // turn-on buzzer // frequency 2kHz ICR1 = 2000; OCR1A = 1000; // write to display writeDisplayData(convertBcd(DIGIT_MINUS, DIGIT_MINUS, DIGIT_BLANK, DIGIT_BLANK, 255)); } else { // turn-on buzzer // frequency 2kHz ICR1 = 4000; OCR1A = 2000; // write to display writeDisplayData(convertBcd(DIGIT_BLANK, DIGIT_BLANK, DIGIT_MINUS, DIGIT_MINUS, 255)); } if (++mydelay >= 25) mydelay = 0; */ } else { // turn-off buzzer ICR1 = 0; // led3 off cbit(OUTPORT(LED3_PORT), LED3_BIT); } // wait until all mode buttons are released while (button1Pressed() || button2Pressed() || button3Pressed()); _delay_ms(20); } }
/* Mode 5 - Laplacian edge detection in software */ inline void mode5(uint32_t *fbase, uint32_t *imageaddr) { uint32_t x, y; /* Y = 0.299*R + 0.587*G + 0.114*B */ /* 640x480 resolution, 16-bit pixels in 5-6-5 format */ /* hactive_video = 640, vactive_video = 480 */ // Temporary pixels to use for Laplacian kernel int32_t ul, uc, ur, cl, c, cr, ll, lc, lr, tmp; // Test to see if assumption on array index is correct. uint16_t (*fbase2d)[f->hactive_video] = (uint16_t (*)[f->hactive_video])&fbase[0]; uint32_t *grayscale_img = (uint32_t *)malloc(f->hactive_video*f->vactive_video*2); uint16_t (*grayscale_img2d)[f->hactive_video]= (uint16_t (*)[f->hactive_video])&grayscale_img[0]; if(grayscale_img == 0) { printf("ERROR: Out of memory!\n"); } if(imageaddr == 0x41e4c000) { for (x = 0; x < f->hactive_video*f->vactive_video/2; x++) { fbase[x] = imageaddr[x]; } } else { // Used the fixed point software grayscale mode to get a grayscale image mode3(grayscale_img, imageaddr); for(y = 1; y < (f->vactive_video - 1); y++) { for(x = 1; x < (f->hactive_video - 1); x++) { // Edge case to load initial pixels if(x == 1) { ul = grayscale_img2d[y-1][0]; uc = grayscale_img2d[y-1][1]; cl = grayscale_img2d[y][0]; c = grayscale_img2d[y][1]; ll = grayscale_img2d[y+1][0]; lc = grayscale_img2d[y+1][1]; } ur = grayscale_img2d[y-1][x+1]; cr = grayscale_img2d[y][x+1]; lr = grayscale_img2d[y+1][x+1]; tmp = ((8*c) - ul - uc - ur - cl - cr - ll - lc - lr); if(tmp < 0) { fbase2d[y][x] = 0; } else if(tmp > 65535) { fbase2d[y][x] = 0xFFFF; } else { fbase2d[y][x] = tmp & 0xFFFF; } ul = uc; uc = ur; cl = c; c = cr; ll = lc; lc = lr; } } } // Free the memory we used for the temporary image free(grayscale_img); }
void main() { OLED_Init(); //初始化oled qd=1; ftm_pwm_init(FTM0,FTM_CH3,10000,0); ftm_pwm_init(FTM0,FTM_CH4,10000,0); ftm_pwm_init(FTM2,FTM_CH0,10000,0); ftm_pwm_init(FTM2,FTM_CH1,10000,0); adc_init (ADC1_SE10); adc_init (ADC1_SE11); adc_init (ADC1_SE12); adc_init (ADC1_SE13); //按键初始化 gpio_init (PTA13, GPI,HIGH);//拨码开关初始化 gpio_init (PTA19, GPI,HIGH); gpio_init (PTA24, GPI,HIGH); gpio_init (PTA25, GPI,HIGH); gpio_init (PTA26, GPI,HIGH); gpio_init (PTA27, GPI,HIGH); gpio_init (PTA28, GPI,HIGH); gpio_init (PTA29, GPI,HIGH); led_init (LED0); mpu6050_init(); lptmr_delay_ms(1000); gyro_zero=ad_ave(100); gyro_zero1=ad_ave1(100); mpu6050_read(); accel_accel=(accel_x-accel_zero)/16384.0; if(accel_accel>1) accel_accel=1; if(accel_accel<-1) accel_accel=-1; angle_fuse=180/pi*(asin(accel_accel)); accel_accel1=(accel_y-accel_zero1)/16384.0; if(accel_accel1>1) accel_accel1=1; if(accel_accel1<-1) accel_accel1=-1; angle_fuse1=180/3.1415926*(asin(accel_accel1)); pit_init_ms(PIT0, 5); //初始化PIT0,定时时间为: 5ms set_vector_handler(PIT0_VECTORn ,PIT0_IRQHandler); //设置PIT0的中断服务函数为 PIT0_IRQHandler enable_irq (PIT0_IRQn); //使能PIT0中断 uart_init(UART3, 115200); while(aa<200); //初始化 1秒 DIP_switch(); while(1) { //display[0]=angle_fuse; //display[1]=angle_fuse1; display[0]=angle_fuse3; oledplay(); if(flag==1) mode1(); else if (flag==2) mode2(); else if (flag==3) mode3(); else if (flag==4) mode4(); vcan_sendware((unsigned char *)display, 20); } }