พิมพ์หน้านี้ - ช่วยหน่อยครับ CCS pic 16f627a

LSVคลังสมองออนไลน์ "ปีที่21"

ห้องโครงงาน - D.I.Y.- เทคโนโลยี่ => ►ถาม-ตอบโครงงาน => ข้อความที่เริ่มโดย: beeking ที่ เมษายน 25, 2015, 10:56:43 AM



หัวข้อ: ช่วยหน่อยครับ CCS pic 16f627a
เริ่มหัวข้อโดย: beeking ที่ เมษายน 25, 2015, 10:56:43 AM
คือผมอยากทราบว่าจะเพิ่มให้ถ้ากดสวิตพร้อมกัน 3 ปุ่มจะให้หยุดการทำงานครับ มือใหม่ครับ  เงื่อนไขมีอยู่ว่า
1. กดสวิต 1 ดีเลย์ตัวที่ 1 ทำงาน
2. กดสวิต 2 ดีเลย์ตัวที่ 1และตัวที่ 2  ทำงานพร้อมกัน
3. กดสวิต 3 ดีเลย์ตัวที่ 2 ทำงาน
4. กดสวิต พร้อมกัน 3 ตัว ดีเลย์หยุดการทำงานทั้ง 2 ตัว

โค๊ดที่เขียนครับ
#include <16F627A.h>
#fuses HS,NOWDT,NOWDT,NOPROTECT,NOLVP
#use delay (clock=40000000)
void main(void)
{
      set_tris_b(0x00);
      set_tris_a(0xFF);
     
      while(TRUE){
            if (!input(PIN_A0))
           
                  {
                  output_high(PIN_B0);
                  delay_ms(500);
                  }
                if (input(PIN_A0))
                  {
                  output_low(PIN_B0);
                  }
            if (!input(PIN_A1))
                  {
                  output_high(PIN_B0);
                  output_high(PIN_B3);
                  delay_ms(500);
                  }
                if (input(PIN_A1))
                  {
                  output_low(PIN_B0);
                  output_low(PIN_B3);
                  }
            if (!input(PIN_A2))
                  {
                  output_high(PIN_B3);
                  delay_ms(500);
                  }
                if (input(PIN_A2))
                  {
                  output_low(PIN_B3);
                  }
           
      }
}(http://upic.me/i/dx/hr351.jpg) (http://upic.me/show/55322070)
(http://upic.me/i/vn/324t2.jpg) (http://upic.me/show/55322071)
(http://upic.me/i/j7/peb-16f62x.png) (http://upic.me/show/55322072)


หัวข้อ: Re: ช่วยหน่อยครับ CCS pic 16f627a
เริ่มหัวข้อโดย: empirejrz ที่ กรกฎาคม 07, 2015, 07:58:48 PM
(http://i.imgur.com/qLqbR4il.jpg)
เงื่อนไขที่ 1
(http://i.imgur.com/TfEK0bDl.jpg)
เงื่อนไขที่ 2
(http://i.imgur.com/ECtRgiTl.jpg)
เงื่อนไขที่ 3

เงื่อนไขสุดท้ายเป็นเงื่อนไข Default อยู่แล้ว

มีอยู่ 2 File นะครับ
.C กับ .H
ได้ไม่ได้อย่างไร ใช้งานไม่ได้แจ้งด้วยนะครับ
/*
                             *******************
******************************* C HEADER FILE *******************************
**                           *******************                           **
**                                                                         **
** project      :                                                          **
** filename     :                                                          **
** version      :                                                          **
** date         :                                                          **
**                                                                         **
*****************************************************************************
**                                                                         **
** Copyright (c) 2015                                                      **
** All rights reserved.                                                    **
**                                                                         **
*****************************************************************************
 
VERSION HISTORY:
-------------------------
 
Version         :   
Date            :   
Revised by      :   
Description     :   
 
*/
#ifndef   _SW_CASE_TEST_INCLU DED
#define   _SW_CASE_TEST_INCLU DED
/****************************************************************************/
/**                                                                        **/
/**                                       MODULES USED                     **/
/**                                                                        **/
/****************************************************************************/
#include   "16F627A.h"
#include    "CTYPEDAT.H"
/****************************************************************************/
/**                                                                        **/
/**                              DEFINITIONS AND MACROS                    **/
/**                                                                        **/
/****************************************************************************/
#fuses HS,NOWDT,NOWDT,NOPROTECT,NOLVP
#use delay (clock=40000000)

//Define PIN input
#define A0 PIN_A0
#define A1 PIN_A1
#define A2 PIN_A2

//Define PIN output
#define B0 PIN_B0
#define B1 PIN_B1
#define B2 PIN_B2
#define B3 PIN_B3
/****************************************************************************/
/**                                                                        **/
/**                              TYPEDEFS AND STRUCTURES                   **/
/**                                                                        **/
/****************************************************************************/
 
/****************************************************************************/
/**                                                                        **/
/**                              EXPORTED VARIABLES                        **/
/**                                                                        **/
/****************************************************************************/
#ifndef _SW_CASE_TEST_C_SRC
#endif
/****************************************************************************/
/**                                                                        **/
/**                              EXPORTED FUNCTIONS   PROTOTYPE            **/
/**                                                                        **/
/****************************************************************************/
#endif
/****************************************************************************/
/**                                                                        **/
/**                              EOF                                       **/
/**                                                                        **/
/****************************************************************************/


/*
                             *******************
******************************* C SOURCE FILE *******************************
**                           *******************                           **
**                                                                         **
** project      :                                                          **
** filename     :                                                          **
** version      :                                                          **
** date         :                                                          **
**                                                                         **
*****************************************************************************
**                                                                         **
** Copyright (c) 2015                                                      **
** All rights reserved.                                                    **
**                                                                         **
*****************************************************************************
 
VERSION HISTORY:
------------------------
 
Version         :   
Date            :   
Revised by      :   
Description     :   
 
*/
#define _SW_CASE_TEST_C_SRC
/****************************************************************************/
/**                                                                        **/
/**                                 MODULES USED                           **/
/**                                                                        **/
/****************************************************************************/
#include   "SW_CASE_TEST.H"
/****************************************************************************/
/**                                                                        **/
/**                                 DEFINITIONS AND MACROS                 **/
/**                                                                        **/
/****************************************************************************/

/****************************************************************************/
/**                                                                        **/
/**                                 TYPEDEFS AND STRUCTURES                **/
/**                                                                        **/
/****************************************************************************/
 
/****************************************************************************/
/**                                                                        **/
/**                                 PROTOTYPES OF LOCAL FUNCTIONS          **/
/**                                                                        **/
/****************************************************************************/
void Idie(void);
void SET_D1(void);
void SET_D2(void);
void SET_D1_D2(void);
/****************************************************************************/
/**                                                                        **/
/**                                 EXPORTED VARIABLES                     **/
/**                                                                        **/
/****************************************************************************/
 
/****************************************************************************/
/**                                                                        **/
/**                                 GLOBAL VARIABLES                       **/
/**                                                                        **/
/****************************************************************************/
 
/****************************************************************************/
/**                                                                        **/
/**                                 EXPORTED FUNCTIONS                     **/
/**                                                                        **/
/****************************************************************************/
 
/****************************************************************************/
/**                                                                        **/
/**                                 LOCAL FUNCTIONS                        **/
/**                                                                        **/
/****************************************************************************/
void main(void)
{
   set_tris_b(0x00);
   set_tris_a(0xFF);   

   while(1)               //Forever loop
   {
      if(input(A0) == 1)                           //Check input A0
      {
         SET_D1();
      }
      else if(input(A1) == 1)                        //Check input A1
      {
         SET_D1_D2();
      }
      else if(input(A2) == 1)                        //Check input A2
      {
         SET_D2();
      }
      else if((input(A0)&&input(A1)&&input(A2)) == 1)      //Check input A0 and A1 and A2 will be equal 1
      {
         Idie();
      }
      else                                    //Default jump to function below
      {
         Idie();
      }
   }
}

void Idie(void)                  //Default and input A0 , A1 , A2 == 1
{
   output_high(B3);
   output_high(B0);   
   delay_ms(500);
}

void SET_D1(void)               //When input A0 == 1
{
   output_low(B0);
}

void SET_D2(void)               //When input A1 == 1
{
   output_low(B3);
}

void SET_D1_D2(void)            //When input A2 == 1
{
   output_low(B0);
   output_low(B3);
}
/****************************************************************************/
/**                                                                        **/
/**                                 EOF                                    **/
/**                                                                        **/
/****************************************************************************/