|
估计是:HD44780
- #include
- #include
- #include
- #define uchar unsigned char
- #define uint unsigned int
- #define nop() _nop_()
- uchar bdata status;
- sbit status_busy=status^7;
- sbit status_Reset=status^4;
- sbit LCD_E=P3^2;
- sbit LCD_RW=P3^6;
- sbit LCD_RS=P3^7;
- void LCD_delay1ms(uint delay_xms);
- void LCD_delay50us(uchar count50us);
- void LCD_command(uchar command_data);
- void LCD_data(uchar w_data);
- void LCD_read_busy();
- void LCD_initialize();
- void LCD_dip_11();
- uchar code LCD_dis_char[]={0x32,'Q',0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,'Q',
- };
- uchar code LCD_write_cgram[]={
- 0x01,0x03,0x07,0x0f,0x1f,0x0f,0x07,0x03,//picture3
- 0x10,0x18,0x1c,0x1e,0x1f,0x1e,0x1c,0x18,//picture4
- 0x1f,0x00,0x1f,0x00,0x1f,0x00,0x1f,0x00,//picture5
- 0x08,0x04,0x12,0x08,0x04,0x02,0x11,0x00,//picture7
- 0x08,0x11,0x02,0x04,0x08,0x11,0x02,0x04,//picture8
- 0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,//picture9
- 0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,//picture11
- 0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,//picture12
- };
- //* delay 1ms *//
- void LCD_delay1ms(uint delay_xms)
- {
- uint data n,m;
- for(n=0;n
- {
- for(m=0;m<75;m++)
- {
- ;
- }
- }
- }
- //***********delay50us************************//
- void LCD_delay50us(uchar count50us)
- {
- uchar data k ;
- _nop_();
- for(k=0;k<2*count50us;k++)
- {
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- }
- }
- void LCD_command(uchar command_data)
- { //RS=0;
- //RW=0;
- P3=0;
- LCD_E=1;
- P1=command_data;
- LCD_delay1ms(0x02);
- _nop_();
- LCD_E=0;
- LCD_RS=1;
- LCD_RW=1;
- }
- void LCD_data(uchar w_data)
- {
- LCD_RS=1;
- LCD_RW=0;
- LCD_E=1;
- P1=w_data;
- LCD_delay50us(0x02);
- _nop_();
- LCD_E=0;
- LCD_RS=0;
- LCD_RW=1;
- }
- void LCD_read_busy()
- {
- do
- {
- LCD_RS=0;
- LCD_RW=1;
- LCD_E=1;
- status=P1;
- LCD_delay50us(0x02);
- LCD_delay50us(0x02);
- }
- while(status_busy);
- _nop_();
- LCD_E=0;
- LCD_RS=0;
- LCD_RW=1;
- }
- void LCD_initialize()
- {
- uchar data i;
- P1=0;
- for(i=0;i<3;i++)
- {
- LCD_command(0x38);//N=1 2 line diaplay DL=1 8_bit bus mode whih MPU F=0 5*8 dots //
- LCD_delay50us(0x02);
- LCD_read_busy();
- }
- LCD_command(0x01); /* CLR LCD AC=0 AC+1清屏 */
- LCD_delay1ms(0x02);
- LCD_read_busy();
- //write_command(0x8f); //
-
- LCD_command(0x02);//归home位 set DDRAM Adress is 00h //
- LCD_delay1ms(0x02);
- LCD_read_busy();
- LCD_command(0x04);// 1 I/D S I/D=0 cursor/blink moves to left and ddram address is decreased by 1 //
- LCD_delay50us(0x02);
- LCD_read_busy();
-
- LCD_command(0x0c);//1DCB D=1 entire display is turned on cursor off //cursor bink off //
- LCD_delay50us(0x02);
- LCD_read_busy();
- LCD_command(0x07);
- LCD_delay50us(0x02);
- LCD_read_busy();
-
- }
- void LCD_dip_11()
- { uchar data i;
- LCD_command(0x40);
- for(i=0;i<8;i++)
- {
- LCD_data(0x0a);
- }
- for(i=0;i<8;i++)
- {
- LCD_data(0x15);
- }
- LCD_command(0x80);
- for(i=0;i<40;i++)
- {
- LCD_data(0x00);
- LCD_data(0x01);
- }
- LCD_delay1ms(1000);
- }
- main()
- {
- uchar data i,j;
- LCD_initialize();
- while(1)
- {
- LCD_command(0x40);
- LCD_delay50us(0x02);
-
- for(j=0;j<64;j++)
- {
- LCD_data(LCD_write_cgram[j]);
- LCD_delay50us(0x02);
- }
- for(j=0;j<9;j++)
- {
- LCD_command(0x80);
- LCD_delay50us(0x01);
- for(i=0;i<80;i++)
- {
- LCD_data(LCD_dis_char[j]);
- //write_data(0x00);
- LCD_delay50us(0x01);
- }
- LCD_delay1ms(1000);
- }
- LCD_dip_11();
- LCD_command(0x01);
- LCD_delay1ms(1000);
- }
- }
复制代码 |
|