پاسخ : تاچ خازنی Capacitive Touch
oo:
oo:
، من کل تاپیک رو هم خوندم قبلش بگم :biggrin:
PORTB |= 0x02;
while ( !Touch1 ) آیا این معادل اینه: while(Touch!=0) و این خط هم همینطور if ( PINB.2 && !Touch1) آیا معادل اینه: if(PINB.2&&Touch1!=0)
و اینکه چرا time1 مقدار دهی میشه ولی time5 چک میشه؟؟
)#include <mega8.h>
#include <delay.h>
volatile unsigned int time,tedad_overflow;
interrupt [TIM0_OVF] void timer0_ovf_isr(void){
++tedad_overflow;
}
void main(){
DDRD=0x00;
PORTD=0x00;
DDRB=0xff;
PORTB=0x00;
TCCR0=0x01;
TCNT0=0x00;
TIMSK=0x01;
#asm("sei")
while(1){
PORTB|=0x80;
TCCR0=0x01;
while(PIND.0==0);
TCCR0=0x00;
time=(tedad_overflow*255)+TCNT0;
tedad_overflow=0;
PORTD.0=0;
PORTB&=0x7f;
if(time>=320) PORTB.6=1;
else PORTB.6=0;
}
}
، من کل تاپیک رو هم خوندم قبلش بگم :biggrin:
و اینکه چرا time1 مقدار دهی میشه ولی time5 چک میشه؟؟
)#include <mega8.h>
#include <delay.h>
volatile unsigned int time,tedad_overflow,tedad_anjam;
interrupt [TIM0_OVF] void timer0_ovf_isr(void){
++tedad_overflow;
}
void after_touch(){
#asm("cli")
اینجا هر کاری که بعد از تشخیص تاچ شدن میخواین انجام بدین رو بنویسید
#asm("sei")
}
void main(){
DDRD=0x00;
PORTD=0x00;
DDRB=0xff;
PORTB=0x00;
TCCR0=0x01;
TCNT0=0x00;
TIMSK=0x01;
#asm("sei")
while(1){
PORTB|=0x10;
TCCR0=0x01;
while(PIND.0==0);
TCCR0=0x00;
time=(tedad_overflow*255)+TCNT0;
tedad_overflow=0;
TCNT0=0;
PORTD.0=0;
PORTB&=0xef;
if(time>=320) {
++tedad_anjam;
if(tedad_anjam==1){
after_touch();
}
}
if(time<=280) tedad_anjam=0;
delay_ms(10);
}
}
دیدگاه