?? display.c
字號:
#include "externh.h"
#define Pout_LCD_RS ((*((volatile PORTBIT *)&PORTB)).Bit5)
#define Pout_LCD_RW ((*((volatile PORTBIT *)&PORTD)).Bit3)
#define Pout_LCD_E ((*((volatile PORTBIT *)&PORTD)).Bit4)
#define Pout_LCD_D0 ((*((volatile PORTBIT *)&PORTB)).Bit1)
#define Pout_LCD_D1 ((*((volatile PORTBIT *)&PORTB)).Bit2)
#define Pout_LCD_D2 ((*((volatile PORTBIT *)&PORTB)).Bit3)
#define Pout_LCD_D3 ((*((volatile PORTBIT *)&PORTB)).Bit4)
#define Pout_LCD_D4 ((*((volatile PORTBIT *)&PORTB)).Bit0)
#define Pout_LCD_D5 ((*((volatile PORTBIT *)&PORTD)).Bit7)
#define Pout_LCD_D6 ((*((volatile PORTBIT *)&PORTD)).Bit6)
#define Pout_LCD_D7 ((*((volatile PORTBIT *)&PORTD)).Bit5)
#define DELAYTIME_1 10 //100
#define DELAYTIME_2 20 //200
U8 *string;
void LCDWrite(U8 cmd,U8 rs,U8 dat);
U8 LCDReadStatus(void);
void DispStr(U8 x,U8 y)
{//在(x,y)處顯示字符串*string.
U8 tmp;
tmp = x&0x0f;
if(ChkBit(y,0)) tmp |=0x40;
tmp |=0x80;
LCDWrite(1,0,tmp);
while(*string){
LCDWrite(1,1,*string);
string++;
}
}
void Cls(void)
{
LCDWrite(1,0,1);
}
void SetDataPortOut(void)
{
DDRB |=(1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4);
DDRD |=(1<<5)|(1<<6)|(1<<7);
}
void LCDInit(void)
{
DDRB |=(1<<5);
DDRD |=(1<<3)|(1<<4);
SetDataPortOut();
Delay(DELAYTIME_2);
Pout_LCD_E=0;
Pout_LCD_RW=0;
Pout_LCD_RS=0;
LCDWrite(0,0,0x38);
Delay(DELAYTIME_1);
LCDWrite(0,0,0x38);
Delay(DELAYTIME_1);
LCDWrite(0,0,0x38);
Delay(DELAYTIME_1);
LCDWrite(1,0,0x38);
LCDWrite(1,0,0x08);
LCDWrite(1,0,0x01);
LCDWrite(1,0,0x06);
LCDWrite(1,0,0x0c);
}
void LCDWrite(U8 cmd,U8 rs,U8 dat)
{
U16 t1;
if(cmd) LCDReadStatus();
Pout_LCD_RW=0;
if(rs)
Pout_LCD_RS=1; //對數據進行操作.
else
Pout_LCD_RS=0; //對命令進行操作.
if(ChkBit(dat,0)) Pout_LCD_D0=1;
else Pout_LCD_D0=0;
if(ChkBit(dat,1)) Pout_LCD_D1=1;
else Pout_LCD_D1=0;
if(ChkBit(dat,2)) Pout_LCD_D2=1;
else Pout_LCD_D2=0;
if(ChkBit(dat,3)) Pout_LCD_D3=1;
else Pout_LCD_D3=0;
if(ChkBit(dat,4)) Pout_LCD_D4=1;
else Pout_LCD_D4=0;
if(ChkBit(dat,5)) Pout_LCD_D5=1;
else Pout_LCD_D5=0;
if(ChkBit(dat,6)) Pout_LCD_D6=1;
else Pout_LCD_D6=0;
if(ChkBit(dat,7)) Pout_LCD_D7=1;
else Pout_LCD_D7=0;
Pout_LCD_E=1;
for(t1=0;t1<50;t1++);
Pout_LCD_E=0;
}
U8 LCDReadStatus(void)
{//讀LCD的D7.
U8 ch;
ClrBit(DDRD,5); //D7.
Pout_LCD_E=0;
Pout_LCD_RW=1;
Pout_LCD_RS=0;
Pout_LCD_E=1;
while(1){
if(!ChkBit(PIND,5)) break; //D7.
}
Pout_LCD_E=0;
SetBit(DDRD,5);
return (ch);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -