PIC单片机如何实现单按键输入LED灯点亮.doc

上传人:白大夫 文档编号:3270703 上传时间:2019-08-07 格式:DOC 页数:3 大小:18KB
返回 下载 相关 举报
PIC单片机如何实现单按键输入LED灯点亮.doc_第1页
第1页 / 共3页
亲,该文档总共3页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《PIC单片机如何实现单按键输入LED灯点亮.doc》由会员分享,可在线阅读,更多相关《PIC单片机如何实现单按键输入LED灯点亮.doc(3页珍藏版)》请在三一文库上搜索。

1、PIC单片机如何实现单按键输入LED灯点亮IO输出和输入/*按键连接RB1,点亮LED,PORTA RA0控制输出。按一次点亮,再按一次熄灭,如此循环。RB外接上拉电阻。*/#include#define uchar unsigned char#define uint unsigned int/ CONFIG#pragma config FOSC = HS /#pragma config WDTE = OFF / Watchdog Timer Enable bit (WDT disabled)#pragma config PWRTE = OFF / Power-up TImer Enable

2、bit (PWRT disabled)#pragma config BOREN = ON / Brown-out Reset Enable bit (BOR enabled)#pragma config LVP = ON / Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3/PGM pin has PGM funcTIon; low-voltage programming enabled)#pragma config CPD = OFF / Data EEPROM Memory Code Prot

3、ecTIon bit (Data EEPROM code protecTIon off)#pragma config WRT = OFF / Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)#pragma config CP = OFF / Flash Program Memory Code Protection bit (Code protection off)uchar count;void delay(ui

4、nt x)uint y,z;for(y=x;y0;y-)for(z=25;z0;z-);void Init_GPIO()TRISA = 0X00; / RA0 output directionPORTA=0X00;TRISB = 0x02; / RB1 inputPORTB = 0x00;void Keyscan()/temp = PORTBif(RB1=0)delay(200); / delay time 根据机械按键的抖动情况调整,if(RB1=0)count+;void main(void)count = 0;Init_GPIO();while(1)Keyscan();if(count%2)=1)PORTA=0x01;elsePORTA = 0x00;

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

当前位置:首页 > 其他


经营许可证编号:宁ICP备18001539号-1