云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 《单片机的C语言程序设计与运用(第2版)》期末复习题及答案2

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

  • 62 次阅读
  • 3 次下载
  • 2025/5/5 20:02:54

.

#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为列数

可编辑

  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

. #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

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com