Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include <util/delay.h>
- #include <cpu_speed.h>
- #include <macros.h>
- #include <graphics.h>
- #include <lcd.h>
- #include "lcd_model.h"
- void setup( void ) {
- set_clock_speed(CPU_8MHz);
- // (a) Enable input from the joystick-up switch and joystick-down switch.
- CLEAR_BIT(DDRD, 1); //up
- CLEAR_BIT(DDRB, 7); //down
- // (b) Initialise the LCD display using the default contrast setting.
- lcd_init(LCD_DEFAULT_CONTRAST);
- // (c) Use one of the functions declared in "graphics.h" to display
- // your student number, "n9829369", using the foreground colour,
- // positioning the left edge of the text at 12 and the nominal top
- // of the text at 18.
- draw_string(12, 18, "n9829369", FG_COLOUR);
- // (d) Use one of the functions declared in "graphics.h" to copy the contents
- // of the screen buffer to the LCD.
- show_screen();
- }
- // (e) Declare a global variable of type int named Contrast and
- // initialise it to the default LCD contrast.
- //int Contrast = uint8_t contrast;
- //static uint8_t
- int Contrast = LCD_DEFAULT_CONTRAST;
- void process(void) {
- // (f) Test pin corresponding to joystick-down switch. If closed,
- // decrement Contrast by 9. If the result is less than zero,
- // set Contrast to the maximum permitted LCD contrast value.
- if ( BIT_IS_SET(DDRB, 7) ) {
- Contrast = Contrast - 9;
- if ( Contrast < 128 ) Contrast = 255;
- }
- // (g) Test pin corresponding to joystick-up switch. If closed,
- // increment Contrast by 9. If the result is greater
- // then the maximum permitted LCD contrast value, set Contrast
- // to zero.
- if ( BIT_IS_SET(DDRD, 1) ) {
- Contrast = Contrast + 9;
- if ( Contrast > 255 ) Contrast = 128;
- }
- // (h) Send a sequence of commands to the LCD to enable extended
- // instructions, set contrast to the current value of Contrast,
- // and finally retore the LCD to basic instruction mode.
- LCD_CMD( lcd_set_function, lcd_instr_extended );
- LCD_CMD( lcd_set_contrast, Contrast );
- LCD_CMD( lcd_set_function, lcd_instr_basic );
- }
- int main(void) {
- setup();
- for ( ;; ) {
- process();
- _delay_ms(100);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement