CS代写 CPU 16000000UL

* project.c
* Main file
* Authors: , ,
* Modified by

Copyright By PowCoder代写 加微信 powcoder

#include
#include
#include
#include
#include

#define F_CPU 16000000UL
#include

#include “game.h”
#include “display.h”
#include “buttons.h”
#include “serialio.h”
#include “terminalio.h”
#include “timer0.h”

// Function prototypes – these are defined below (after main()) in the order
// given here
void initialise_hardware(void);
void start_screen(void);
void new_game(void);
void play_game(void);
void handle_game_over(void);

/////////////////////////////// main //////////////////////////////////
int main(void) {
// Setup hardware and call backs. This will turn on
// interrupts.
initialise_hardware();

// Show the splash screen message. Returns when display
// is complete
start_screen();

// Loop forever,
while(1) {
new_game();
play_game();
handle_game_over();

void initialise_hardware(void) {
init_button_interrupts();
// Setup serial port for 38400 baud communication with no echo
// of incoming characters
init_serial_stdio(38400,0);

init_timer0();

// Turn on global interrupts

void start_screen(void) {
// Clear terminal screen and output a message
clear_terminal();
move_terminal_cursor(10,10);
printf_P(PSTR(“Snakes and Ladders”));
move_terminal_cursor(10,12);
printf_P(PSTR(“CSSE2010/7201 A2 by “));

// Output the static start screen and wait for a push button
// to be pushed or a serial input of ‘s’
start_display();

// Wait until a button is pressed, or ‘s’ is pressed on the terminal
while(1) {
// First check for if a ‘s’ is pressed
// There are two steps to this
// 1) collect any serial input (if available)
// 2) check if the input is equal to the character ‘s’
char serial_input = -1;
if (serial_input_available()) {
serial_input = fgetc(stdin);
// If the serial input is ‘s’, then exit the start screen
if (serial_input == ‘s’ || serial_input == ‘S’) {
// Next check for any button presses
int8_t btn = button_pushed();
if (btn != NO_BUTTON_PUSHED) {

void new_game(void) {
// Clear the serial terminal
clear_terminal();

// Initialise the game and display
initialise_game();

// Clear a button push or serial input if any are waiting
// (The cast to void means the return value is ignored.)
(void)button_pushed();
clear_serial_input_buffer();

void play_game(void) {

uint32_t last_flash_time, current_time;
uint8_t btn; // The button pushed

last_flash_time = get_current_time();

// We play the game until it’s over
while(!is_game_over()) {

// We need to check if any button has been pushed, this will be
// NO_BUTTON_PUSHED if no button has been pushed
btn = button_pushed();

if (btn == BUTTON0_PUSHED) {
// If button 0 is pushed, move the player 1 space forward
// YOU WILL NEED TO IMPLEMENT THIS FUNCTION
move_player_n(1);

current_time = get_current_time();
if (current_time >= last_flash_time + 500) {
// 500ms (0.5 second) has passed since the last time we
// flashed the cursor, so flash the cursor
flash_player_cursor();

// Update the most recent time the cursor was flashed
last_flash_time = current_time;
// We get here if the game is over.

void handle_game_over() {
move_terminal_cursor(10,14);
printf_P(PSTR(“GAME OVER”));
move_terminal_cursor(10,15);
printf_P(PSTR(“Press a button to start again”));

while(button_pushed() == NO_BUTTON_PUSHED) {

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com