找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

帖子
查看: 5895|回復(fù): 3
打印 上一主題 下一主題
收起左側(cè)

4*4鍵盤(pán)單鍵掃描1602顯示程序,感謝51hei群同胞的幫助

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:17922 發(fā)表于 2009-12-15 21:42 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式

#include<reg52.h>
sbit p30=P3^0;
sbit p31=P3^1;
sbit p32=P3^2;
sbit p07=P0^7;
const s=1;
/*****************
延時(shí)函數(shù)
*****************/
delaynms(unsigned int m)
{
unsigned char i,j;
for(;m!=0;m--)
  for(i=0;i<4;i++)
   for(j=0;j<32;j++)
   ;
}
/******************
1602busy jump
******************/
busyjump()
{
bit result;
p30=0;
p31=1;
p32=1;
result=p07;
p32=0;
return result;

}
/******************
1602讀指令
******************/
readinstruction(unsigned char ins)
{
while(busyjump())
 p30=0;
 p31=0;
 P0=ins;
 p32=1;
 p32=0;
 }
 /**************
 1602讀數(shù)據(jù)
 **************/
 readdata(unsigned char dat)
 {
   while(busyjump());
   p30=1;
   p31=0;
   P0=dat;
   p32=1;
   p32=0;
 }
 /*************
 1602初始化
 *************/
 chush()
{
 delaynms(15);//模塊熱啟動(dòng)
  readinstruction(0x36);
 readinstruction(0x36);
 readinstruction(0x0c);

 readinstruction(0x01);     
 readinstruction(0x06);
}
/****************
顯示地址轉(zhuǎn)換
***************/
showaddr(unsigned char addr)
{
readinstruction(addr|0x80);
}
/***************
定位
***************/
char dingwei (char n)
{
char i;
n=~n;
switch(n)
{
case 0xf0:i=-1; break;
case 0xf1:i=0; break;
case 0xf2:i=1; break;
case 0xf4:i=2; break;
case 0xf8:i=3;  break;
}
return i;
}
/****************
主函數(shù)
***************/
main()
{
char h,l,j,k,flag;
unsigned char temp;
chush();
while(1)
{
  temp=0xfe;
 flag=0;
  for(j=0;j<4;j++,temp=(temp<<1)+0x01)
 {
 P1=temp;
 h=P1/16;
 l=P1&0x0f;
 k=dingwei(l)*4+dingwei(h)+1;
 if(dingwei(h)+1)
  {
   delaynms(1);
  if(dingwei(h)+1)//去抖動(dòng)
    {
  readinstruction(0x01);
  showaddr(0x00);
  readdata(k/10+0x30);
  readdata(k%10+0x30);
  delaynms(2);
  delaynms(1500);
  flag=1;
    }
  
  }
   if(j==3&&flag==0)
    {
     readinstruction(0x01);
  showaddr(0x00);
  readdata('n');delaynms(2);
  readdata('o');delaynms(2);
  readdata(' ');delaynms(2);
  readdata('k');delaynms(2);
  readdata('e');delaynms(2);
  readdata('y');delaynms(2);
  readdata(' ');delaynms(2);
  readdata('p');delaynms(2);
  readdata('u');delaynms(2);
  readdata('t');delaynms(2);
  readdata(' ');delaynms(2);
  readdata('o');delaynms(2);
  readdata('n');delaynms(2);
  delaynms(150);
     }
 }

}

}

[此貼子已經(jīng)被作者于2009-12-17 23:32:23編輯過(guò)]
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:19691 發(fā)表于 2009-12-16 09:38 | 只看該作者

不是很懂

i,m都是什么變量呀!

 

回復(fù)

使用道具 舉報(bào)

板凳
ID:17922 發(fā)表于 2009-12-20 19:29 | 只看該作者
i,m是用來(lái)延時(shí)的
回復(fù)

使用道具 舉報(bào)

地板
ID:786505 發(fā)表于 2020-6-23 15:21 | 只看該作者
原理圖有沒(méi)有��?
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表