?? 并行-16.txt
字號:
Char_Set_XY(0,0,"ntzhf100@163.com"); //在第0行的第0個位置依次輸出文字
Char_Set_XY(2,1,"藍水天下"); //在第1行的第2個位置依次輸出文字
Char_Set_XY(0,2,"我的天下,我的自"); //在第2行的第0個位置依次輸出文字
Char_Set_XY(0,3,"由空間!"); //在第3行的第0個位置依次輸出文字
Delay(2000); //軟件延時2S
Lcd_flash(500,3); //液晶閃爍程序每次500ms的延時,閃動3次
//=========液晶內部的地址=============
//Line1 80H 81H 82H 83H 84H 85H 86H 87H
//Line2 90H 91H 92H 93H 94H 95H 96H 97H
//Line3 88H 89H 8AH 8BH 8CH 8DH 8EH 8FH
//Line4 98H 99H 9AH 9BH 9CH 9DH 9EH 9FH
//因為液晶本身的缺陷,所以移動顯示會很丑
Move(8,left,500); //液晶左移程序,移動8步,步與步之間間隔500ms
Delay(2000); //軟件延時2S
Move(8,right,500); //液晶右移程序,移動8步,步與步之間間隔500ms
Delay(2000); //軟件延時2S
Set_Draw(); //設定為繪圖模式
Draw_Pic(0,0,*PIC1); //第一張圖片ATMEL的LOGO
Delay(3000); //軟件延時3S
Draw_Pic(0,0,*PIC2); //第一張圖片AVR的LOGO
Delay(3000); //軟件延時3S
Lcd_Init(); //重新設定為普通模式,即輸出中英文和字符模式
}
}
/*************************************************/
void Chip_Init(void)
{
DDRA = 0XFF;
PORTA = 0X00;
DDRB = 0X07;
PORTB = 0X00;
}
/*************************************************/
void Lcd_Init(void)
{
uint8_t cmd;
cmd=0x30; //功能設置 8位數據,基本指令
WriteCom(cmd); //寫指令
cmd=0x0C; //顯示狀態 ON,游標OFF,反白OFF
WriteCom(cmd); //寫指令
cmd=0x01; //清除顯示
WriteCom(cmd); //寫指令
cmd=0x02; //地址歸位
WriteCom(cmd); //寫指令
cmd=0x80; //設置DDRAM地址
WriteCom(cmd); //寫指令
Delay(100); //延時
}
/*************************************************/
void Delay(uint16_t ms) //毫秒級延時,當改晶振為幾M則xtal設為幾
{
uint16_t i;
while(ms--)
{
for(i=1;i<(uint16_t)(xtal*143-2);i++)
;
}
}
/*************************************************/
void Lcd_flash(uint16_t delay_t,uint8_t times)
{
uint8_t j;
for(j=0;j<times;j++)
{
WriteCom(0x08); //關閉顯示
Delay(delay_t); //軟件延時
WriteCom(0x0c); //開顯示
Delay(delay_t); //軟件延時
}
}
/*************************************************/
void Move(uint8_t step,uint8_t dirction,uint16_t time)
{
uint8_t i;
for(i=0;i<step-1;i++) //移動的步數
{
WriteCom(dirction); //文字移動方向
Delay(time); //控制移動時間
}
}
/*************************************************/
void WriteCom(uint8_t CMD) //寫控制命令函數
{
while(CheckBusy()); //檢測液晶內部是否忙
Clr_RS();
Clr_RW();
DATA_PORT = CMD;
Set_EN();
nop();
nop();
Clr_EN();
}
/*************************************************/
void WriteDat(uint8_t DAT) //寫數據函數
{
while(CheckBusy()); //檢測液晶內部是否忙
Set_RS();
Clr_RW();
DATA_PORT = DAT;
Set_EN();
nop();
nop();
Clr_EN();
}
/*************************************************/
uint8_t CheckBusy(void)
{
uint8_t temp;
DATA_PORT = 0XFF;
Clr_RS();
nop(); //這里的nop不能省略,否則不行
Set_RW();
nop();
Set_EN();
nop();
Set_input();
nop();
temp = PINA;
nop();
Clr_EN();
nop();
Set_output();
temp &= 0x80;
return(temp);
}
/*************************************************/
void Char_Set_XY(uint8_t x, uint8_t y, uint8_t *p)
{
if(y == 0)
{
WriteCom((0x80+x));
}
if(y == 1)
{
WriteCom((0x90+x));
}
if(y == 2)
{
WriteCom((0x88+x));
}
if(y == 3)
{
WriteCom((0x98+x));
}
while(*p != 0)
{
WriteDat(*p++);
}
}
/*************************************************/
void Set_Draw(void)
{
WriteCom(0x01); //清屏
Delay(20); //延時
WriteCom(0x36); //8BIT控制界面,擴充指令集,,繪圖顯示ON
Delay(20); //延時
}
/*************************************************/
void Draw_Pic(uint8_t x, uint8_t y, const uint8_t *Draw)
{
uint8_t i, j, temp_x, temp_y;
temp_x = x;
temp_y = y;
temp_x |= 0x80;
temp_y |= 0x80;
for(i=0;i<32;i++ )
{
WriteCom(temp_y++); //設置繪圖區的Y地址坐標
WriteCom(temp_x); //設置繪圖區的X地址坐標
for(j=0;j<16;j++)
{
WriteDat(*Draw);
Draw++;
}
}
temp_x = 0x88;
temp_y = 0x80;
j = 0;
for(;i<64;i++ )
{
WriteCom(temp_y++); //設置繪圖區的Y地址坐標
WriteCom(temp_x); //設置繪圖區的X地址坐標
for(j=0;j<16;j++)
{
WriteDat(*Draw);
Draw++;
}
}
}
/**************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -