标题: PIC10F202做的一个按键切换两个继电器 [打印本页]

作者: gravedigger    时间: 2018-2-19 00:17
标题: PIC10F202做的一个按键切换两个继电器
环境X IDE V2.35
   C
  PICKIT3
一个按键切换两个继电器单片机源程序如下:
  1. #include<pic.h>
  2. #include <xc.h>

  3. #pragma config WDTE = OFF       // Watchdog Timer (WDT disabled)
  4. #pragma config CP = OFF         // Code Protect (Code protection off)
  5. #pragma config MCLRE = OFF      // Master Clear Enable (GP3/MCLR pin fuction is digital I/O, MCLR internally tied to VDD)

  6. void DELAY(unsigned int n)
  7. {

  8.     unsigned int j;
  9.     unsigned int k;
  10.     for(j=0;j<n;j++)
  11.         for(k=200;k>0;k--)
  12.             NOP();
  13. }

  14. void main()
  15. {
  16.     GP0=GP1=GP2=0;
  17.     unsigned char num=0;

  18.     TRISGPIO=0b00001000;
  19.     OPTION=0B010000111;
  20.     OSCCAL=0b11111110;
  21.     while(1)
  22.     {
  23.         if(GP3==0)
  24.         {
  25.             DELAY(20);
  26.             if(GP3==0)
  27.             {
  28.              while(!GP3);
  29.             num++;
  30.             }
  31.            
  32.         }
  33.             if(num==3)
  34.                 {
  35.                     num=0;
  36.                     GP1=GP2=0;
  37.                 }
  38.         if(num==1)
  39.         {
  40.             GP1=1;GP2=0;
  41.         }
  42.         if(num==2)
  43.         {
  44.             GP1=0;GP2=1;
  45.         }

  46.     }
  47. }
复制代码

所有资料51hei提供下载:
一个按键切换两个继电器.rar (567 Bytes, 下载次数: 43)





作者: xianrui1989    时间: 2018-9-18 17:23
谢谢论坛,正在找关于F202的程序




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1