#include"reg52.h"
#include"string.h"
unsigned char table[]={0x00,0x00,0x00,0x3C,0x12,0x11,0x11,0x11,0x11,0x11,0x12,0x3C,0x00,0x00,0x19,0x19,0x06,0x06,0x19,0x19,0x06,0x00,0x06,0x19,0x19,0x06,0x06,0x19,0x19,0x00,0x89,0x89,0x06,0x06,0x89,0x89,0x06,0x00,0x06,0x89,0x89,0x06,0x06,0x89,0x89,0x00};
#define CLEARSCREEN LCD_write_command(0x01)
#define LCDIO P0
sbit LCD1602_RS=P2^0;
sbit LCD1602_RW=P2^1;
sbit LCD1602_EN=P2^2;
sbit Key1=P2^3;
sbit Key2=P2^4;
sbit Key3=P2^5;
sbit Key4=P2^6;
sbit Key5=P2^7;
void LCD_write_command(unsigned char command);//寫入指令函數
void LCD_write_dat(unsigned char dat);//寫入數據函數
void LCD_set_xy( unsigned char x, unsigned char y );//設置顯示位置函數
void LCD_dsp_char( unsigned x,unsigned char y,unsigned char dat);//顯示一個字符函數
void LCD_dsp_string(unsigned char X,unsigned char Y,unsigned char *s);//顯示字符串函數
void LCD_init(void);//初始化函數
void delay_nms(unsigned int n);
void Write_CGRAM(unsigned char *p)
{
unsigned char i,j,kk;
unsigned char tmp=0x40; //操作CGRAM的命令碼
kk=0;
for(j=0;j<8;j++) //64 字節存儲空間,可以生成 8="8" 個自定義字符點陣
{
for(i=0;i<8;i++) // 8="8" 個字節生成 1="1" 個字符點陣
{
LCD_write_command(tmp+i); //操作CGRAM的命令碼+寫入CGRAM地址.
LCD_write_dat(p[kk]); //寫入數據
kk++;
}
tmp="tmp" += 8;
}
}
void LCD_init(void)
{
CLEARSCREEN;//clear screen="screen"
LCD_write_command(0x38);//set 8="8" bit="bit" data="data" transmission="transmission" mode="mode"
LCD_write_command(0x0c);//open display="display" (enable lcd="lcd" display)
LCD_write_command(0x80);//set lcd="lcd" first="first" display="display" address="address"
CLEARSCREEN;//clear screen
}
void LCD_write_command(unsigned char="char" command)
{
lcdio="command;
" lcd1602_rs="0;"
lcd1602_rw="0;
" lcd1602_en="0;
" delay_nms(10);
lcd1602_en="1;
" delay_nms(10);
}
void LCD_write_dat(unsigned char="char" dat)
{
LCDIO=dat;
LCD1602_RS=1;
LCD1602_RW=0;
LCD1602_EN=0;
delay_nms(10);
LCD1602_EN=1;
}
void LCD_set_xy( unsigned="unsigned" char="char" x, unsigned="unsigned" char="char" y="y" )
{
unsigned char="char" address;
if (y == 1) {
address="address" = 0x80="0x80" + x;}
else
{ address="address" =0xc0+ x;}
LCD_write_command(address);
}
/****************顯示一個字符**********************/
void LCD_dsp_char( unsigned="unsigned" x,unsigned char="char" y,unsigned char="char" dat)
{
LCD_set_xy( x, y="y" );
LCD_write_dat(dat);
}
/***************顯示字符串函數***************/
void LCD_dsp_string(unsigned char="char" X,unsigned char="char" Y,unsigned char="char" *s)
{
LCD_set_xy( X, Y="Y" );
while="while" (*s)
{
LCD_write_dat(*s);
s="s" ++;
}
}
/***********************************************/
void delay_nms(unsigned int="int" n)
{
unsigned="unsigned" int="int" i="0,j=0;
" for="for" (i=n;i>0;i--)
for (j=0;j<10;j++);
}
void main(void)
{
int i,aa,bb;
delay_nms(5000);
LCD_init();
delay_nms(100);
Write_CGRAM(table);
Key1=0;
Key2=0;
Key3=0;
Key4=0;
Key5=0;
lable:while(1){
LCD_dsp_string(0,1," welcome ");//顯示歡迎界面
LCD_dsp_string(0,2," 2011.05.25 ");
if(Key1==1||Key2==1||Key3==1||Key4==1||Key5==1){
CLEARSCREEN;
while(1){
if(Key1==1){ //顯示大寫D.
CLEARSCREEN;
for (i=0;i<1;i++)
{
LCD_dsp_char( 8+i,1,i);
delay_nms(1);
}
for (i=1;i<2;i++)
{
LCD_dsp_char( 8+i-1,2,i);
delay_nms(1);
}
aa="0;bb=0;
" while(1){
aa++;
if(aa==10000) bb++;
if(bb==10)goto lable;
if(Key1==1||Key2==1||Key3==1||Key4==1||Key5==1)
{
break;
}
}}
if (Key2==1){
CLEARSCREEN;
LCD_dsp_string(0,1," D ");delay_nms(100); //顯示小寫D
aa="0;bb=0;
" while(1){
aa++;
if(aa==10000)bb++;if(bb==10)goto lable;
if(Key1==1||Key2==1||Key3==1||Key4==1||Key5==1)
{
break;
}
}}
if (Key3==1){ CLEARSCREEN;
LCD_dsp_char( 8,1,2);//顯示自己設計好的圖案。
LCD_dsp_char( 9,1,4);
LCD_dsp_char( 8,2,3);
LCD_dsp_char( 9,2,5);
delay_nms(100);
aa="0;bb=0;
" while(1){
aa++;
if(aa==10000)bb++;if(bb==10)goto lable;
if(Key1==1||Key2==1||Key3==1||Key4==1||Key5==1)
{
break;
}
}
}
if (Key4==1){ CLEARSCREEN;
LCD_dsp_string(0,1," smile ") ;//顯示微笑
LCD_dsp_string(0,2," (^-^) ");
delay_nms(100);
aa="0;bb=0;
" while(1){
aa++;
if(aa==10000) bb++;
if(bb==10)goto lable;
if(Key1==1||Key2==1||Key3==1||Key4==1||Key5==1)
{
break;
}
}}
if (Key5==1){ CLEARSCREEN;
LCD_dsp_string(0,1," thankyou byebye ");//顯示thankyou byebye.
LCD_dsp_string(0,2," 2011.05.25 ");
delay_nms(100);
aa="0;bb=0;
" while(1){
aa++;
if(aa==10000) bb++;
if(bb==10)goto lable;
if(Key1==1||Key2==1||Key3==1||Key4==1||Key5==1)
{
break;
}
}}
}
}
}
}
為什么下載到單片機里面只有第一行全滿,求指教。 |