完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
各位走过路过的大神OR初学者,小弟刚接触单片机,现在想编写一个程序实现这样的功能:开关(SwitchH)按下,通道1(CHAN1)通路,按下一个(DOWN_BUTTON)通道2(CHAN2)通路,以此类推。如下代码请各位看看错在哪里:
#include typedef unsigned char u8; typedef unsigned int u16; ***it CHAN1 = P0^0; ***it CHAN2 = P0^1; ***it CHAN3 = P0^2; ***it CHAN4 = P0^3; ***it CHAN5 = P0^4; ***it CHAN6 = P0^5; ***it CHAN7 = P0^6; ***it CHAN8 = P0^7; ***it CHAN9 = P2^0; ***it CHAN10 = P2^1; ***it SwitchH = P1^5; ***it UP_BUTTON = P1^6; ***it DOWN_BUTTON = P1^7; void dealy(unsigned int y) { unsigned int x,z; for(x = y;x > 0;x--) for(z = 110;z > 0;z--); } void main() { CHAN1 = 1; CHAN2 = 1; CHAN3 = 1; CHAN4 = 1; CHAN5 = 1; CHAN6 = 1; CHAN7 = 1; CHAN8 = 1; CHAN9 = 1; CHAN10 = 1; SwitchH = 1; UP_BUTTON = 1; DOWN_BUTTON = 1; while(1) { dealy(10); if (SwitchH == 0) { CHAN1 = 0; } if (CHAN1 == 0) { if (DOWN_BUTTON == 0) { CHAN1 = 1; CHAN2 = 0; } if (SwitchH == 0) { CHAN1 = 1; } } if (CHAN2 == 0) { if (DOWN_BUTTON == 0) { CHAN3 = 0; CHAN2 = 1; } if (UP_BUTTON == 0) { CHAN1 = 0; CHAN2 = 1; } if (SwitchH == 0) { CHAN2 = 1; } } if (CHAN3 == 0) { if (DOWN_BUTTON == 0) { CHAN4 = 0; CHAN3 = 1; } if (UP_BUTTON == 0) { CHAN2 = 0; CHAN3 = 1; } if (SwitchH == 0) { CHAN3 = 1; } } if (CHAN4 == 0) { if (DOWN_BUTTON == 0) { CHAN5 = 0; CHAN4 = 1; } if (UP_BUTTON == 0) { CHAN3 = 0; CHAN4 = 1; } if (SwitchH == 0) { CHAN4 = 1; } } if (CHAN5 == 0) { if (DOWN_BUTTON == 0) { CHAN6 = 0; CHAN5 = 1; } if (UP_BUTTON == 0) { CHAN4 = 0; CHAN5 = 1; } if (SwitchH == 0) { CHAN5 = 1; } } if (CHAN6 == 0) { if (DOWN_BUTTON == 0) { CHAN7 = 0; CHAN6 = 1; } if (UP_BUTTON == 0) { CHAN5 = 0; CHAN6 = 1; } if (SwitchH == 0) { CHAN6 = 1; } } if (CHAN7 == 0) { if (DOWN_BUTTON == 0) { CHAN8 = 0; CHAN7 = 1; } if (UP_BUTTON == 0) { CHAN6 = 0; CHAN7 = 1; } if (SwitchH == 0) { CHAN7 = 1; } } if (CHAN8 == 0) { if (DOWN_BUTTON == 0) { CHAN9 = 0; CHAN8 = 1; } if (UP_BUTTON == 0) { CHAN7 = 0; CHAN8 = 1; } if (SwitchH == 0) { CHAN8 = 1; } } if (CHAN9 == 0) { if (DOWN_BUTTON == 0) { CHAN10 = 0; CHAN9 = 1; } if (UP_BUTTON == 0) { CHAN8 = 0; CHAN9 = 1; } if (SwitchH == 0) { CHAN9 = 1; } } if (CHAN10 == 0) { if (UP_BUTTON == 0) { CHAN9 = 0; CHAN10 = 1; } if (SwitchH == 0) { CHAN10 = 1; } } } } 谢谢各位 |
|
相关推荐
1个回答
|
|
顶回去
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
464 浏览 0 评论
478 浏览 1 评论
基于瑞萨FPB-RA4E2智能床头灯项目——1编译环境搭建与点亮驱动ws2812全彩LED
439 浏览 0 评论
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-LCD显示图片编程示例之介绍mmap
994 浏览 0 评论
《DNESP32S3使用指南-IDF版_V1.6》第二章 常用的C语言知识点
1056 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
11788 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-25 16:37 , Processed in 0.582630 second(s), Total 75, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号