อีกอย่างนึงคับ ช่วยดูที

Started by pomcoe, March 23, 2013, 04:47:27 PM

Previous topic - Next topic

pomcoe

ก็คือว่าผมใช้ เซนเซอร์ตรวจความเคลื่อนไหวคับ

การทำงานคือว่าเมื่อมีคนเข้ามาแล้วให้ไฟติดและ delay 2 นาที
   แต่ว่าในขณะที่มัน delay 2นาที อยู่ ถ้าเกิดเจอความเคลื่อนไหวก็ให้มันเริ่มนับ delay ใหม่คับ
แก้ code ไงดีคับ

#include <16F88.h>         // Standard Header file for the PIC16F877A
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, NOPUT, NOLVP 
#use delay(clock=10000000)   
int i,j;


void delay_2min(void){
      for(j=0;j<120;j++){
      delay_ms(1000);
      }}   

void main(void)
{
   set_tris_a(0x07);
   set_tris_b(0x00);
   output_b(0x00);
   delay_ms(200);
   while(TRUE)
{       
   if(input(PIN_A0))     
      {
       output_high(PIN_B0);
       if(input(PIN_A0))
         {
         output_high(PIN_B0);
         }
         delay_2min();
         output_high(PIN_B0);
      }
      output_low(PIN_B0);
}
}




nont_peet

int16 i=0;
void mian()
{
if(pir==1){i=120;}// 60*2

if(i>0){high;i--;}else{low;}
delay_ms(1000);
}
คนรักหุ่นยนต์

firmware.c

อันดับแรกอย่าใช้ software delay ให้ใช้ interrupt timer เป็นตัวช่วย
IAR Embedded Workbench for ARM
AVR-Studio + AVR-GCC
CodeBlocks + MinGw
CodeBlocks + Gtk+


pomcoe

Quote from: firmware.c on March 23, 2013, 10:22:52 PM
อันดับแรกอย่าใช้ software delay ให้ใช้ interrupt timer เป็นตัวช่วย

interrupt ไม่เป็นไงคับ

zilog

Quote from: pomcoe on March 24, 2013, 01:17:38 AM
Quote from: firmware.c on March 23, 2013, 10:22:52 PM
อันดับแรกอย่าใช้ software delay ให้ใช้ interrupt timer เป็นตัวช่วย

interrupt ไม่เป็นไงคับ

ถ้า interrupt ไม่เป็น ก็ใช้การ Polling ก็ได้
http://home.kku.ac.th/regis/student/snakiiz/New%20Folder/15.html

อ้อ ท่าน pomcoe ครับ ภาษาไทย ควรใช้ให้ถูกต้องด้วยครับ
อย่าง "interrupt ไม่เป็นไงคับ"
อาจแก้เป็น  "interrupt ทำไม่เป็น ทำอย่างไรครับ"

เขียนคำถามให้เหมาะสม เป็นการให้เกียรติกับผู้ตอบนะครับ

pomcoe


olee

อันนี้ Project ใหม่หรือครับ สรุปแล้วอันเก่า sensor IR ใช้ได้แล้ว.....?

pomcoe

Quote from: olee on March 24, 2013, 08:58:07 PM
อันนี้ Project ใหม่หรือครับ สรุปแล้วอันเก่า sensor IR ใช้ได้แล้ว.....?
ได้แล้วคับ