SHARE
TWEET

Untitled

a guest May 13th, 2014 238 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include
  2. #include
  3.  
  4. #define LCD_DPRT PORTA
  5. #define LCD_DDDR DDRA
  6. #define LCD_DPIN PINA
  7. #define LCD_CPRT PORTB
  8. #define LCD_CDDR DDRB
  9. #define LCD_CPIN PINB
  10. #define LCD_RS 0
  11. #define LCD_RW 1
  12. #define LCD_EN 2
  13. void delay_us(int d)
  14. {
  15. _delay_us(d);
  16. }
  17. void LCDcommand(unsigned char cmnd)
  18. {
  19. LCD_DPRT=cmnd;
  20. LCD_CPRT &= ~ (1<<LCD_RS);
  21. LCD_CPRT &= ~ (1<<LCD_RW);
  22. LCD_CPRT |=(1<<LCD_EN);
  23. delay_us(1);
  24. LCD_CPRT &= ~ (1<<LCD_EN);
  25. delay_us(100);
  26.  
  27. }
  28. void LCDdata(unsigned char data)
  29. {
  30. LCD_DPRT=data;
  31. LCD_CPRT |=(1<<LCD_RS);
  32. LCD_CPRT &= ~ (1<<LCD_RW);
  33. LCD_CPRT |=(1<<LCD_EN);
  34. delay_us(1);
  35. LCD_CPRT &= ~ (1<<LCD_EN);
  36. delay_us(100);
  37.  
  38. }
  39. void LCD_init()
  40. {
  41. LCD_DDDR=0XFF;
  42. LCD_CDDR=0XFF;
  43. LCD_CPRT &= ~ (1<<LCD_EN);
  44. delay_us(2000);
  45. LCDcommand(0X38);
  46. LCDcommand(0X0E);
  47. LCDcommand(0X01);
  48. delay_us(2000);
  49. LCDcommand(0X06);
  50. }
  51. void LCD_gotoxy(unsigned char x , unsigned char y)
  52. {
  53. unsigned char FirstCharAdr[]={0X80,0XC0,0X94,0XD4};
  54. LCD_command(FirstCharAdr[y-1]+x-1);
  55. delay_us(100);
  56. }
  57. void LCD_print(char * str)
  58. {
  59. unsigned char i=0;
  60. while(str[i]!=0);
  61. {
  62. LCD_data(str[i]);
  63. i++;
  64. }
  65.  
  66. }
  67.  
  68. int main(void)
  69. {
  70. LCD_init();
  71. LCD_gotoxy(1,1);
  72. LCD_print("the world is but");
  73. LCD_gotoxy(1,2);
  74. LCD_print("one country");
  75. while(1);
  76. return 0;
  77. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top