void init_hardware(void) { // Initialising the LCD screen LCDInitialise(LCD_DEFAULT_CONTRAST); // Initalising the buttons as inputs (old and new) if (AM_I_OLD) { DDRB &= ~((1 << PB0) | (1 << PB1)); } else { DDRF &= ~((1 << PF5) | (1 << PF6)); } // Initialising the LEDs as outputs DDRB |= ((1 << PB2) | (1 << PB3)); // Initialise the USB serial usb_init(); // Setup two timers with overflow interrupts: // 0 - button press checking @ ~30Hz // 1 - system time overflowing every 8.3s TCCR0B |= ((1 << CS02) | (1 << CS00)); TCCR1B |= ((1 << CS12) | (1 << CS10)); TIMSK0 |= (1 << TOIE0); TIMSK1 |= (1 << TOIE1); // Enable interrupts globally sei(); }
//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; }
//setup and initialise ports and LCD void Init() { DDRB |= (1<<PINB2)|(1<<PINB3); //LED0 and LED1 as outputs DDRB &= ~((1<<PINB0)|(1<<PINB1)); //Switch0 and Switch1 as input PORTB = 0x00; // Turn everything off to start with LCDInitialise( LCD_DEFAULT_CONTRAST ); clear_screen(); show_screen(); }
void init_hardware(void) { // Initialising the LCD screen LCDInitialise(LCD_DEFAULT_CONTRAST); // Initialising the LEDs as outputs DDRB |= ((1 << PB2) | (1 << PB3)); // Initialise the USB serial usb_init(); }
void Init(){ DDRB |= 1 << PINB3; //PIN 3 PORTB for LED1 = output PORTB ^= 1 << PINB3; // DDRB |= 1 << PINB2; // //PIN 2 PORTB for LED2 = output DDRB &= ~(1 << PINB1);// PIN 1 PORT B for Switch 1 = input PORTB |= 1 << PINB1; // LCDInitialise( LCD_DEFAULT_CONTRAST ); // initliase LCD screen clear_screen(); //clear screen }
void main( void ) { /*set up main with initialisation function, then remain in infinite loop*/ buttonsInitialisation(); TRISD = 0; LCDInitialise(); while(1){ if(gotShit){ LCDMoveCursor(0,0); intToDisplay(buttonPressValue); LCDWriteHere(displayChars.characters); delayMs(1); LCDMoveCursor(1,0); intToDisplay(interuptCount); LCDWriteHere(displayChars.characters); delayMs(1); gotShit = 0; } } }