环境X IDE V2.35
C
PICKIT3
一个按键切换两个继电器单片机源程序如下:
- #include<pic.h>
- #include <xc.h>
- #pragma config WDTE = OFF // Watchdog Timer (WDT disabled)
- #pragma config CP = OFF // Code Protect (Code protection off)
- #pragma config MCLRE = OFF // Master Clear Enable (GP3/MCLR pin fuction is digital I/O, MCLR internally tied to VDD)
- void DELAY(unsigned int n)
- {
- unsigned int j;
- unsigned int k;
- for(j=0;j<n;j++)
- for(k=200;k>0;k--)
- NOP();
- }
- void main()
- {
- GP0=GP1=GP2=0;
- unsigned char num=0;
- TRISGPIO=0b00001000;
- OPTION=0B010000111;
- OSCCAL=0b11111110;
- while(1)
- {
- if(GP3==0)
- {
- DELAY(20);
- if(GP3==0)
- {
- while(!GP3);
- num++;
- }
-
- }
- if(num==3)
- {
- num=0;
- GP1=GP2=0;
- }
- if(num==1)
- {
- GP1=1;GP2=0;
- }
- if(num==2)
- {
- GP1=0;GP2=1;
- }
- }
- }
复制代码
所有资料51hei提供下载:
一个按键切换两个继电器.rar
(567 Bytes, 下载次数: 43)
|