尹其畅甲乙两机串口通信和控制流水灯

题目:通过甲单片机来控制乙机

要求:四个键盘中有一个按键按下时,甲乙二机中的对应的流水灯闪烁,如果有其他的键按下,则转向其他的对应的灯闪烁。 甲机代码:

#include #include

#define uchar unsigned char #define uint unsigned int void delay(uchari); voidkeyscan( );

voidchuankou(ucharrr); voidshanshuo(ucharww); void delay(uchari) { ucharj,k;

for(j=i;j>0;j--)

for(k=500;k>0;k--); }

void main() {

P0=0xff; SCON=0X40;

TMOD=0x20; PCON=0x00; TH1=0xfd; TL1=0xfd; TI=0; TR1=1; while(1) {

keyscan(); } }

voidkeyscan() { uchar temp; P1=0xff; temp=P1;

temp=temp&0xff; if(temp!=0xff) { delay(10);

temp=P1; if(temp!=0xff) { switch(temp)

{ case 0xfe:

chuankou('A'); shanshuo(temp); break; case 0xfd: chuankou('B');

shanshuo(temp); break;

case 0xfb: chuankou('C'); shanshuo(temp); break; case 0xf7: chuankou('D'); shanshuo(temp);

break; }

while(temp!=0xff)

}

}

{

temp=P1; temp=temp&0xff; } }

voidshanshuo(ucharaa) { ucharss; while(1) {

P0=aa; delay(300); P0=0xff; delay(300); ss=P1; if(ss!=0xff) {

delay(10); ss=P1; if(ss!=0xff) {

switch(ss) {

case 0xfe: chuankou('A'); shanshuo(ss); break; case 0xfd:

chuankou('B'); shanshuo(ss);

break; case 0xfb:

chuankou('C'); shanshuo(ss); break; case 0xf7: chuankou('D');

shanshuo(ss); break; }

}

} } }

voidchuankou(uchar F) {

SBUF=F; while(!TI); TI=0; }

乙机代码: #include #include #define uchar unsigned char #define uint unsigned int voidshanshuo(uintss); void delay(uchari); void delay(uchari) {

ucharj,k;

for(j=i;j>0;j--)

for(k=500;k>0;k--); }

void main() {

uchar a; SCON=0X50; TMOD=0x20; PCON=0x00; TH1=0xfd; TL1=0xfd; RI=0; TR1=1; P0=0xff; while(1) { if(RI) {

RI=0; switch(SBUF)

{ case 'A': a=0xfe;

break; case 'B':

a=0xfd; shanshuo(a); break; case 'C': a=0xfb; shanshuo(a);

break; case 'D': a=0xf7; shanshuo(a); break; }

}

} }

voidshanshuo(uintss) {

uchar a; a=ss; while(1) { P0=ss; delay(300); P0=0xff; delay(300); if(RI) {

RI=0; switch(SBUF)

{ case 'A':

a=0xfe; shanshuo(a);

break; case 'B':

a=0xfd;

shanshuo(a); break;

case 'C':

a=0xfb; shanshuo(a);

}

case 'D':

a=0xf7; shanshuo(a); break; }

} }

题目:通过甲单片机来控制乙机

要求:四个键盘中有一个按键按下时,甲乙二机中的对应的流水灯闪烁,如果有其他的键按下,则转向其他的对应的灯闪烁。 甲机代码:

#include #include

#define uchar unsigned char #define uint unsigned int void delay(uchari); voidkeyscan( );

voidchuankou(ucharrr); voidshanshuo(ucharww); void delay(uchari) { ucharj,k;

for(j=i;j>0;j--)

for(k=500;k>0;k--); }

void main() {

P0=0xff; SCON=0X40;

TMOD=0x20; PCON=0x00; TH1=0xfd; TL1=0xfd; TI=0; TR1=1; while(1) {

keyscan(); } }

voidkeyscan() { uchar temp; P1=0xff; temp=P1;

temp=temp&0xff; if(temp!=0xff) { delay(10);

temp=P1; if(temp!=0xff) { switch(temp)

{ case 0xfe:

chuankou('A'); shanshuo(temp); break; case 0xfd: chuankou('B');

shanshuo(temp); break;

case 0xfb: chuankou('C'); shanshuo(temp); break; case 0xf7: chuankou('D'); shanshuo(temp);

break; }

while(temp!=0xff)

}

}

{

temp=P1; temp=temp&0xff; } }

voidshanshuo(ucharaa) { ucharss; while(1) {

P0=aa; delay(300); P0=0xff; delay(300); ss=P1; if(ss!=0xff) {

delay(10); ss=P1; if(ss!=0xff) {

switch(ss) {

case 0xfe: chuankou('A'); shanshuo(ss); break; case 0xfd:

chuankou('B'); shanshuo(ss);

break; case 0xfb:

chuankou('C'); shanshuo(ss); break; case 0xf7: chuankou('D');

shanshuo(ss); break; }

}

} } }

voidchuankou(uchar F) {

SBUF=F; while(!TI); TI=0; }

乙机代码: #include #include #define uchar unsigned char #define uint unsigned int voidshanshuo(uintss); void delay(uchari); void delay(uchari) {

ucharj,k;

for(j=i;j>0;j--)

for(k=500;k>0;k--); }

void main() {

uchar a; SCON=0X50; TMOD=0x20; PCON=0x00; TH1=0xfd; TL1=0xfd; RI=0; TR1=1; P0=0xff; while(1) { if(RI) {

RI=0; switch(SBUF)

{ case 'A': a=0xfe;

break; case 'B':

a=0xfd; shanshuo(a); break; case 'C': a=0xfb; shanshuo(a);

break; case 'D': a=0xf7; shanshuo(a); break; }

}

} }

voidshanshuo(uintss) {

uchar a; a=ss; while(1) { P0=ss; delay(300); P0=0xff; delay(300); if(RI) {

RI=0; switch(SBUF)

{ case 'A':

a=0xfe; shanshuo(a);

break; case 'B':

a=0xfd;

shanshuo(a); break;

case 'C':

a=0xfb; shanshuo(a);

}

case 'D':

a=0xf7; shanshuo(a); break; }

} }


相关文章

  • 7研修日记
  • 技 师 研 修 阶 段 个 人 日 记 资 料 班级: 09电气技师1班 姓名: 陆佳卫 10月7日 星期一 雨 今天是技师阶段实习的第一天.对各电脑硬件进行熟悉,识别各硬件,知道这些 硬件所起的作用.并且了解各硬件如何组装.电脑的主机系统 ...查看


  • 直流电机速度控制_
  • 组员: 班级:研1308 授课教师:徐洪泽 计算机控制系统实践--直流电机速度控制 电子信息工程学院 2013-11-24 日期: 目录 1. 2. 整体设计 . ...................................... ...查看


  • 触摸屏收款机说明书
  • 第四代嵌入式触摸屏第四代嵌入式触摸屏 收银机 使 用 说 明 书 收款机使用规范 收款机使用规范 请认真阅读并遵守本规定,以确保您的收款机能正常工作. 1. 在使用过程中,必须采用符合国家标准的带地线的电源. 2. 避免收款机与其它大功率电 ...查看


  • 经典单片机毕业论文
  • PIC单片机的多路温度巡回检测系统 摘要:本文介绍了一种基于PIC16F877A单片机,利用DS18B20对多路温度采集,并进行温度的控制与检测,并通过12864液晶显示出来.系统中通过控制按钮实现了实时各路的报警温度,并且实现多路与任一单 ...查看


  • 超声波传感器的设计与应用
  • 传感器课程设计 (2010级) 题目: 超声波传感器的设计与应用 学员姓名: 学员姓名: xxx 学员姓名: xxx 学号: 学号: [1**********]0 [1**********]7 [1**********]3 xxx 学号: ...查看


  • 经典单片机毕业论文 1
  • 本文由421239245贡献 doc文档可能在WAP端浏览体验不佳.建议您优先选择TXT,或下载源文件到本机查看. PIC 单片机的多路温度巡回检测系统 摘要: 摘要:本文介绍了一种基于 PIC16F877A 单片机,利用 DS18B20 ...查看


  • 用VC 6.0实现串行通信的三种方法
  • 用VC 6.0实现串行通信的三种方法 2004-2-8加入 来自天极论坛 作者yhww 1条评论 点击2964次 摘要: 本文介绍了在Windows 平台下串行通信的实现机制,讨论了根据不同的条件用Visual C++ 设计串行通信程序的三 ...查看


  • 自动化工程训练报告
  • 自动化工程训练 设计报告 学 院: 信息科学与工程学院 班 级: 姓 名: 学 号: 指导老师: 时间:2011年9月7日 目录 一.设计课题名称及要求 .............................. 2 二.设计思想和实施方 ...查看


  • 单片机与pc机串口通信
  • 综合电子课程设计报告 题目:单片机与PC机串口双向数据通信 设计时间:2011年 8 月 22 日至 9 月 9 日 学 院: 电气与信息工程学院 专业名称: 电子信息科学与技术 学 号: [1**********]5 姓 名: 夏攀 指导 ...查看


热门内容