?? text1.c
字號:
#include"reg51.h" //#include"AT89X51.H"
#include"intrins.h"
typedef unsigned char BYTE; //自定義了數(shù)據(jù)類型 BYTE為unsigned char ;
tepedef bit BOOL;
sbit LCD_RS=P2^5;
sbit LCD_RW=P2^6;
sbit LCD_EP=P2^7;
sbit P1_0=P1^0;
sbit P1_1=P1^1;
sbit P1_2=P1^2;
sbit P1_3=P1^3;
sbit P1_4=P1^4;
sbit P1_5=P1^5;
sbit P1_6=P1^6;
sbit P1_7=P1^7;
sbit P2_0=P2^0;
sbit P2_1=P2^1;
sbit P2_2=P2^2;
sbit P2_3=P2^3;
sbit P2_7=P2^7;
BYTE codedis1[]={"A"}; //使用了自己定義的數(shù)據(jù)類型;
BYTE codedis2[]={"B"};
BYTE codedis3[]={"C"};
BYTE codedis4[]={"D"};
BYTE codedis5[]={"1"};
BYTE codedis6[]={"2"};
BYTE codedis7[]={"3"};
//----------------------------------------------------------------------------
delay(int ms)
{
while(1)
{
for(i=0;i<250;i++)
{
_nop_();
_nop_();
_nop_();
_nop_();
}
}
}
//-------------------------------------------------------------------------------
BOOL led_bz()
{
BOOL result;
LCD_RS=0; //0表示選擇指令寄存器;1表示選擇數(shù)據(jù)寄存器。
LCS_RW=1; //選擇寫入數(shù)據(jù)操作; 讀取忙信號???1忙
LCD_EP=1;
_nop_();
_nop_();
_nop_();
_nop_();
result=(BOOL)(P0&0X80);
LCD_EP=0; //EN高電平到低電平,表示有效;
return result;
}
//------------------------------------------------------------------------------
lcd_wcmd(BYTE cmd)
{
while(lcd_bz());
LCD_RS=0;
LCD_RW=0;
LCD_EP=0;
_nop_();
_nop_();
P0=cmd;
_nop_();
_nop_();
_nop_();
_nop_();
LCD_EP=1; //下降沿有效 ,使能位工作
_nop_();
_nop_();
_nop_();
_nop_();
LCD_EP=0;
}
//-----------------------------------------------------------------------------
lcd_pos(BYTE pos)
{
lcd_wcmd(pos|0x80);
}
lcd_wdat(BYTE dat)
{
while(lcd_bz);
LCD_RS=1;
LCD_RW=0;
LCD_EP=0;
P0=dat;
_nop_();
_nop_();
_nop_();
_nop_();
LCD_EP=1;
_nop_();
_nop_();
_nop_();
_nop_();
LCD_EP=0;
}
//--------------------------------------------------------------------------------------------
lcd_init()
{
lcd_wcmd(0x38);
delay(1);
lcd_wcmd(0x0c);
delay(1);
lcd_wcmd(0x06);
delay(1);
lcd_wcmd(0x01);
delay(!);
}
//-------------------------------------------------------------------------------------------
main()
{
unsigned char shujv=0x00;
BYTE i;
lcd_init();
delay(10);
lcd_wcmd(0x06);
lcd_pos(0);
i=0;
while(dis1[i]!='\0')
{
lcd_wdat(dis1[i]);
i++;
delay(30);
}
lcd_pos(0x40);
i=0;
while(dis2[i]='\0')
{
lcd_wdat(dis2[i]);
i++;
delay(30);
}
delay(800);
lcd_wcmd(0x01);
delay(1);
lcd_wcmd(0x04);
lcd_pos(15);
i=0;
while(dis3[]!='\0')
{
lcd_wdat(dis3[i]);
i++;
delay(30);
}
lcd_pos(0x4f);
i=0;
while(dis4[i]!='\0')
{
lcd_wdat(dis4[i]);
i++;
delay(30);
}
delay(800);
lcd_wcmd(0x01);
delay(200);
//---------------------------------------------------------------------------------------------------
while(1) //安防 主程序
{
P1=0X00;
//P2_0=1;
P2=0X1F;
P1=0X01;
if(P2_0==1)
{
shujv=P2;
shujv=shujv&0x1e;
shujv=shujv>>1;
P3_7=0;
lcd_wcmd(0x01);
lcd_pos(0x40);
i=0;
while(dis5[i]!='\0')
{
lcd_wdat(dis5[i]);
i++;
delay(30);
}
}
delay(200);
//P2_0=0;
P1=0X02;
if(P2_0==1)
{
shujv=shujv&0x1e;
shujv=shujv>>1;
P3_7=0;
lcd_wcmd(0x01);
lcd_pos(0x40);
i=0;
while(dis6[i]!='\0')
{
lcd_wdat(dis6[i]);
i++;
delay(30);
}
}
delay(200);
//P2_0=0;
P1=0X04;
if(P2_0==1)
{
shujv=shujv&0x1e;
shujv=shujv>>1;
P3_7=0;
lcd_wcmd(0x01);
lcd_pos(0x40);
i=0;
while(dis6[i]!='\0')
{
lcd_wdat(dis6[i]);
i++;
delay(30);
}
}
delay(200);
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -