|
|
在暑假做的,參考了好多資料,比較適合新手學(xué)習(xí)。- #include<All.h>
- uchar code LCD1602_5x8[8]={0x80,0x00,0x07,0x08,0x08,0x08,0x08,0x07};//度的數(shù)組
- uchar xdata LCD1602_Write1_Buffer[16]=254;//第一行
- uchar xdata LCD1602_Write2_Buffer[16]=254;//第二行
- //延遲1ms
- void Delay1ms() //@24.000MHz
- {
- unsigned char i, j;
- _nop_();
- i = 32;
- j = 40;
- do
- {
- while (--j);
- } while (--i);
- }
- //寫入寄存器
- void LCD1602_Write_Reg(uchar addr)
- {
- LCD1602_RS=0;//寫命令
- LCD1602_RW=0;
- LCD1602_E=1;
- Delay1ms();
- LCD1602_Data=addr; //傳輸數(shù)據(jù)
- Delay1ms();
- LCD1602_E=0;
- }
- //讀取數(shù)據(jù)
- uchar LCD1602_Read_Data(uchar addr)
- {
- LCD1602_RS=1;//寫命令
- LCD1602_RW=0;
- LCD1602_E=1;
- Delay1ms();
- LCD1602_Data=addr;//傳輸數(shù)據(jù)
- Delay1ms();
- LCD1602_E=0;
-
- return addr;
- }
- //初始化
- void LCD1602_Init()
- {
- uchar idata i;
- LCD1602_RS=0;
- LCD1602_RW=0;
- LCD1602_E=0;
-
- LCD1602_Write_Reg(0x01);//清除顯示
- Delay1ms();
- LCD1602_Write_Reg(0x02);//光標(biāo)復(fù)位
- Delay1ms();
- LCD1602_Write_Reg(0x06);//光標(biāo)和顯示模式
- Delay1ms();
- LCD1602_Write_Reg(0xc0);//顯示開關(guān)控制
- Delay1ms();
- LCD1602_Write_Reg(0x14);//光標(biāo)和字符移一格
- Delay1ms();
- LCD1602_Write_Reg(0x38);//功能設(shè)置
- Delay1ms();
-
-
- //初始化度
- LCD1602_Write_Reg(0x40);
- for(i=0;i<8;i++)
- LCD1602_Read_Data(LCD1602_5x8[i]);
-
- }
- 余下代碼看附件
復(fù)制代碼
|
|