RenHao

lab5

Dec 4th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1. #include <reg51.h>
  2.  
  3. #define SW (~P3 & 0x1f )
  4. #define DBPORT P0
  5. sbit RS=P2^7 ;
  6. sbit RW=P2^6 ;
  7. sbit E=P2^5 ;
  8.  
  9.                                                             0x99 , 0x92 , 0x82 , 0xf8 ,
  10.                                                             0x80 , 0x90 };
  11.  
  12. unsigned char code scan[4] = {0xf7 , 0xfb , 0xfd , 0xfe};
  13.  
  14. void LCD_CMD(char cmd)
  15. {
  16.     char i ;
  17.     DBPORT = cmd ;
  18.     RS = 0;
  19.     RW = 0;
  20.     E  = 1;
  21.     for(i=0; i<40; i++)
  22.     RS = 0;
  23.     RW = 0;
  24.     E  = 0;
  25. }
  26.  
  27. void LCD_DATA(char data1)
  28. {
  29.     char i;
  30.     DBPORT = data1;
  31.     RS = 1;
  32.     RW = 0;
  33.     E  = 1;
  34.     for(i=0; i<40; i++)
  35.     RS = 1;
  36.     RW = 0;
  37.     E  = 0;
  38. }
  39.  
  40. void delay1ms(char i)
  41. {
  42.     char m,n;
  43.     for(m=0; m<i; m++)
  44.         for(n=0; n<120; n++)
  45.             ;
  46. }
  47.  
  48.  
  49. void debouncer()
  50. {
  51.     delay1ms(20);
  52. }
  53.  
  54.  
  55.  
  56. char mess[]="HELLO KITTY!!";
  57.  
  58. main()
  59. {
  60.     int i=0 ;
  61.     delay1ms(5);
  62.     LCD_CMD(0x3f);
  63.     LCD_CMD(0x0e);
  64.     LCD_CMD(0x01);
  65.     delay1ms(2);
  66.     LCD_CMD(0x80);
  67.    
  68.     for(i=0;i<15;i++)
  69.                 LCD_DATA(mess[i]);
  70.     while(1);
  71. }
Advertisement
Add Comment
Please, Sign In to add comment