Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. #include <avr/io.h>
  2. #include <util/delay.h>
  3. #include <cpu_speed.h>
  4. #include <macros.h>
  5. #include <graphics.h>
  6. #include <lcd.h>
  7. #include "lcd_model.h"
  8.  
  9. void setup( void ) {
  10. set_clock_speed(CPU_8MHz);
  11.  
  12. // (a) Enable input from the joystick-up switch and joystick-down switch.
  13. CLEAR_BIT(DDRD, 1); //up
  14. CLEAR_BIT(DDRB, 7); //down
  15.  
  16.  
  17. // (b) Initialise the LCD display using the default contrast setting.
  18. lcd_init(LCD_DEFAULT_CONTRAST);
  19. // (c) Use one of the functions declared in "graphics.h" to display
  20. // your student number, "n9829369", using the foreground colour,
  21. // positioning the left edge of the text at 12 and the nominal top
  22. // of the text at 18.
  23. draw_string(12, 18, "n9829369", FG_COLOUR);
  24. // (d) Use one of the functions declared in "graphics.h" to copy the contents
  25. // of the screen buffer to the LCD.
  26. show_screen();
  27. }
  28.  
  29. // (e) Declare a global variable of type int named Contrast and
  30. // initialise it to the default LCD contrast.
  31. //int Contrast = uint8_t contrast;
  32. //static uint8_t
  33. int Contrast = LCD_DEFAULT_CONTRAST;
  34.  
  35. void process(void) {
  36. // (f) Test pin corresponding to joystick-down switch. If closed,
  37. // decrement Contrast by 9. If the result is less than zero,
  38. // set Contrast to the maximum permitted LCD contrast value.
  39. if ( BIT_IS_SET(DDRB, 7) ) {
  40. Contrast = Contrast - 9;
  41. if ( Contrast < 128 ) Contrast = 255;
  42. }
  43. // (g) Test pin corresponding to joystick-up switch. If closed,
  44. // increment Contrast by 9. If the result is greater
  45. // then the maximum permitted LCD contrast value, set Contrast
  46. // to zero.
  47. if ( BIT_IS_SET(DDRD, 1) ) {
  48. Contrast = Contrast + 9;
  49. if ( Contrast > 255 ) Contrast = 128;
  50. }
  51. // (h) Send a sequence of commands to the LCD to enable extended
  52. // instructions, set contrast to the current value of Contrast,
  53. // and finally retore the LCD to basic instruction mode.
  54. LCD_CMD( lcd_set_function, lcd_instr_extended );
  55. LCD_CMD( lcd_set_contrast, Contrast );
  56. LCD_CMD( lcd_set_function, lcd_instr_basic );
  57.  
  58.  
  59.  
  60. }
  61.  
  62.  
  63. int main(void) {
  64. setup();
  65.  
  66. for ( ;; ) {
  67. process();
  68. _delay_ms(100);
  69. }
  70.  
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement