Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #define F_CPU 16000000UL
  2. #include "LCD.h"
  3. #include <avr/io.h>
  4. #include <util/delay.h>
  5.  
  6. void LCD_command(unsigned char command)
  7. {
  8. LCD_CONTROL &= ~((1<<EN) | (1<<RS) | (1<<RW));
  9. _delay_us(1);
  10. LCD_DATABUS = command;
  11. LCD_CONTROL |= (1<<EN);
  12. _delay_us(1);
  13. LCD_CONTROL &= ~(1<<EN);
  14. _delay_us(40);
  15. }
  16.  
  17. void LCD_data(unsigned char data)
  18. {
  19. LCD_CONTROL &= ~((1<<EN) | (1<<RW));
  20. LCD_CONTROL |= (1<<RS);
  21. _delay_us(1);
  22. LCD_DATABUS = data;
  23. LCD_CONTROL |= (1<<EN);
  24. _delay_us(1);
  25. LCD_CONTROL &= ~(1<<EN);
  26. _delay_us(40);
  27. }
  28.  
  29. void LCD_string(unsigned char command, char* string)
  30. {
  31. LCD_command(command);
  32. while(*string != '\0')
  33. {
  34. LCD_data(*string);
  35. string++;
  36. }
  37. }
  38.  
  39. void LCD_init()
  40. {
  41. LCD_DATABUS_DDR = 0b11111111;
  42. LCD_CONTROL_DDR |= ((1<<EN) | (1<<RS) | (1<<RW));
  43. _delay_us(50);
  44. LCD_CONTROL |= ((1<<EN) | (1<<RS));
  45. _delay_us(50);
  46. LCD_CONTROL &= ~(1<<EN);
  47. _delay_us(50);
  48.  
  49. LCD_command(0x38);
  50. LCD_command(0x0C);
  51. LCD_command(0x06);
  52. LCD_command(0x01);
  53. _delay_ms(10);
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement