Пример #1
0
//wirte the main file
int main(void) {

    // Set the CPU speed to 8MHz (you must also be compiling at 8MHz)
    set_clock_speed(CPU_8MHz);

    //initialise the LCD screen
    LCDInitialise(LCD_DEFAULT_CONTRAST);

    //clear any characters that were written on the screen
    clear_screen();

    //fill a buffer (array) of charactes with the string "Microcontroller fun begins! - Happy Hacking", in the position x,y
    //array is too big for the screen size
    //draw_string(10,5, "Microcontroller fun begins! - Happy Hacking");

    ////array is too big for the screen size, so we break it into 3 parts
    draw_string(5,5,"Microcontroller");
    draw_string(5,15,"fun begins!");
    draw_string(5,25,"Happy Hacking");


    //write the string on the lcd
    show_screen();


    return 0;
}
Пример #2
0
/**
 * Main - Run the main program which prints the system time and flashes the LEDs
 * if certain conditions are met
 */
int main() {
    // Setup the hardware
    set_clock_speed(CPU_8MHz);
    init_hardware();

    // Wait until the 'debugger' is attached...
    draw_centred(17, "Waiting for");
    draw_centred(24, "debugger...");
    show_screen();
    while(!usb_configured() || !usb_serial_get_control());
	send_debug_string("Debugger initialised. Debugging strings will appear below:");

    // Run the main loop displaying the system time @ ~10Hz...
    char buff[BUFF_LENGTH];
    unsigned long count = 0;
	send_debug_string("Entering main loop...");
    while (1) {
        // Draw the current system time on the screen
        clear_screen();
        sprintf(buff, "%7.4f", get_system_time());
        draw_centred(21, buff);
        if (count < 1) { send_debug_string("Calling show_screen()..."); }
		show_screen();
        if (count < 1) { send_debug_string("Finished show_screen()."); }
		_delay_ms(100);

        // Toggle LEDs if the conditions are met
        if ((count % 25) == 0) {
            PORTB ^= (1 << PB2);
			send_debug_string("LED0 was toggled.");
        }
        if ((count % 50) == 10) {
            PORTB ^= (1 << PB3);
			send_debug_string("LED1 was toggled.");
        }

        // Increment the loop count
        count++;
		
		enter_breakpoint(99);
    }

    // We'll never get here...
    return 0;
}
Пример #3
0
int main(void) {
    
    //set clock speed to 8MhZ
    set_clock_speed(CPU_8MHz);

    //initialise ports and LCD screen
	Init();
    
    //initialiase timer
    TimerInit();

 
    //initial mesasge
    clear_screen();
    draw_string(4,4,"Simple Timer");
    show_screen();
    
    //stop for 2 sec
    _delay_ms(2000);
    
    //temp buffer
    char buffer[32];
    
    while (1)
    {
        if (TCNT0 >= 254)
        {
            
        clear_screen();
        PORTB ^= (1<<PINB3);        // toggle LED at a frequancy
        sprintf(buffer,"%u",TCNT0); //
        draw_string(20,20,buffer);  // print value of the counter
        show_screen();
            
        TCNT0 = 0; // reset counter
            
        }
       
    }
                

	return 0;
}	
Пример #4
0
int main(void)
{
    //set clock speed to 8MhZ
    set_clock_speed(CPU_8MHz);
    
    
    //call initialisation routines
	Init();	
	PinChangeInit();

	clear_screen();
	draw_string(10,10,"Interrupt Demo");
	show_screen();

    //stops for 2 secs
    _delay_ms(2000);
    
    //do nothing. stop main program from exiting
    while(1);
	
	
	return 0;
}
Пример #5
0
// Basic command interpreter for controlling port pins
int main(void)
{
	char rx_buf[8];// the buffer to store received characters
	uint8_t n = 0;  // to store the number of bytes read from the serial port
    uint8_t counter = 0; //keep count of the number of cycles in the while loop
    // coordinates of the middle of the screen
    int x=LCD_X/2; 
    int y=LCD_Y/2;

	//set clock speed to 8MhZ
    set_clock_speed(CPU_8MHz);
    
    
    //initialise LCD and ports
	Init();

	// initialize the USB, and then wait for the host
	// to set configuration.  If the Teensy is powered
	// without a PC connected to the USB port, this 
	// will wait forever.
	usb_init();
	while (!usb_configured()) /* wait */ ;
	  _delay_ms(1000);


   //keep looping until the character 'q' is received
	while (rx_buf[0]!='q') {
        counter++;
		// wait for the user to run their terminal emulator program
		// which sets DTR to indicate it is ready to receive.
		while (!(usb_serial_get_control() & USB_SERIAL_DTR)) /* wait */ ;

		// discard anything that was received prior.  Sometimes the
		// operating system or other software will send a modem
		// "AT command", which can still be buffered.
		usb_serial_flush_input();


		// and then listen for commands and process them
		while (1) {
            
            //send some characters to the other side
             //send_str(PSTR("> \n"));
            
            if (usb_serial_available())
			  n = recv_str(rx_buf, sizeof(rx_buf)); //read serial port
			else
			  break;	 
            
            
            parse_and_execute_command(rx_buf, n);
            
            
            clear_screen();
            draw_string(x-40,y,"receiving: ");
            show_screen();
            draw_char(x+20,y,rx_buf[0]);
            show_screen();
            
		}
		
	}	 
	return 0;
}
Пример #6
0
/**
 * Main - Run the game which repeatedly loops through trying to find the gold
 */
int main() {
    // Setup the hardware
    set_clock_speed(CPU_8MHz);
    init_hardware();

    // Wait until the 'player' is attached...
    draw_centred(17, "Waiting for");
    draw_centred(24, "the player...");
    show_screen();
    while(!usb_configured() || !usb_serial_get_control());

    // Run the main game loop
    unsigned int seed = 0;
    while (1) {
        // Game start screen
        clear_screen();
        draw_centred(16, "--- LUCKY DIP ---");
        draw_centred(25, "'s' to start...");
        show_screen();
        send_line("--- LUCKY DIP ---");
        send_line("Press 's' to start...");

        // Wait until the key has been pressed (perform seeding only if first run)
        unsigned int seed_temp = 0;
        int16_t curr_char;
        do {
            curr_char = usb_serial_getchar();
            seed_temp++;
        } while (curr_char != 's');
        if (seed == 0) {
            seed = seed_temp;
            srand(seed);
        }
        usb_serial_write("\r\n", 2);

        // Set the gold location
        bury_gold();

        // Present the 9 closed boxes
        clear_screen();
        for (unsigned char i = 0; i<BOXES_W*BOXES_H; i++) {
            draw_box(i, 0);
        }
        show_screen();

        // Prompt the user to pick a box by pressing a number key until they find the gold
		send_line("Please enter a number between 1 and 9 to select a box...");
		int dinner = 0;
		while (!dinner) {
			// Get the users input.			
			int16_t input = usb_serial_getchar();
			
			// Convert the input to an intager to be used as an id.
			int box = (input == '1') ? 0 : (input == '2') ? 1 : (input == '3') ? 2 : (input == '4') ? 3 : (input == '5') ? 4 : (input == '6') ? 5 : (input == '7') ? 6 : (input == '8') ? 7 : (input == '9') ? 8 : -1;
			
			if (box != -1) {
				// Debugging - Display selected box (once it's converted to an id from the users input).
				char buff[20];
				sprintf(buff, "User has selected box #%d", box);
				(debug) ? send_debug_string(buff) : 0;
				
				// Is the selected box open? I should probably open it is it's not...
				if (is_open[box] == 1) {
					send_line("  - That box is already open!");
				} else {
					is_open[box] = 1;
					draw_box(box, 1);
				}
				
				// Did that box contain gold!?
				if (is_gold[box] == 1) {
					show_screen();
					dinner = 1;
				}
			}
			show_screen();
		}

        // Winner, winner, chicken dinner
        send_line("You found the $$$!");
        for (unsigned char i = 0; i<10; i++) {
            PORTB ^= (1 << PB2);
            PORTB ^= (1 << PB3);
            _delay_ms(250);
        }
    }

    // We'll never get here...
    return 0;
}
Пример #7
0
// Basic command interpreter for controlling port pins
int main(void)
{
	char rx_buf[8];// the buffer to store received characters
    uint8_t n=0;  //number of bytes read


	//set clock speed to 8MhZ
    set_clock_speed(CPU_8MHz);
    
    
    //initialise LCD and ports
	Init();

	// initialize the USB, and then wait for the host
	// to set configuration.  If the Teensy is powered
	// without a PC connected to the USB port, this 
	// will wait forever.
	usb_init();
	while (!usb_configured()) /* wait */ ;
	  _delay_ms(1000);


   //keep looping until the character 'q' is received
	while (rx_buf[0]!='q') {
        
		// wait for the user to run their terminal emulator program
		// which sets DTR to indicate it is ready to receive.
		while (!(usb_serial_get_control() & USB_SERIAL_DTR)) /* wait */ ;

		// discard anything that was received prior.  Sometimes the
		// operating system or other software will send a modem
		// "AT command", which can still be buffered.
		usb_serial_flush_input();


		// and then listen for commands and process them
		while (1) {
            
            if (usb_serial_available())
            {
			   n = recv_str(rx_buf, sizeof(rx_buf)); //read serial port
			   //send a characters to the other side
               send_str(PSTR("> \n"));
			}
			else
			{
			  break;
			}	 
          	    
            //check first character of the buffer and perform an action
            if(rx_buf[0]=='a') //turn LED0 ON
                PORTB = 1<<2;
            if(rx_buf[0]=='d') //turn LED1 ON
            	PORTB = 1<<3;
            if(rx_buf[0]=='s') //turn LED0 OFF
            	PORTB = 0x00;
                         
		}
		
	}	 
	return 0;
}