Exemplo n.º 1
0
int main(void)
{
    Set_System();
    SysTick_Config(SystemCoreClock/10000);
    Set_USBClock();
    USB_Interrupts_Config();
    USB_Init();

    lcdInit();

    volatile int x;
    while (1)
    {
        lcdSetBklight(sysTicks%10000/100);
        x++;
    }
}
Exemplo n.º 2
0
/*
*	Function: ioBoardLcdTest
* Description: be used to test Lcd interface on the board
*/
void ioBoardLcdTest(int bits, int rows, int cols)
{
    int lcdHandle;
    lcdHandle = lcdInit (rows, cols, 8, 21, 23, 0, 1, 2, 3, 4, 5, 6, 7) ;
    if(lcdHandle < 0)
    {
        printf("Lcd init failed!\n");
        return;
    }

    printf("LCD: the LCD will display character, please view!\n");

    lcdPosition (lcdHandle, 0, 0) ;
    lcdPuts (lcdHandle, "Lcd Test OK") ;
    lcdPosition (lcdHandle, 0, 1) ;
    lcdPuts (lcdHandle, "www.lemaker.org") ;
}
Exemplo n.º 3
0
Arquivo: ifs.c Projeto: elseym/kitpi
int main(void) {
	char buf[1024];
	int i;

	int sck = socket(AF_INET, SOCK_DGRAM, 0);
	if(sck < 0) {
		perror("socket");
		return 1;
	}

	struct ifconf ifc;
	ifc.ifc_len = sizeof(buf);
	ifc.ifc_buf = buf;
	if(ioctl(sck, SIOCGIFCONF, &ifc) < 0) {
		perror("ioctl(SIOCGIFCONF)");
		return 1;
	}

	if (wiringPiSetup() == -1) {
		printf("wiringPiSetup failed!\nexiting.\n");
		return 1;
	}

	int lcd = lcdInit(2, 16, 4, 15, 16, 7, 0, 2, 3, 0, 0, 0, 0);
	delay(5);
	if (lcd == -1) {
		printf("lcdinit failed!\nexiting.\n");
		return 2;
	}

	lcdClear(lcd);
	delay(2);

	struct ifreq *ifr = ifc.ifc_req;
	int nInterfaces = ifc.ifc_len / sizeof(struct ifreq), y = 0;
	for(i = 0; i < nInterfaces; i++) {
		struct ifreq *item = &ifr[i];
		if (strcmp(item->ifr_name, "lo") == 0) continue;
		lcdPosition(lcd, 0, y++);
		delay(2);
		lcdPrintf(lcd, "%s: %s", item->ifr_name, inet_ntoa(((struct sockaddr_in *)&item->ifr_addr)->sin_addr));
		delay(5);
	}

  return 0;
}
Exemplo n.º 4
0
/**********MAIN ROUTINE*************/
int main(int argc, char** argv) {
    //char i = '0';
    config_init();
    lcdInit();
    lcdWriteStrC("Counting test: ");
    while (1) {
        /*
        lcdSetPos(0,1);
        lcdWriteChar(i++);
        if(i > '9') i = '0';
        for(int j = 0; j < 10; j++) __delay_ms(50);
         */
        menu = read_button(); // wait for any changes in buttons
        menu_update(menu);
    }

    return (EXIT_SUCCESS);
}
Exemplo n.º 5
0
void CLCD::init(const char * fontfile, const char * fontname,
                const char * fontfile2, const char * fontname2,
                const char * fontfile3, const char * fontname3)
{
	InitNewClock();

	if (!lcdInit(fontfile, fontname, fontfile2, fontname2, fontfile3, fontname3 ))
	{
		printf("[lcdd] LCD-Init failed!\n");
		return;
	}

	if (pthread_create (&thrTime, NULL, TimeThread, NULL) != 0 )
	{
		perror("[lcdd]: pthread_create(TimeThread)");
		return ;
	}
}
Exemplo n.º 6
0
void main (void)
{
	lcdInit();							// Clear Screen, Display ON, Cursor ON, Blinking ON
										// Use 8-bit, 2 Lines, Font 5x7

	lcdSetInput(LCD_MODE_INPUT_INC		 |
				LCD_MODE_INPUT_SHIFT_OFF);
	
	for (;;)
	{
		lcdClearRow(0);
		delay(30000);

		lcdWriteString("I am LCD");
		delay(30000);
	}

} /* main */
Exemplo n.º 7
0
int main(void)
{
	cpu_clock_init();
	ssp_clock_init();

	inputInit();

    lcdInit();
    lcdFill(0xff);
	OFF(MIXER_EN);

	static const struct MENU main={ "img test", {
		{ "LCD", &doLCD},
		{NULL,NULL}
	}};
	handleMenu(&main);
	return 0;
}
Exemplo n.º 8
0
int main(uint32_t startloc) {
	cpu_clock_init();
	ssp_clock_init();
	systick_set_reload(208000);
	systick_set_clocksource(0);
	systick_interrupt_enable();
	systick_counter_enable();

//	cpu_clock_pll1_max_speed();

	SETUPgout(EN_VDD);
	SETUPgout(MIXER_EN);

	SETUPgout(LED1);
	SETUPgout(LED2);
	SETUPgout(LED3);
	SETUPgout(LED4);
	inputInit();
	flashInit();

    lcdInit();
	fsInit();
    lcdFill(0xff); /* Display BL Image here */

	sli=startloc;

	if (startloc != (uintptr_t)&_app_start){ /* not booted via DFU, do autoboot */ 
		if (getInputRaw()!=BTN_LEFT){
			char filename[FLEN];
			readTextFile(BOOTCFG, filename, FLEN);
			lcdPrintln("Fname");
			lcdPrintln(filename);
			bootFile(filename,0);
		};
	};
	static const struct MENU main={ "Bootloader", {
		{ "Info", &doInfo},
		{ "Exec", &doExec},
		{ "Flash", &doFlash},
		{NULL,NULL}
	}};
	handleMenu(&main);
	return 0;
}
Exemplo n.º 9
0
int main(void)
{
	int fd;
	int i;
	if (wiringPiSetup() == -1){
		exit(1);
	}

	fd = lcdInit(2,16,4, 2,3, 6,5,4,1,0,0,0,0); //see /usr/local/include/lcd.h
	printf("%d", fd);
	if (fd == -1){
		printf("lcdInit 1 failed\n") ;
		return 1;
	}
	sleep(1);

	lcdClear(fd);
	lcdPosition(fd, 0, 0); 
	lcdPuts(fd, "Welcom To--->");

	lcdPosition(fd, 0, 1); 
	lcdPuts(fd, "  sunfounder.com");

	sleep(1);
	lcdClear(fd);

	while(1){
		for(i=0;i<sizeof(Buf)-1;i++){
			lcdPosition(fd, i, 1);
			lcdPutchar(fd, *(Buf+i));
			delay(200);
		}
		lcdPosition(fd, 0, 1); 
		lcdClear(fd);
		sleep(0.5);
		for(i=0; i<16; i++){
			lcdPosition(fd, i, 0);
			lcdPutchar(fd, *(myBuf+i));
			delay(100);
		}
	}

	return 0;
}
Exemplo n.º 10
0
void initialize() {
	//initialize base encoders
	yellowDriveEncoder = encoderInit(8, 9, true);
	greenDriveEncoder = encoderInit(6, 7, false);

	//initialize flywheel encoders
	yellowFlywheelEncoder = encoderInit(3, 4, false);
	greenFlywheelEncoder = encoderInit(11, 12, false);

	tbhStarted = 0;

	//initialize lcd screen
	lcdInit(uart1 );
	lcdClear(uart1 );
	lcdSetBacklight(uart1, true);

	//run autonomous selection menu when we are done initializing
	lcdAutoSelection();
}
Exemplo n.º 11
0
int main(void)
{
    DDRD = 0xFF;
    lcdInit(&lcdHandle,
            LCD_4BIT_BUS | LCD_2LINE_MODE | LCD_5X7_DOTS_FORMAT,
            LCD_DISPLAY_ON,
            LCD_INCREMENT);

    uartInit(BAUD_PS(9600));
    uartEnableTx();

    lcdwStringAt(&lcdHandle, 1, 1, "Hello world.");
    lcdInitBargraph(&lcdHandle);

    uartwString("Hello world!\n");

    while(1)
    {

        lcdPrintBargraphAt(&lcdHandle, 2, 1, &lcdBargraphDescriptor);
        /*
        _delay_ms(1000);
        lcdwCmd(&lcdHandle, LCD_DISPLAY_OFF);
        _delay_ms(1000);
        lcdwCmd(&lcdHandle, LCD_DISPLAY_ON);
        */


        lcdBargraphDescriptor.level += 1;
        uartwULong(lcdBargraphDescriptor.level);
        uartwLong(-lcdBargraphDescriptor.level);
        uartwChar('\n');

        if(lcdBargraphDescriptor.level >= lcdBargraphDescriptor.maxLevel)
        {
            lcdBargraphDescriptor.level = 0;
        }

        _delay_ms(100);
    }

    return 0;
}
Exemplo n.º 12
0
void CLCD::init(const char *fontfile, const char *fontfile2, const char *fontfile3)
{
	InitNewClock();

	if (!lcdInit(fontfile, fontfile2, fontfile3))
	{
		printf("[lcdd] LCD-Init failed!\n");
#ifndef BOXMODEL_DM500
		// on the dm500, we need the timethread for the front LEDs
		return;
#endif
	}

	if (pthread_create (&thrTime, NULL, TimeThread, NULL) != 0 )
	{
		perror("[lcdd]: pthread_create(TimeThread)");
		return ;
	}
}
Exemplo n.º 13
0
int main(int argc, const char *argv[]) {
	uint8 i;
	uint8 track[4];
	uint8 player[4];

	// Init system clock & disable WDT
	//
	CLKPR = 0x80;
	CLKPR = 0x00;
	MCUSR &= ~(1 << WDRF);
	wdt_disable();

	srand(12345);

	// Init LCD
	//
	lcdInit();

	for ( ; ; ) {
		if ( PIND & 0x80 ) {
			initSelector(32);
			for ( i = 0; i < 4; i++ ) {
				track[i] = selectItem();
			}
			initSelector(NUM_CHARACTERS);
			for ( i = 0; i < 4; i++ ) {
				player[i] = selectItem();
			}
			lcdSetCursor(0,0);
			for ( i = 0; i < 4; i++ ) {
				lcdPrintFlashString(selectCharacter(player[i]));
				lcdPrintFlashString(selectTrack(track[i]));
			}
			while ( PIND & 0x80 );
		} else {
			lcdClearScreen();
			do {
				rand();
			} while ( !(PIND & 0x80) );
		}
	}
}
Exemplo n.º 14
0
void main(void) {
    // Configure cpu and mandatory peripherals
    cpuInit();                                // Configure the CPU
// we do it later
//    systickInit(CFG_SYSTICK_DELAY_IN_MS);     // Start systick timer
// cpuInit already calls this
//    gpioInit();                               // Enable GPIO 
    pmuInit();                                // Configure power management
    adcInit();                                // Config adc pins to save power

    // initialise basic badge functions
    rbInit();

    initUUID(); // Cache UUID values.
  
    lcdInit(); // display

    lcdFill(0);
    lcdDisplay();
    
    switch(getInputRaw()){
        case BTN_ENTER:
            lcdPrint("ISP active");
            lcdRefresh();
            ReinvokeISP();
            break;
        case BTN_DOWN:
            lcdPrint("MSC active");
            lcdRefresh();
            usbMSCInit();
            while(1);
            break;
    };

    fsInit();

    if( getInputRaw() == BTN_UP ){ // Reset config
            saveConfig();
    }

	wrapper(); // see applications/ subdirectory
}
Exemplo n.º 15
0
static long init_record(lcdoutRecord *pstrout)
{
  struct Pin_Info *pin_info = malloc(sizeof(struct Pin_Info));

  if(wiringPiSetup() == -1)
    return 1;

  int rows = 2;
  int cols = 16;
  int bits = 4;
  int rs = 4;
  int strb = 5;
  int data[8] = {0,1,2,3,0,0,0,0};

  char *para = pstrout->out.value.instio.string;
  rows = atoi(strtok(para, " "));
  cols = atoi(strtok(NULL, " "));
  bits = atoi(strtok(NULL, " "));
  rs = atoi(strtok(NULL, " "));
  strb = atoi(strtok(NULL, " "));

  pinMode(rs, OUTPUT);
  pinMode(strb, OUTPUT);

  int i;
  for(i=0; i<bits; i++)
  {
    data[i] = atoi(strtok(NULL, " "));
    pinMode(data[i], OUTPUT);
  }

  int handle = -1;

  handle = lcdInit(rows,cols,bits,rs,strb,data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7]);

  pin_info->bits = bits;
  pin_info->handle = handle;

  pstrout->dpvt = pin_info;

  return 0;
}
Exemplo n.º 16
0
void main(int argc, char **argv)
{
    lcdInit();

    lcdDisplayText("***********\nBeagle Bone\n***********");
    DELAY_SECONDS(5);

    lcdClear();
    lcdGoToXY(1,5);
    lcdDisplayText("Welcome");
    lcdGoToXY(2,5);
    lcdDisplayText("Rakesh");
    lcdGoToXY(3,5);
    lcdDisplayText("Mali");
    DELAY_SECONDS(5);
        
    lcdClear();
    lcdGoToXY(3,0);
    lcdScrollText("<<Scroll>>", 100, 10);
}
Exemplo n.º 17
0
//! Initializes all enabled board features. Must be called in your program before using other library functions.
inline void initialize()
{
	//configure BTN1 as an input
	cbi(DDRD, DDD4);
	//enable pullup for BTN1
	sbi(PORTD, PD4);

	//configure LED as an output
	sbi(DDRG, DDG2);

	//configure 74LS374 (D Flip-Flop) clock pin as an output
	sbi(DDRD, DDD5);

	//configure LCD/Servo bus on port C as an output
	DDRC = 0xFF;

	#if USE_LCD == 1
		//initialize LCD
		lcdInit();
	#endif

	#if USE_I2C == 1
		//configure I2C clock rate
		i2cInit();
	#endif

	#if USE_MOTOR0 == 1 || USE_MOTOR1 == 1
		//initialize enabled motors
		motorInit();
	#endif

	#if NUM_SERVOS > 0
		//initialize servos
		servoInit();
	#endif

	#if USE_ADC == 1
		//initialize ADC
		adcInit();
	#endif
}
Exemplo n.º 18
0
//----- Begin Code ------------------------------------------------------------
int main(void)
{
	uint8_t a=0;

	// initialize our libraries
	// initialize the UART (serial port)
	uartInit();
	// make all rprintf statements use uart for output
	rprintfInit(uartSendByte);
	// turn on and initialize A/D converter
	a2dInit();
	// initialize the timer system
	timerInit();
	// print a little intro message so we know things are working
	rprintf("\r\nWelcome to AVRlib!\r\n");
	
	// initialize LCD
	lcdInit();
	// direct printf output to LCD
	rprintfInit(lcdDataWrite);

	// print message on LCD
	rprintf("Welcome to AVRlib!");

	DDRA = 0x00;
	PORTA = 0x00;

	// display a bargraph of the analog voltages on a2d channels 0,1
	while(1)
	{
		lcdGotoXY(0,0);
		lcdProgressBar(a2dConvert8bit(0), 255, 20);
		rprintf(" X: %d", a2dConvert8bit(0));
		rprintf(" Sample: %d", a++);
		lcdGotoXY(0,1);
		lcdProgressBar(a2dConvert8bit(1), 255, 20);
		rprintf(" Y: %d", a2dConvert8bit(1));
	}

	return 0;
}
Exemplo n.º 19
0
int main(void) {
	halInit();
	chSysInit();
	
	lcdInit(&GLCDD1);
	lcdClear(Black);
	lcdDrawString(100, 100, "Hello World", White, Black);

	lcdMoveCursor(10,10,White, Black);
	chprintf((BaseSequentialStream *)&GLCDD1, "chTimeNow: %d", chTimeNow());

	lcdDrawCircle(150, 150, 10, filled, Green);
	lcdDrawLine(0, 0, lcdGetWidth(), lcdGetHeight(), Yellow);

	while (TRUE) {
		
		chThdSleepMilliseconds(200);	
	}

	return 0;
}
Exemplo n.º 20
0
 void main (void)
 {
 	lcdInit();								// Clear Screen, Display ON, Cursor ON, Blinking ON
											// Use 8-bit, 2 Lines, Font 5x7

	lcdSetInputMode(1,0);					// Cursor INC, No Shift

	for(;;)
	{
		lcdClearRow(0);
		lcdWriteString("April is a girl");
		lcdClearRow(1);
		lcdWriteString("Ha! Ha!");
		delay(50000);
		
		lcdClearRow(0);
		lcdWriteString("Ha! Ha!");	
		lcdClearRow(1);
		lcdWriteString("April is a girl");	
		delay(50000);
	}
 } /* main */
Exemplo n.º 21
0
Arquivo: main.c Projeto: DanBUK/r0ket
int main(void) {
    // Configure cpu and mandatory peripherals
    cpuInit();                                // Configure the CPU
// we do it later
//    systickInit(CFG_SYSTICK_DELAY_IN_MS);     // Start systick timer
// cpuInit already calls this
//    gpioInit();                               // Enable GPIO 
    pmuInit();                                // Configure power management
    adcInit();                                // Config adc pins to save power

    // initialise basic badge functions
    rbInit();

    fsInit();
  
    lcdInit(); // display

    lcdFill(0);
    lcdDisplay();

	wrapper(); // see module/ subdirectory
}
Exemplo n.º 22
0
void main (void)
{
	unsigned char n;

	lcdInit();							// Clear Screen, Display ON, Cursor ON, Blinking ON
										// Use 8-bit, 2 Lines, Font 5x7

	lcdSetInput(LCD_MODE_INPUT_INC |
				LCD_MODE_INPUT_SHIFT_OFF);
		
	for (;;)
	{
		for(n=0; n<0xf; n++)
		{
			lcdClearRow(1);
			lcdWriteCmd(0x80 | 0x40 | n);

			lcdWriteString("April");
			delay(10000);
		}
	}

} /* main */
Exemplo n.º 23
0
void init(void)
{
   // Initialize Timer
   timerInit();
   // Initialize LCD
   lcdInit();
   ourLcdControlWrite(1<<LCD_ON_CTRL | 1<<LCD_ON_DISPLAY);
   // Initialize UART
	uartInit();
	uartSetBaudRate(CMU_BAUD);
	uartSetRxHandler(packetRcv);
   rprintfInit(uartSendByte);
   // Initialize PWM
   outb(DDRD, 0xFF);	// set all port D pins to output
   timer1PWMInit(8);
	timer1PWMAOn();
   timer1PWMBOn();
   // Initialize  Servos
   servoInit();
   // Initialize CMU
   lcdWriteStr("CMUcam2 init", 0, 0);
   cmuInit();
}
Exemplo n.º 24
0
/*
 * Application entry point.
 */
int main(void) {

  /*
   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   */
  halInit();
  chSysInit();

  /*
   * Activates the serial driver 2 using the driver default configuration.
   */
  sdStart(&SD2, NULL);

  /*
   * This initialization requires the OS already active because it uses delay
   * APIs inside.
   */
  lcdInit();
  lcdCmd(LCD_CLEAR);
  lcdPuts(LCD_LINE1, "   ChibiOS/RT   ");
  lcdPuts(LCD_LINE2, "  Hello World!  ");

  /*
   * Starts the LED blinker thread.
   */
  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

  while(TRUE) {
    if (!palReadPad(IOPORT1, PORTA_BUTTON1))
      TestThread(&SD2);
    chThdSleepMilliseconds(500);
  }
}
Exemplo n.º 25
0
void main(void)
{
	char font0[]={0x06, 0x09, 0x09, 0x06, 0x03, 0x1a, 0x05, 0x08};

	char msgA[]="Wow8051";
	char msgB[]="Wow is Great!!!";

	lcdInit();				// Set 2 lines, font:5x7

	lcdSetDisplayMode(LCD_DMODE_DISPLAY_ON | 
					  LCD_DMODE_CURSOR_ON  |
					  LCD_DMODE_CURSOR_BLINK_ON);

//	lcdMakeRawFont(0, 0x01, 0x02, 0x04, 0x08, 0x10, 0x11, 0x0a, 0x11);

//	lcdMakeRawFont(0, 0x04, 0x0b, 0x04, 0x07, 0x1a, 0x04, 0x08, 0x10);
//	lcdMakeRawFont(1, 0x06, 0x09, 0x09, 0x06, 0x03, 0x1a, 0x05, 0x08);

	lcdMakeFont(0, font0);

	lcdClearScreen();
	lcdSetInputMode(LCD_INPUT_INC, LCD_INPUT_SHIFT_OFF);

	lcdWriteData(0);
	lcdWriteData(1);
	lcdWriteData(' ');
	lcdWriteString(msgA);
	lcdWriteData(' ');
	lcdWriteData(1);
	lcdWriteData(0);

	lcdSelectRow(1);
	lcdWriteString(msgB);

	for (;;);

} /* main */
Exemplo n.º 26
0
int main(void) {
	cpu_clock_init_();
	ssp_clock_init();

	systickInit();

//	cpu_clock_pll1_max_speed();

	SETUPgout(EN_VDD);
	SETUPgout(MIXER_EN);

	SETUPgout(LED1);
	SETUPgout(LED2);
	SETUPgout(LED3);
	SETUPgout(LED4);

	inputInit();
	feldInit();

    lcdInit();
	fsInit(); 
    lcdFill(0xff);

	static const struct MENU main={ "main 1", {
		{ "FS", &doFS},
		{ "MSC", &doMSC},
		{ "flash", &doFlash},
		{ "LCD", &doLCD},
		{ "speed", &doSpeed},
		{ "ADC", &doADC},
		{ "feld", &doFeld},
		{ "chrg", &doChrg},
		{NULL,NULL}
	}};
	handleMenu(&main);
	return 0;
}
Exemplo n.º 27
0
Arquivo: main.c Projeto: sebseb7/lun1k
int main(void)
{
	RCC_ClocksTypeDef RCC_Clocks;


	RCC_GetClocksFreq(&RCC_Clocks);
	/* SysTick end of count event each 0.1ms */
	SysTick_Config(RCC_Clocks.HCLK_Frequency / 10000);

	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
	
	
	//prepare init structure
	GPIO_InitTypeDef GPIO_InitStructure;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
	GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_OUT;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
/*
 *      10   11   12
 *
 * E    C7   C5   B12
 * DC   A7   A7   A7
 * RW   C9   C9   C9
 * RST  A6   A6   A6
 * D0   C4   B15  B15
 * D1   C5   B0   B0
 * D2   B0   B1   B1
 * D3   B1   B2   B2
 * D4   B15  B14  B14
 * D5   B14  B13  B13
 * D6   B13  B12  C5
 * D7   B12  C6   C6
 *
 * v11 : E,D0..D7 swapped
 * v12 : E and D6 swapped
 *
 */

	
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_6;
	GPIO_Init(GPIOA, &GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_7;
	GPIO_Init(GPIOA, &GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_0;
	GPIO_Init(GPIOB, &GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_1;
	GPIO_Init(GPIOB, &GPIO_InitStructure);
#if LUN1K_VERSION >= 11
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_2;
	GPIO_Init(GPIOB, &GPIO_InitStructure);
#endif
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_12;
	GPIO_Init(GPIOB, &GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_13;
	GPIO_Init(GPIOB, &GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_14;
	GPIO_Init(GPIOB, &GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_15;
	GPIO_Init(GPIOB, &GPIO_InitStructure);
#if LUN1K_VERSION == 10
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_4;
	GPIO_Init(GPIOC, &GPIO_InitStructure);
#endif
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_5;
	GPIO_Init(GPIOC, &GPIO_InitStructure);
#if LUN1K_VERSION >= 11
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_6;
	GPIO_Init(GPIOC, &GPIO_InitStructure);
#endif
#if LUN1K_VERSION == 10
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_7;
	GPIO_Init(GPIOC, &GPIO_InitStructure);
#endif
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_9;
	GPIO_Init(GPIOC, &GPIO_InitStructure);

	//leds
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_2;       
	GPIO_Init(GPIOD, &GPIO_InitStructure);  
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_1;       
	GPIO_Init(GPIOC, &GPIO_InitStructure);  
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_3;       
	GPIO_Init(GPIOC, &GPIO_InitStructure);  
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_3;       
	GPIO_Init(GPIOB, &GPIO_InitStructure);  

	//regen
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_1;       
	GPIO_Init(GPIOA, &GPIO_InitStructure);  


	//ESC Button
	GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_IN;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_8;       
	GPIO_Init(GPIOB, &GPIO_InitStructure);  
	
	//stick button
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_13;       
	GPIO_Init(GPIOC, &GPIO_InitStructure);  
	//A
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_4;       
	GPIO_Init(GPIOB, &GPIO_InitStructure);  
	//B
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_0;       
	GPIO_Init(GPIOA, &GPIO_InitStructure);  
	buttonsInitialized=1;
		


	//set RW to 0
	GPIO_ResetBits(GPIOC,GPIO_Pin_9);	

	// 12V power
	GPIOA->ODR           |=       1<<1;


	RNG_Enable();
	srand(RNG_Get());
	RNG_Disable();

	adc_a3_init();

	lcdInit();
	
	n35p112_init();

	
	int current_animation = 0;
	animations[current_animation].init_fp();
	int tick_count = 0;
	

	int loopcount = 0;

	uint8_t count  = 0;
		
	int16_t bat_voltage = adc_a3_get();

	float voltagesample = bat_voltage;

	while(1)
	{
		loopcount++;
		if((loopcount == 55)||(loopcount == 57))
		{
			GPIOC->ODR           |=       1<<1;
			GPIOD->ODR           |=       1<<2;
			GPIOB->ODR           |=       1<<3;
			GPIOC->ODR           |=       1<<3;
		}
		if((loopcount == 56)||(loopcount == 58))
		{
			GPIOC->ODR           &=       ~(1<<1);
			GPIOD->ODR           &=       ~(1<<2);
			GPIOB->ODR           &=       ~(1<<3);
			GPIOC->ODR           &=       ~(1<<3);
			if(loopcount==58)
				loopcount = 0;
		}
		
		uint32_t start_tick = tick;

		get_n35p112(&joy_x,&joy_y);

		animations[current_animation].tick_fp();
/*		int16_t bat_voltage = adc_a3_get();

		fill_8x6(20,20, 5,0,0,0);
		fill_8x6(20,30, 5,0,0,0);
		draw_number_8x6(20,20, bat_voltage, 5, ' ' ,255,255,255);

		voltagesample = voltagesample * 0.98f;
		voltagesample += bat_voltage * 0.02f;


		float tmp2 = voltagesample / (4096.0f / 3.3f);

		float tmp3 = tmp2 * 2.14f;

		draw_number_8x6(20,30, tmp3*1000, 5, ' ' ,255,255,255);

		setLedXY(bat_voltage-2364, count,255,0,0);*/

		lcdFlush();

		uint32_t duration = tick - start_tick;

		//draw_number_8x6(20,20, animations[current_animation].timing - duration, 6, ' ' ,255,255,255);


		if(animations[current_animation].timing > 0)
			Delay100us(animations[current_animation].timing - duration);
	

//		draw_number_8x6(20,30, joy_y, 3, ' ' ,255,255,255);

//		draw_filledCircle(joy_y>>1,joy_x>>1,8,0,0,0);
//		draw_filledCircle(joy_y>>1,joy_x>>1,5,255,255,255);


		count++;
		if(count > 128)
			count=0;

		tick_count++;


		if(get_key_press(KEY_ESC))
		{
			animations[current_animation].deinit_fp();

			current_animation++;
			if(current_animation == animationcount)
			{
				current_animation = 0;
			}
			tick_count=0;
	
			lcdFillRGB(0,0,0);

			animations[current_animation].init_fp();

			//usb_printf("diff: %i , %i (%i) (%i %i %i %i %i %i %i)\n",diff,int_status,i2c_errors,i2c_e[0],i2c_e[1],i2c_e[2],i2c_e[3],i2c_e[4],i2c_e[5],i2c_e[6]);

		}
	}

}
Exemplo n.º 28
0
 /**
  * Runs pre-initialization code.
  *
  * This function will be started in kernel mode one time while the VEX Cortex is starting up. As the scheduler is still paused, most API functions will fail.
  *
  * The purpose of this function is solely to set the default pin modes (pinMode()) and port states (digitalWrite()) of limit switches, push buttons, and solenoids. It can also safely configure a UART port (usartOpen()) but cannot set up an LCD (lcdInit()).
  */
void initializeIO() {
	imeInitializeAll();
	lcdInit(uart1);
}
Exemplo n.º 29
0
int main() {
	int n;
	int c=0;
	int lcd;
	char ch[128];
	int fd_port;				
        int p;					
	int spo2;			
	char read_buf[20];			

	fd_port = open_serial();		// 장치 초기화 및 열기
	
	if(wiringPiSetup()==-1)
	return 1;
	
	pinMode(LED1, OUTPUT);
	pinMode(LED2, OUTPUT);
	pinMode(LED3, OUTPUT);	

	lcd= lcdInit(2,16,4,6,5,4,0,2,3,0,0,0,0);
	sleep(1);
	
		lcdPosition(lcd,0,0);
		lcdPrintf(lcd,"WElCOME!!");
		delay(1000);
		lcdPosition(lcd,0,1);
		lcdPrintf(lcd,"Your Finger Test");
		delay(1500);
		lcdClear(lcd);
		
		lcdPosition(lcd,0,0);
		lcdPrintf(lcd,"Loading   ");
		delay(900);
		lcdPosition(lcd,0,0);
		lcdPrintf(lcd,"Loading.  ");
		delay(900);
		lcdPosition(lcd,0,0);
		lcdPrintf(lcd,"Loading.. ");
		delay(900);
		lcdPosition(lcd,0,0);
		lcdPrintf(lcd,"Loading... ");
		delay(900);
		lcdPosition(lcd,0,0);
		lcdPrintf(lcd,"Loading.  ");
		delay(900);
		lcdPosition(lcd,0,0);
		lcdPrintf(lcd,"Loading..  ");
		delay(900);
		lcdPosition(lcd,0,0);
		lcdPrintf(lcd,"Loading... ");
		delay(900);
		lcdPosition(lcd,0,0);
		lcdPrintf(lcd,"Loading.  ");
		delay(900);
		lcdPosition(lcd,0,0);
		lcdPrintf(lcd,"Loading..  ");
		delay(900);
		lcdPosition(lcd,0,1);
		lcdPrintf(lcd,"S");
		delay(700);
		lcdPosition(lcd,0,1);
		lcdPrintf(lcd,"ST");
		delay(700);
		lcdPosition(lcd,0,1);
		lcdPrintf(lcd,"STA");
		delay(700);
		lcdPosition(lcd,0,1);
		lcdPrintf(lcd,"STAR");
		delay(700);
		lcdPosition(lcd,0,1);
		lcdPrintf(lcd,"START");
		delay(1200);

	while (1)
	{
	 	n=read(fd_port,ch, sizeof(ch));
		p=atoi(ch);
		printf("문자->%s 변환->%d", ch,p);
		
		lcdClear(lcd);				
		lcdPosition(lcd,0,0);
		lcdPrintf(lcd,"Handle Test!");
		lcdPosition(lcd,0,1);
		lcdPrintf(lcd,"Pitch>%d",p);
		if(p<70) {
			digitalWrite(LED3,1);
			digitalWrite(LED2,0);
			digitalWrite(LED1,0);
		}
		else if(p<88){
			digitalWrite(LED3,0);
			digitalWrite(LED2,1);
			digitalWrite(LED1,0);		
		}
		else {
			c++;
			digitalWrite(LED3,0);
			digitalWrite(LED2,0);
			digitalWrite(LED1,1);
			if(c>5){
			lcdClear(lcd);
			lcdPosition(lcd,0,0);
			lcdPrintf(lcd,"Congratulation");
			lcdPosition(lcd,0,1);
			lcdPrintf(lcd,"Pitch>%d  Cure!!",p);
			break;
			}			
		}
//		delay(1);
	}


        close(fd_port);				// 장치 닫기

	return 0;
}
Exemplo n.º 30
0
int main() {
	int G = 0, keyInterval = 1;
	float rms, power = 0, setPower = 3.0;
	unsigned char keyBuf;
	bool adRefresh = true, pwrValueRefresh = true, gainValueRefresh = true;
	bool enAGC = true, atLimit = false;
//	isAdj = false;

	lcdInit();
	ec11Init();
	adInit();
	lcdBacklit(true);

	lcdPrintStr("Design: CX Wang");
	lcdLocate(2, 1);
	lcdPrintStr("Initializing..");
	idelay_s(5);
	lcdClear();

	for(;;) {
		if(pwrValueRefresh || gainValueRefresh) {
			/*
			 * Display
			 */
			lcdWrite(0x0c,0,1); // Turn cursor off
			if(pwrValueRefresh) {
				pwrValueRefresh = false;

				lcdLocate(1, 0);
				lcdPrintStr("PWR: ");
				if(power < 9.94)
					lcdPrintFloat(power + 0.05, 3, 1); //For rounding
				else
					lcdPrintStr(">10");
				lcdPrintStr("W");
				if(enAGC) {
					lcdPrintStr("/");
					lcdPrintFloat(setPower, 3, 1);
					lcdPrintStr("W");
				}
			}
			if(gainValueRefresh) {
				gainValueRefresh = false;
				lcdLocate(0, 1);
				lcdPrintStr("Gain: ");
				lcdPrintInt(G, 4);
				if(G == 0 || G == 1023 * ADNUM) {
					lcdLocate(15, 1);
					lcdPrintStr("*");
					atLimit = true;
				} else if(atLimit) {
					atLimit = false;
					lcdLocate(15, 1);
					lcdPrintStr(" ");
				}

			}
			if(enAGC)
				lcdLocate(15, 0);
			else
				lcdLocate(10, 1);
			lcdWrite(0x0e,0,1); // Turn cursor on
		}

		/*
		 * Adjustment
		 */
		rms = (float)adcRead(0) * 10.0 / 1024.0;
		power = rms * rms / 8.0;
		if(enAGC) {
			if(power < setPower) {
				G += fabs(power - setPower) * 10;//imax(1, fabs(power - setPower) * 10);
				if(G > 1023 * ADNUM)
					G = 1023 * ADNUM;
				adRefresh = true;
				gainValueRefresh = pwrValueRefresh = true;
//				isAdj = true;
			} else if(power > setPower + 0.02) {
				/* Ensure precision for power higher than 0.4watt and reduce oscillation
				 * got x1.03 retired */
				G -= fabs(power - setPower) * 10;//imax(1, fabs(power - setPower) * 10);
				if(G < 0)
					G = 0;
				adRefresh = true;
				gainValueRefresh = pwrValueRefresh = true;
//				isAdj = true;
			} else if(setPower < 0.05) {
				G = 0;
				adRefresh = true;
				gainValueRefresh = pwrValueRefresh = true;
			}
//			else if(isAdj) {
//				isAdj = false;
//				pwrValueRefresh = pwrValueRefresh = true;
//			}
		} else if(fabs(power - setPower) > 0.05){
			setPower = power;
			if(setPower > 7.50)
				setPower = 7.50;
			pwrValueRefresh = true;
		}
		if(adRefresh) {
			adRefresh = false;
			adSetGain(G);
		}

		if((keyBuf = ec11Check()) == 2) {
			if(enAGC) {
				setPower += 0.10;
				if(setPower > 7.50)
					setPower = 7.50;
				pwrValueRefresh = true;
			} else {
				G += keyLevel(keyInterval);
				if(G > 1023 * ADNUM)
					G = 1023 * ADNUM;
				gainValueRefresh = adRefresh = true;
				if(keyInterval < 1000)
					keyInterval += 50;
			}
		} else if(keyBuf == 1) {
			if(enAGC) {
				setPower -= 0.10;
				if(setPower < 0)
					setPower = 0;
				pwrValueRefresh = true;
			} else {
				G -= keyLevel(keyInterval);
				if(G < 0)
					G = 0;
				gainValueRefresh = adRefresh = true;
				if(keyInterval < 1000)
					keyInterval += 50;
			}
		} else if(keyBuf & 0b100) {
			enAGC = !enAGC;
			lcdClear();
			pwrValueRefresh = gainValueRefresh = true;
		}
		if(keyInterval > 1)
			keyInterval--;
	}
}