使用AVR单片机驱动RT1601 LCD显示芯片

研究了一下,如何用ATmega 16单片机,来驱动字符型液晶显示芯片,现把研究心得写出来:
我手里的这个RT1601液晶显示模块,使用的是S6A0069显示芯片。
各个引脚简单说明一下:

控制和数据引脚配置如下:
-------------------------------
PORTD_0 - RS
PORTD_1 - R/W
PORTD_2 - E
PORTA     - DATA BUS
------------------------------
LCD.h

 

 1 #ifndef _LCD_H_
 2 #define  _LCD_H_
 3 /**/ /*****************************************
 4RS  - PORTD_0
 5R/W - PORTD_1
 6E   - PORTD_2
 7DB     - PORTA
 8******************************************/

 9 void  LCD_Set_RS( void );
10 void  LCD_Clear_RS( void );
11 void  LCD_Set_RW( void );
12 void  LCD_Clear_RW( void );
13 void  LCD_Set_E( void );
14 void  LCD_Clear_E( void );
15 void  LCD_CheckBF( void );
16 //  Write Command
17 void  LCD_Write_Cmd(unsigned  char  byCmd);
18 //  Write Data
19 void  LCD_Write_Data(unsigned  char  byData);
20 void  LCD_Delay_5ms( void );
21 void  LCD_Delay_500ms( void );
22 void  LCD_PortInit( void );
23
24 //  Application Interface
25 void  LCD_Init( void );
26 void  LCD_Display( char *  pstrText);
27
28 #endif
29

LCD.c
这里是液晶驱动的实现部分,对外开放两个接口:LCD_Init, LCD_Display。(我这个模块,是两行显示的,共16个字符)

  1 #include  " LCD.h "
  2 #include  < iom16v.h >
  3 #include  < macros.h >
  4
  5 /**/ /*****************************************
  6RS  - PORTD_0
  7R/W - PORTD_1
  8E   - PORTD_2
  9DB     - PORTA
 10******************************************/

 11
 12
 13 void  LCD_Set_RS( void )
 14 {
 15    PORTD |= (1 << 0);
 16
 17    return;
 18}

 19
 20 void  LCD_Clear_RS( void )
 21 {
 22    PORTD &= ~(1 << 0);
 23
 24    return;
 25}

 26
 27 void  LCD_Set_RW( void )
 28 {
 29    PORTD |= (1 << 1);
 30
 31    return;
 32}

 33
 34 void  LCD_Clear_RW( void )
 35 {
 36    PORTD &= ~(1 << 1);
 37
 38    return;
 39}

 40
 41 void  LCD_Set_E( void )
 42 {
 43    PORTD |= (1 << 2);
 44
 45    return;
 46}

 47
 48 void  LCD_Clear_E( void )
 49 {
 50    PORTD &= ~(1 << 2);
 51
 52    return;
 53}

 54
 55 void  LCD_CheckBF( void )
 56 {    
 57    DDRA = 0x00;    // Input
 58
 59    LCD_Clear_RS();
 60    LCD_Set_RW();
 61    LCD_Set_E();
 62    while (PINA & 0x80)
 63    {
 64        ;
 65    }

 66    LCD_Clear_E();
 67
 68    DDRA = 0xFF;    // Output
 69
 70    return;
 71}

 72
 73 //  Write Command
 74 void  LCD_Write_Cmd(unsigned  char  byCmd)
 75 {
 76    LCD_CheckBF();
 77
 78    LCD_Clear_RS();
 79    LCD_Clear_RW();
 80    LCD_Set_E();
 81    PORTA = byCmd;
 82    LCD_Clear_E();
 83
 84    return;
 85}

 86
 87 //  Write Data
 88 void  LCD_Write_Data(unsigned  char  byData)
 89 {
 90    LCD_CheckBF();
 91
 92    LCD_Set_RS();
 93    LCD_Clear_RW();
 94    LCD_Set_E();
 95    PORTA = byData;
 96    LCD_Clear_E();
 97
 98    return;
 99}

100
101 void  LCD_Delay_5ms( void )
102 {
103    unsigned int i = 5552;
104    while (i--)
105    {
106        ;
107    }

108
109    return;
110}

111
112 void  LCD_Delay_500ms( void )
113 {
114    unsigned char i = 5;
115    unsigned char j = 0;
116
117    while (i--)
118    {
119        j = 7269;
120        while (j--)
121        {
122            ;
123        }

124    }

125
126    return;
127}

128
129 //  Port Init
130 void  LCD_PortInit( void )
131 {
132    PORTD = 0x00
133    DDRD = 0xFF;           // Output
134    DDRA = 0xFF;
135
136    return;
137}

138
139 //  LCD Init
140 void  LCD_Init( void )
141 {
142    LCD_PortInit();
143
144    LCD_Delay_500ms();
145
146    LCD_Write_Cmd(0x38);    // Function Set. 8bit data length, 2-line, 5*8 font
147    LCD_Delay_5ms();
148    LCD_Write_Cmd(0x0C);    // Display ON/OFF Control. Display ON, Cursor OFF, Blink OFF
149    LCD_Delay_5ms();
150    LCD_Write_Cmd(0x01);    // Display Clear.
151    LCD_Delay_5ms();
152    LCD_Write_Cmd(0x06);    // Entry Mode Set. Increment mode, Entire shift off
153
154    return;
155}

156
157 void  LCD_Display( char *  pstrText)
158 {
159    unsigned char i = 0;
160
161    LCD_Write_Cmd(0x80 | 0x00);        // 1 Line Position
162    while (*pstrText != 0x00)
163    {
164        if (i == 8)
165        {
166            LCD_Write_Cmd(0x80 | 0x40);    // 2 Line Position
167        }
        
168
169        LCD_Write_Data(*(pstrText++));
170        i++;
171    }

172
173    return;
174}

175
176

client端调用如下:

 1 // ICC-AVR application builder : 2008-6-4 8:41:19
 2 //  Target : M16
 3 //  Crystal: 4.0000Mhz
 4 #include  < iom16v.h >
 5 #include  < macros.h >
 6 #include  " LCD.h "  
 7
 8 void  main( void )
 9 {
10    LCD_Init();    
11    LCD_Display("RT1601Demo by WF");
12
13    while (1)
14    {
15        ;
16    }

17
18    return;
19}

 好了,就这些,有关该芯片的详细资料,请查看 S6A0069资料。
好运!

 

转载于:https://www.cnblogs.com/vsignsoft/archive/2008/06/05/1214361.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值