欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: 51單片機用4x4鍵盤控制12864寫入 [打印本頁]

作者: rocky0521    時間: 2018-4-4 15:28
標題: 51單片機用4x4鍵盤控制12864寫入
鍵盤0~9一共10個鍵,還有一個確認鍵,一個修改鍵。我照著書比葫蘆畫瓢自己寫了一個,怎么用protues仿真不成功呢,大佬們幫幫忙。
#include<reg52.h>
#include<intrins.h>
#include<stdlib.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P3^2;                                                                                                  //修改
sbit wela=P3^3;
#define LCD_data P0                                                                                          //12864顯示用P0口
sbit LCD_RS=P3^5;
sbit LCD_RW=P3^6;
sbit LCD_EN=P3^4;
sbit LCD_PSB=P3^7;
uchar code dis1[]={"歡迎通行"};
uchar code dis2[]={"車牌號:"};
uchar code dis3[]={"每公里5元"};
void delay(uint xms)
{
        uint i,j;
        for(i=xms;i>0;i--)
                for(j=110;j>0;j--)
}

void write_cmd(uchar cmd)                           //寫命令
{
        LCD_RS=0;
        LCD_RW=0;
        LCD_EN=0;
        P0=cmd;
        delay(5);
        LCD_EN=1;
        delay(5);
        LCD_EN=0;
}
void write_dat(uchar dat)                                  //寫數(shù)據(jù)
{
        LCD_RS=1;
        LCD_RW=0;
        LCD_EN=0;
        P0=dat;
        delay(5);
        LCD_EN=1;
        delay(5);
        LCD_EN=0;
}
void lcd_pos(uchar X,uchar Y)
{
        uchar pos;
        if(X==0)
                {X=0x80;}
        if(X==1)
                {X=0x90;}
        if(X==2)
                {X=0x88;}
        if(X==3)
                {X=0x98;}
        pos=X+Y;
        write_cmd(pos);
}
void lcd_init()                                                   //LCD初始化設(shè)定
{
        LCD_PSB=1;
        write_cmd(0x30);
        delay(5);
        write_cmd(0x0C);
        delay(5);
        write_cmd(0x01);
        delay(5);
        write_cmd(0x06);
        delay(5);
        lcd_pos(0,0);
        uchar i=0;
        while(dis2[i]!='\0')
        {
                write_dat(dis2[i]);
                i++;
        }
        lcd_pos(1,0);
        i=0;
        while(dis3[i]!='\0')
        {
                write_dat(dis3[i]);
                i++;
        }       
}                                                                       
void matrixkeyscan()                                 //鍵盤掃描程序,使用P2口
{
        uchar temp,key;
        P2=0xfe;
        temp=p2;
        temp=temp&0xf0;
        if(temp!=0xf0)
        {
                delay(10);
                temp=P2;
                temp=temp&0xf0;
                if(temp!=0xf0)
                {
                        temp=P2;
                        switch(temp)
                        {
                                case 0xee:
                                        key=0;
                                        break;
                                case 0xde:
                                        key=1;
                                        break;
                                case 0xbe:
                                        key=2;
                                        break;
                                case 0x7e:
                                        key=3;
                                        break;
                         }
                        while(temp!=0xf0)
                        {
                                temp=P2;
                                temp=temp&0xf0;
                        }
                        write_dat(key);
                }
        }
        P2=0xfd;
        temp=p2;
        temp=temp&0xf0;
        if(temp!=0xf0)
        {
                delay(10);
                temp=P2;
                temp=temp&0xf0;
                if(temp!=0xf0)
                {
                        temp=P2;
                        switch(temp)
                        {
                                case 0xed:
                                        key=4;
                                        break;
                                case 0xdd:
                                        key=5;
                                        break;
                                case 0xbd:
                                        key=6;
                                        break;
                                case 0x7d:
                                        key=7;
                                        break;
                         }
                        while(temp!=0xf0)
                        {
                                temp=P2;
                                temp=temp&0xf0;
                        }
                        write_dat(key);
                }
        }
        P2=0xfb;
        temp=p2;
        temp=temp&0xf0;
        if(temp!=0xf0)
        {
                delay(10);
                temp=P2;
                temp=temp&0xf0;
                if(temp!=0xf0)
                {
                        temp=P2;
                        switch(temp)
                        {
                                case 0xeb:
                                        key=8;
                                        break;
                                case 0xdb:
                                        key=9;
                                        break;
                         }
                        while(temp!=0xf0)
                        {
                                temp=P2;
                                temp=temp&0xf0;
                        }
                        write_dat(key);
                }
        }
        P2=0xfb;
        temp=p2;
        temp=temp&0xf0;
        if(temp!=0xf0)
        {
                delay(10);
                temp=P2;
                temp=temp&0xf0;
                if(temp!=0xf0)
                {
                        temp=P2;
                        switch(temp)
                        {
                                case 0xbb:                                 //此鍵位為數(shù)字確認按鍵
                                        break;
                         }
                        while(temp!=0xf0)
                        {
                                temp=P2;
                                temp=temp&0xf0;
                        }
                        write_cmd(0x01);
                        delay(5);
                        lcd_pos(1,0);
                        uchar i=0;
                        while(dis1[i]!='\0')
                        {
                                write_dat(dis1[i]);
                                i++;
                        }
                         
                }
        }
        P2=0xfb;
        temp=p2;
        temp=temp&0xf0;
        if(temp!=0xf0)
        {
                delay(10);
                temp=P2;
                temp=temp&0xf0;
                if(temp!=0xf0)
                {
                        temp=P2;
                        switch(temp)
                        {
                                case 0x7b:                                 //此鍵位為數(shù)字修改按鍵
                                        break;
                         }
                        while(temp!=0xf0)
                        {
                                temp=P2;
                                temp=temp&0xf0;
                        }
                        lcd_init();
                        lcd_pos(0,8);
                }
        }
}
void main()                                                                          //主函數(shù)
{
        wela=0;
        dula=0;
        uchar i;
        delay(10);
        lcd_init();
        lcd_pos(0,8);
        while(1)
        {
        matrixkeyscan();
        }
}


作者: yinjianchao    時間: 2018-4-5 10:29
·······························································共同進步·1······························




歡迎光臨 (http://www.raoushi.com/bbs/) Powered by Discuz! X3.1