第一范文网 - 专业文章范例文档资料分享平台

《单片机的C语言程序设计与运用(第2版)》期末复习题及答案2

来源:用户分享 时间:2025/7/10 3:50:39 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

.

#include\ #include\sbit RS=P3^5; sbit RW=P3^6; sbit E=P3^7; #define busy 0x80

#define uchar unsigned char #define uint unsigned int

uchar a[]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f',}; void delay_LCM(uchar k)//延时函数 { uint i,j;

for(i=0;i

for(j=0;j<60;j++) } }

void test_1602busy()//测忙函数 {

P1=0xff; E=1; RS=0; RW=1; _nop_(); _nop_();

while(P1&busy) //检测LCD DB7 是否为1 { E=0; _nop_(); E=1; _nop_(); } E=0;

{;}

可编辑

.

}

void write_1602Command(uchar co) //写命令函数 {

test_1602busy(); RS=0; RW=0; E=0; _nop_();

P1=co; _nop_(); E=1; _nop_(); E=0; }

void write_1602Data(uchar Data)//写数据函数 {

test_1602busy(); P1=Data; RS=1; RW=0; E=1; _nop_(); E=0; }

void init_1602(void)//初始化函数 {

write_1602Command(0x38); //LCD功能设定,DL=1(8位),N=1(2行显示)

delay_LCM(5);

write_1602Command(0x01); //清除LCD的屏幕 delay_LCM(5);

write_1602Command(0x06); // LCD模式设定,I/D=1(计数地址加1)

//LCD的使能端 高电平有效

//检测LCD是否忙

可编辑

.

delay_LCM(5);

write_1602Command(0x0F); //显示屏幕 delay_LCM(5); }

void DisplayOneChar(uchar X,uchar Y,uchar DData) {

Y&=1; X&=15;

if(Y)X|=0x40; //若y为1(显示第二行),地址码+0X40 X|=0x80; //指令码为地址码+0X80 write_1602Command(X); write_1602Data(DData); }

void display_1602(uchar *DData,X,Y)//显示函数 {

uchar ListLength=0; Y&=0x01; X&=0x0f; while(X<16) {

DisplayOneChar(X,Y,DData[ListLength]); ListLength++; X++; } }

void delay(uint i) //延时程序 {uint j;

for (j=0;j

uchar checkkey()// 检测有没有键按下 {uchar i ; uchar j ; j=0x0f;

可编辑

.

P2=j; i=P2; i=i&0x0f;

if (i==0x0f) return (0); else return (0xff); }

uchar keyscan()//键盘扫描程序 {

uchar scancode; uchar codevalue; uchar a; uchar m=0; uchar k; uchar i,j;

if (checkkey() ==0) return (0xff); else {delay(100);

if (checkkey()==0) return (0xff); else {

scancode=0xf7;m=0x00;

for (i=1;i<=4;i++) {

k=0x10; P2=scancode; a=P2;

for (j=0;j<4;j++) //J为行数

{ {

while (checkkey()!=0); return (codevalue);

if ((a&k)==0) codevalue = m+j;

//键盘行扫描初值,M为列数

可编辑

《单片机的C语言程序设计与运用(第2版)》期末复习题及答案2.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c9mq08751z66ksx797jw59jajr88l5800wt4_7.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top