int main(void) { int x, y; char c; char custom_char[] = {0x01, 0x03, 0x03, 0x07, 0x07, 0x0F, 0x0F, 0x1F}; lcd_init(); lcd_on(); c = 0x1F; lcd_custom_char(0, custom_char); while(1){ for(y = 0; y < 2; y++) { c++; if(c > 0xFE) c = 0x1F; for(x = 0; x < 16; x++) { lcd_moveto(x,y); //lcd_write(c); lcd_write(0x00); } } //lcd_clear(); _delay_ms(500); } return 0; /* never reached */ }
int main(void) { unsigned char new_state, old_state; unsigned char a, b; int count = 0; // Count to display char count_str[30]; int note; // Initialize DDR and PORT registers and LCD DDRC &= ~(1<<1) | ~(1<<5); DDRB |= (1<<4); PORTC |= (1<<1) | (1<<5); lcd_init(); // Write a splash screen to the LCD lcd_writecommand(1); lcd_stringout("Melissa Ahn"); // Use lcd_moveto to start at an appropriate column //in the bottom row to appear centered lcd_moveto(1, 4); lcd_stringout("ee109 Lab7"); // Delay 1 second _delay_ms(1000); lcd_writecommand(1); // Read the A and B inputs to determine the initial state // Warning: Do NOT read A and B separately. You should read BOTH inputs // at the same time, then determine the A and B values from that value. lcd_moveto(0, 0); lcd_writedata(count); unsigned char temp = PORTC; b = temp & (1<< 5); a = temp & (1<< 1); if (!b && !a) old_state = 0; else if (!b && a) old_state = 1; else if (b && !a) old_state = 2; else old_state = 3; new_state = old_state; while (1) { /*unsigned char i; for (i = 0; i < 8; i++) { play_note(frequency[i]); _delay_ms(200); }*/ // Read the input bits and determine A and B temp = PINC; b = temp & (1<< 5); a = temp & (1<< 1); if (old_state == 0) { // Handle A and B inputs for state 0 if (!b && a) new_state = 1; else if (b && !a) new_state = 3; } else if (old_state == 1) { // Handle A and B inputs for state 1 if (b && a) new_state = 2; else if (!b && !a) new_state = 0; } else if (old_state == 2) { // Handle A and B inputs for state 2 if (b && !a) new_state = 3; else if (!b && a) new_state = 1; } else { // old_state = 3 // Handle A and B inputs for state 3 if (!b && !a) new_state = 0; else if (b && a) new_state = 2; } if (new_state != old_state) { // Did state change? // Output count to LCD if (new_state > old_state) count++; else count--; lcd_writecommand(1); snprintf(count_str, 30, "%03d", count); lcd_stringout(count_str); old_state = new_state; // Do we play a note? if ((count % 8) == 0) { // Determine which note (0-7) to play note = (abs(count) % 64) / 8; // Find the frequency of the note unsigned short freq = frequency[note]; // Call play_note and pass it the frequency play_note(freq); } } } }
int main(void) { unsigned char adc_result; // Initialize the LCD lcd_init(); // Initialize the ADC adc_init(3); // Use the ADC to find a seed for rand(); adc_result = adc_sample(); srand(adc_result << 8 | adc_result); // Make a 16-bit number for srand() // Write splash screen lcd_writecommand(1); lcd_stringout("Melissa Ahn"); // Use lcd_moveto to start at an appropriate column //in the bottom row to appear centered lcd_moveto(1, 4); lcd_stringout("ee109 Lab6"); // Delay 1 second _delay_ms(1000); // Find a random initial position of the 'X' // n = 16; returns a value 0 - 15 int pos_x = rand() % 16; // Display the 'X' on the screen lcd_writecommand(1); lcd_moveto(0, pos_x); lcd_writedata('X'); //initializes carrot's position int pos_carrot = adc_sample() / 16;//rounds down int second_counter = 0; lcd_moveto(1, pos_carrot); lcd_writedata('^'); while (1) // Loop forever { // Do a conversion int new_pos_carrot = adc_sample() / 16; // Move '^' to new position if (pos_carrot != new_pos_carrot) { lcd_moveto(1, pos_carrot); lcd_writedata(' '); lcd_moveto(1, new_pos_carrot); lcd_writedata('^'); pos_carrot = new_pos_carrot; } // Delay _delay_ms(10); // Check if '^' is aligned with 'X' if (pos_carrot == pos_x) { second_counter++; //increase 10ms counter } else { second_counter = 0; //reset to 0 } if (second_counter != 0 && second_counter % 200 == 0) { lcd_moveto(1, 0); lcd_stringout("You won!!!"); while(1){} //infinite loop; game ends } } return 0; /* never reached */ }