51单片机4乘4矩阵和1602屏幕的计算器代码Word文档格式.docx

上传人:b****1 文档编号:237696 上传时间:2023-04-28 格式:DOCX 页数:8 大小:15.56KB
下载 相关 举报
51单片机4乘4矩阵和1602屏幕的计算器代码Word文档格式.docx_第1页
第1页 / 共8页
51单片机4乘4矩阵和1602屏幕的计算器代码Word文档格式.docx_第2页
第2页 / 共8页
51单片机4乘4矩阵和1602屏幕的计算器代码Word文档格式.docx_第3页
第3页 / 共8页
51单片机4乘4矩阵和1602屏幕的计算器代码Word文档格式.docx_第4页
第4页 / 共8页
51单片机4乘4矩阵和1602屏幕的计算器代码Word文档格式.docx_第5页
第5页 / 共8页
51单片机4乘4矩阵和1602屏幕的计算器代码Word文档格式.docx_第6页
第6页 / 共8页
51单片机4乘4矩阵和1602屏幕的计算器代码Word文档格式.docx_第7页
第7页 / 共8页
51单片机4乘4矩阵和1602屏幕的计算器代码Word文档格式.docx_第8页
第8页 / 共8页
亲,该文档总共8页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

51单片机4乘4矩阵和1602屏幕的计算器代码Word文档格式.docx

《51单片机4乘4矩阵和1602屏幕的计算器代码Word文档格式.docx》由会员分享,可在线阅读,更多相关《51单片机4乘4矩阵和1602屏幕的计算器代码Word文档格式.docx(8页珍藏版)》请在冰点文库上搜索。

51单片机4乘4矩阵和1602屏幕的计算器代码Word文档格式.docx

TIME:

ucharkey_val[]={'

0'

'

1'

2'

3'

4'

5'

6'

7'

8'

9'

A'

B'

C'

D'

E'

F'

G'

ucharcodekey_code[]={0x77,0x7B,0x7D,0x7E,0xB7,0xBB,0xBD,0xBE,0xD7,0xDB,0xDD,0xDE,0xE7,0xEB,0xED,0xEE};

ucharkey,x,count;

uinttime=0;

sbitU3_DS=P1^5;

sbitU3_STCP=P1^4;

sbitU3_SHCP=P1^3;

sbitU4_DS=P1^2;

sbitU4_STCP=P1^1;

sbitU4_SHCP=P1^0;

voiddelay(unsignedintn);

//74HC595

voidU3_595(unsignedcharnum)

{

unsignedcharcount1;

for(count1=0;

count1<

=7;

count1++)

if((num&

0x80)==0x80)//最高位为1,则向SDATA_595发送1

U3_DS=1;

}

else

U3_DS=0;

U3_SHCP=0;

U3_SHCP=1;

num<

<

=1;

//左移

U3_STCP=0;

U3_STCP=1;

}

voidU4_595(unsignedcharnum)//发送指令到RS,RW,E(4,5,6位)

unsignedcharcount2;

for(count2=0;

count2<

count2++)

if((num&

0x80)==0x80)

   {

  U4_DS=1;

    }

    {

  U4_DS=0;

    }

U4_SHCP=0;

  U4_SHCP=1;

 num<

U4_STCP=0;

U4_STCP=1;

//LCD延时子程序n=1时延时1ms

voiddelay(unsignedintn)

{

unsignedinti;

for(;

n>

0;

n--)

for(i=0;

i<

255;

i++)

_nop_();

//写指令到LCD

voidwcmd(unsignedcharcmd)

{

U4_595(0x00);

U3_595(cmd);

U4_595(0x40);

//写要显示的数据到LCD

voidwdat(unsignedchardat)

U4_595(0x10);

U3_595(dat);

U4_595(0x50);

//初始化LCD

voidinit()

wcmd(0x38);

//设置8位总线双行显示,5*7点阵

delay(20);

wcmd(0x0C);

//开显示,开光标,不闪烁

wcmd(0x06);

//读写字符时地址加1

wcmd(0x01);

//清屏

wcmd(0x80+2);

for(x=0;

x<

12;

x++)//第一行显示helloworld!

wdat(dis[x]);

wcmd(0xC2);

4;

x++)//第二行显示按键和次数

wdat(dis1[x]);

wcmd(0xC8);

for(x=0;

5;

x++)

wdat(dis2[x]);

TMOD=0x01;

//中断设置

TH0=0x3C;

//定时初值设置

TL0=0xB0;

EA=1;

//开中断

ET0=1;

//定时器0中断允许

//键盘扫描子程序

ucharkeyscan(void)

unsignedcharhang,lie,keycode;

chari;

P0=0xf0;

hang=P0;

if((hang&

0xf0)!

=0xf0)//有键按下?

delay(50);

//去抖动

=0xf0)//有键按下

P0=0x0f;

lie=P0;

keycode=hang|lie;

//获得键码

for(i=15;

i>

=0;

i--)

if(keycode==key_code[i])//查找键码

key=i;

return(key);

else

P0=0xff;

//按键弹起则关闭定时器

TR0=0;

count=0;

return(16);

voidkeydown()//判断按键按下和显示程序

{

if((P0&

=0xf0)

TR0=1;

//开启定时器

while(P0!

keyscan();

if(count<

30)

time++;

}

else//超过1.5秒计数2次

time+=2;

wcmd(0xC6);

//设置键值显示位置

wdat(key_val[16-key]);

wcmd(0xCD);

//设置次数显示位置

if(time<

10)

wdat(0x30+time);

if(time>

9&

&

time<

100)

wdat(0x30+time/10);

wdat(0x30+time%10);

99&

1000)

wdat(0x30+time/100);

wdat(0x30+time/10-(time/100)*10);

//中断函数

voidtimer()interrupt1

TH0=0x3C;

TL0=0xB0;

count++;

voidmain(void)

init();

for(;

;

keydown();

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 经管营销 > 经济市场

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2