static void init_adc() { LCDclr(); LCDGotoXY(3,0); LCDstring((uint8_t *)"Initing...",10); AD7793_Reset(); if(!AD7793_Init()) { LCDclr(); LCDGotoXY(2,0); LCDstring((uint8_t *)"ADC Error!",10); return; } LCDGotoXY(0,1); LCDstring((uint8_t *)"S1...",5); adc_init_channel(AD7793_CH_AIN1P_AIN1M); LCDstring((uint8_t *)"OK S2...",9); adc_init_channel(AD7793_CH_AIN2P_AIN2M); LCDstring((uint8_t *)"OK",2); adc_current_channel = AD7793_CH_AIN1P_AIN1M; adc_change_channel_and_trigger_delay(adc_current_channel); LCDclr(); }
void init() { TCCR1A |= (1 << WGM11); TCCR1B |= (1 << WGM12) | (1 << WGM13); TCCR3A |= (1 << WGM31); TCCR3B |= (1 <<WGM32) | (1 <<WGM33); TCCR1A |= (1 << COM1A1) | (1 <<COM1A0) | (1 <<COM1B1) | (1 <<COM1B0) | (1 << COM1C1) | (1 <<COM1C0); TCCR3A |= (1 << COM3A1) | (1 << COM3A0) | (1 << COM3B1) | (1 << COM3B0); TCCR1B |= (1 << CS11); TCCR3B |= (1 << CS31); ICR3 = 40000; ICR1 = 40000; //set PWM pins as output DDRB |= (1 << 5) | (1 << 6) | (1 << 7); DDRE |= (1 << 3) | (1 << 4); LCDinit(); LCDclr(); LCDcursorOFF(); LCDstring("GRIP MODE", 9); }
//Function used to determine which button has been pushed without polling void testAndRespondToButtonPush(char buttonToTest) { if (buttonToTest & P1IFG) { if (buttonToTest & P1IES) { if (flag == 5) { LCDclr(); location = initPlayer(); printPlayer(location); flag = 0; } else { //This code is used to prevent the player (*) from moving outside of the game bounds. int mod = 0; mod = movePlayerInResponseToButtonPush(buttonToTest); clearPlayer(location); location += mod; location = movePlayer(location, mod); clearTimer(); } //Debounces the button } else { debounce(); } //Toggles between reading rising and falling edge P1IES ^= buttonToTest; P1IFG &= ~buttonToTest; } }
//Initialize the LCD void InitLCD(void){ LCDinit(); //initialize the display LCDcursorOFF(); LCDclr(); //clear the display LCDGotoXY(0,0); CopyStringtoLCD(LCDHello, 0, 0); CopyStringtoLCD(LCDHello2, 0, 1); }
//Initialize the LCD void initLCD(){ LCDinit(); //initialize the display LCDcursorOFF(); LCDclr(); //clear the display LCDGotoXY(0,0); const uint8_t LCDHelloTop[] PROGMEM = "Water Cooler v9000\0"; const uint8_t LCDHelloBot[] PROGMEM = "\0"; CopyStringtoLCD(LCDHelloTop, 0, 0); CopyStringtoLCD(LCDHelloBot, 0, 1); }
//----------------------Funktioner------------------------ void init_LCD() { const char lcd_text[] = "ADC value:"; LCDinit(); _delay_ms(1000); LCDclr(); _delay_ms(1000); LCDhome(); _delay_ms(1000); LCDstring((uint8_t*) lcd_text, (uint8_t) strlen(lcd_text)); _delay_ms(1000); LCDvisible(); }
/* * main.c */ int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer //Create strings of text to output to the user char * requiredMsg = "ECE382 is my favorite class! "; char * prompt = "Message?"; char * promptKey = "Press123"; char * message1 = "Learn from yesterday... "; char * message2 = "Live for today... "; char * message3 = "Hope for tomorrow. "; //SPI initialization function initSPI(); // LCD initialization function LCDinit(); //Clear the LCD screen LCDclr(); //Position the cursor to write the prompt to the user. cursorToLineOne(); writeString(prompt); cursorToLineTwo(); writeString(promptKey); int buttonPushed = 0; //A different value is returned depending on which button is pushed. buttonPushed = pollButton(); //Move the selected message to the screen if (buttonPushed == 1) { scrollString(requiredMsg, message1); } if (buttonPushed == 2) { scrollString(requiredMsg, message2); } if (buttonPushed == 3) { scrollString(requiredMsg, message3); } return 0; }
void lcd_init(void) { /* setup LCD on portB and display greeting */ LCDinit(); LCDclr(); LCDGotoXY(0,0); LCDcursorOFF(); LCDstring((uint8_t*)"System online", 13); LCDGotoXY(0,1); if(config.flags.mode == CONFIG_MODE_BASE) LCDstring((uint8_t*)"base", 4); else LCDstring((uint8_t*)"node", 4); }
void init() { load_eeprom_data(); init_outputs(); LCDinit();//init LCD bit, dual line, cursor right LCDclr();//clears LCD init_adc(); uart0_init(UART_BAUD_SELECT(115200UL, F_CPU)); if(target.oxygen > 40000){ target.oxygen = 40000; } while(ANY_BUTTON_PRESSED){;} _delay_ms(150); sei(); set_current_working_mode(MODE_CALIBRATE); set_countdown_timer(15); }
void scrollString(char *string1, char *string2) { unsigned int i = 0; char *count1 = string1, *count2 = string2; while (1) { cursorToLineOne(); char *currentChar = count1; for (i = 0; i < 8; i++) { writeDataByte(*currentChar); //send data in the string to be written currentChar++; if (*currentChar == 0) currentChar = string1; } count1++; if (*count1 == 0) { count1 = string1; } cursorToLineTwo(); char *currentChar2 = count2; for (i = 0; i < 8; i++) { writeDataByte(*currentChar2); //send data in the string to be written currentChar2++; if (*currentChar2 == 0) currentChar2 = string2; } count2++; if (*count2 == 0) { count2 = string2; } __delay_cycles(665544); LCDclr(); } }
void panic(const char* msg) { unsigned char panic_msg[] = "KERNEL PANIC!"; cli(); PORTC=0xFF; LCDinit(); LCDclr(); LCDGotoXY(0,0); LCDcursorOFF(); LCDstring(panic_msg, sizeof(panic_msg)-1); LCDGotoXY(0,1); while(*msg) LCDsendChar(*(msg++)); while(1) { PORTC = ~PORTC; _delay_ms(500); } }
void spilcd_init() { SETBIT(DDRD, 7); //output LCDclr(); dbg_putchar(CMD_ID); dbg_putchar(CMD_NB_LINE); dbg_putchar(4); _delay_ms(5); dbg_putchar(CMD_ID); dbg_putchar(CMD_NB_COLUMN); dbg_putchar(20); _delay_ms(5); dbg_putchar(CMD_ID); dbg_putchar(CMD_CONTRAST); dbg_putchar(255); _delay_ms(5); dbg_putchar(CMD_ID); dbg_putchar(CMD_BACKLIGHT); dbg_putchar(255); _delay_ms(5); }
void change_mode() { LCDclr(); if(currentMode == GRIP_MODE) { currentMode = SHOULDER_MODE; LCDstring("SHOULDER MODE", 13); PORTA |= (1 << PA6); //light on for lift mode } else if(currentMode == SHOULDER_MODE) { currentMode = ELBOW_MODE; LCDstring("ELBOW MODE", 10); PORTA |= (1 << PA6); //light off for grip mode } else if(currentMode == ELBOW_MODE) { currentMode = GRIP_MODE; LCDstring("GRIP MODE", 9); PORTA &= ~(1 << PA6); } else {/*just empty*/} }
// --- Initialize the LCD ---------------------------- void InitLCD(void) { LCDinit(); //initialize the display LCDcursorOFF(); LCDclr(); //clear the display LCDGotoXY(0,0); }
int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer //Use seed to create a random number static const char seed = 1234; //Define all of the strings that will be used in the program char * you = "YOU "; char * win = "WIN! "; char * game = "GAME "; char * over = "OVER! "; char * boom = "BOOM! "; char * space = " "; //Initialize the timer init_timer(); //Initialize the buttons init_buttons(); //Enable the interrupt __enable_interrupt(); //SPI initialization function initSPI(); // LCD initialization function LCDinit(); //Clear the LCD screen LCDclr(); //Place the player at the starting location printPlayer(location); //Create random mine placement char random = prand(seed); random = prand(random); char mine1Location = 0x81 + random % 7; random = prand(random); char mine2Location = 0xC0 + random % 7; //print the first mine, and check to make sure the second mine is printed in a place that the user can still win the game printMine(mine1Location); while (mine2Location == mine1Location || mine2Location == (mine1Location + 0x40) || mine2Location == (mine1Location + 0x41) || mine2Location == (mine1Location + 0x3F)) { random = prand(random); mine2Location = 0xC0 + random % 7; } printMine(mine2Location); //during the rest of the game while (1) { //This is the end of the level - player wins! if (location == 0xC7) { print2LineMessage(you, win); //Set flag and increment to a value above 4 so that 'game over' is not printed flag = 5; increment = 5; //Reset the game for the next level while (flag > 4) { } LCDclr(); location = initPlayer(); printPlayer(location); mine1Location = 0x81 + random % 7; printMine(mine1Location); while (mine2Location == mine1Location || mine2Location == (mine1Location + 0x40) || mine2Location == (mine1Location + 0x41) || mine2Location == (mine1Location + 0x3F)) { random = prand(random); mine2Location = 0xC0 + random % 7; } printMine(mine2Location); increment = 0; } //The game is over if the player hits a mine if (location == mine1Location || location == mine2Location) { flag = 4; print2LineMessage(boom, space); __delay_cycles(444444); } //If two seconds have passed, increment the mines to move in the opposite directions of each other if (increment == 4) { clearPlayer(mine1Location); clearPlayer(mine2Location); mine1Location--; mine2Location++; printMine(mine1Location); printMine(mine2Location); increment = 0; } //If the player loses, print 'game over' if (flag == 4) { print2LineMessage(game, over); flag = 5; increment = 5; //Reset the game for a new level while (flag > 4) { } LCDclr(); location = initPlayer(); printPlayer(location); flag = 0; increment = 0; mine1Location = 0x81 + random % 7; printMine(mine1Location); while (mine2Location == mine1Location || mine2Location == (mine1Location + 0x40) || mine2Location == (mine1Location + 0x41) || mine2Location == (mine1Location + 0x3F)) { random = prand(random); mine2Location = 0xC0 + random % 7; } printMine(mine2Location); } } }
int main(void) { //var uint8_t answer; uint8_t http_respon_data[64]; //init pa sbg in DDRA = 0; PORTA = 0xff; //init lcd LCDinit(); LCDclr(); LCDcursorOFF(); LCDhome(); //init uart sim900_init_uart(38400); //enable isr sei(); LCDGotoXY(0, 0); fprintf(&LCDInputOutputStream, "setup modem = %d", sim900_setup(SETUP_WAIT_INFINITE)); _delay_ms(1000); while(1) { //krm sms pa0 if (bit_is_clear(PINA, PA0)) { _delay_ms(100); loop_until_bit_is_set(PINA, PA0); LCDclr(); LCDhome(); fprintf(&LCDInputOutputStream, "open gprs = %d", sim900_gprs_open_connection( (const uint8_t*)"internet", (const uint8_t*)" ", (const uint8_t*)" ")); } //open gprs if (bit_is_clear(PINA, PA1)) { _delay_ms(100); loop_until_bit_is_set(PINA, PA1); //answer = sim900_gprs_open_bearer((const uint8_t*)"internet", (const uint8_t*)" ", (const uint8_t*)" "); //answer = sim900_gprs_open_bearer("internet", " ", " "); //answer = sim900_gprs_is_opened(); //answer = sim900_gprs_closed(); //answer = sim900_http_get((const uint8_t*) //"http://ex4-tech.id.or.id/sim900/data.php", (const uint8_t*)"c=1", 64, //http_respon_data); answer = sim900_http_send_data( HTTP_POST, (const uint8_t*)"http://ex4-tech.id.or.id/sim900/data.php", (const uint8_t*)"c=1", 64, http_respon_data); LCDclr(); LCDhome(); fprintf(&LCDInputOutputStream, "post = %d", answer); LCDGotoXY(0, 1); fprintf(&LCDInputOutputStream, "%s", http_respon_data); _delay_ms(5000); } if (bit_is_clear(PINA, PA2)) { _delay_ms(100); loop_until_bit_is_set(PINA, PA2); answer = sim900_gprs_close_connection(); LCDclr(); LCDhome(); fprintf(&LCDInputOutputStream, "close gprs = %d", answer); } } }
//initialize the LCD void initLCD(){ LCDinit(); //initialize the display LCDcursorOFF(); LCDclr(); //clear the display }
//********************************************************** //Entry point and task scheduler loop int main(void){ initialize(); // Check if R (for ReactionMaster) is written. Write default score if not if (eeprom_read_byte((uint8_t*)EEPROM_TRUE_ADDR) != 'R'){ eeprom_write_word((uint16_t*)EEPROM_DATA_ADDR,DEFAULT_SCORE); eeprom_write_byte((uint8_t*)EEPROM_TRUE_ADDR,'R'); } // main task scheduler loop // set LEDs corresponding to state // LED7 is used as reaction timer LED while(1){ switch (gameState){ case INITIAL: PORTB = ~0x01; //led0 break; case READY: if (!readyDisplayed){ pressedAndReleased = 0; scoreDisplayed = 0; PORTB = ~0x02; //led1 LCDclr(); LCDGotoXY(0,0); CopyStringtoLCD(LCDReady, 0, 0); readyDisplayed = 1; } break; case WAITING: if (!randomTimeChosen){ pressedAndReleased = 0; readyDisplayed = 0; cheatDisplayed = 0; cheatState = 0; PORTB = ~0x04; //led2 LCDclr(); //assign a random time to waitTime waitTime = rand() % (RND_MAX - RND_MIN + 1) + 1000; randomTimeChosen = 1; } break; case LED_ON: if (!ledTurnedOn){ randomTimeChosen = 0; rxnCount = 0; PORTB = ~(0x08 | 0x80); //led7 and led3 // PORTB = ~0x80; // led7 // turn the buzzer on buzzer = 1; ledTurnedOn = 1; } break; case DISPLAY: if (!scoreDisplayed){ PORTB = ~0x10; //led4 // PORTB = ~0x00; // All off buzzer = 0; pressedAndReleased = 0; ledTurnedOn = 0; if(rxnCount == 1000) { CopyStringtoLCD(LCDTooSlow, 0, 0); } else { CopyStringtoLCD(LCDScore, 0, 0); //Display the player's score //eeprom_write_word((uint16_t*)EEPROM_DATA_ADDR,rxnCount); sprintf(LCDBuffer, "%i", rxnCount); LCDGotoXY(7, 0); LCDstring(LCDBuffer, strlen(LCDBuffer)); } CopyStringtoLCD(LCDHighScore, 0, 1); //Display the high score uint16_t highScore = eeprom_read_word((uint16_t*)EEPROM_DATA_ADDR); sprintf(LCDBuffer, "%i", highScore); LCDGotoXY(11, 1); LCDstring(LCDBuffer, strlen(LCDBuffer)); scoreDisplayed = 1; //Store the player's score if it is larger than the current high score if (rxnCount < highScore){ eeprom_write_word((uint16_t*)EEPROM_DATA_ADDR,rxnCount); } } break; case CHEAT: if (!cheatDisplayed){ PORTB = ~0x20; //led5 // PORTB = ~0x00; // All off randomTimeChosen = 0; cheatState = 0; buzzer = 0; LCDGotoXY(0, 0); CopyStringtoLCD(LCDCheat, 0, 0); cheatDisplayed = 1; } break; } } }