Jump to content
ELFORUM - Forumul electronistilor

Numarat cate apasari pe buton sunt in x sec.


critix

Recommended Posts

SalutDoresc sa fac un montaj cu pic in felul urmator: am un boton care poate fi apasat ori o data ori de 2 ori,in max 4 secunde... doresc ca pe o iesire de la pic, atunci cand am o singura apasare, sa tin pe 1 iesirea pt 150 ms, iar cand am 2 apasari sa tin 450 ms.Problema e ca nu stiu cum pot contoriza cate apasari am in acest interval.Ma puteti ajuta cu un sfat? Multumesc

Link to comment
  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

  • nooob64

    1

  • critix

    1

Popular Days

Top Posters In This Topic

Utilizezi un timer pe care il setezi la o anumita frecventa si cu un contor cronometrezi cite secunde au trecut , apoi butonul tau va fii legat la o intrare (inrerupere hardware) INT0 (RB0 in general) dar va trebuii setat si acel bit al portului ca sa aibe functia dorita , iar cu un contor numeri cite intreruperi externe ai primit ...

Dupa ce contorul timerului a ajuns la o valoare x specifica cu n secunde te pui si verifici de cite ori sa incrementat contorul intreruperii externe .

 

Am facut un programel in C pentru un turometru , este cam varzalit putin dar cred ca iti va da o idee

#define MENIU_STOP 1#define MENIU_START 2#define BUTON_BK 1#define BUTON_FW 2#define BUTON_ST 3// LCD module connectionssbit LCD_RS at RB2_bit;sbit LCD_EN at RB3_bit;sbit LCD_D4 at RB4_bit;sbit LCD_D5 at RB5_bit;sbit LCD_D6 at RB6_bit;sbit LCD_D7 at RB7_bit;sbit LCD_RS_Direction at TRISB2_bit;sbit LCD_EN_Direction at TRISB3_bit;sbit LCD_D4_Direction at TRISB4_bit;sbit LCD_D5_Direction at TRISB5_bit;sbit LCD_D6_Direction at TRISB6_bit;sbit LCD_D7_Direction at TRISB7_bit;// End LCD module connectionsunsigned char scan_taste(){ if(PORTA.F1) return 1; if(PORTA.F2) return 2; if(PORTA.F3) return 3;  return 0;}void afisare_numar(unsigned int x,unsigned char y,unsigned char z,unsigned char q){unsigned int ch=0;  ch = x / 10000;  Lcd_Chr(y, z, 48 + ch);  ch    = (x / 1000) % 10;  Lcd_Chr_Cp(48 + ch);  ch    = (x / 100) % 10;  Lcd_Chr_Cp(48 + ch);  ch    = (x / 10) % 10;  Lcd_Chr_Cp(48 + ch);  if(q) Lcd_Chr_CP('.');  ch    = x % 10;  Lcd_Chr_Cp(48 + ch);}unsigned int set_t = 250,pas = 50,contor_ms=0,contor_nr=0;unsigned char meniu = 1,key = 0,key_old = 0,contor_timer0=0,numar=0;unsigned int contor_aux=0,var=0;void interrupt(){if (INTCON.T0IF == 1) // timer 0 interrupt flag{    contor_ms++;    INTCON.T0IF = 0;    INTCON.T0IE = 1;    TMR0 =55;           // reset the timer preset count}if(INTCON.INTF){ if(numar) {   PORTA.F0 = 1;   contor_nr++;   if(contor_nr == set_t)   {   PORTA.F0 = 0;   contor_nr = 0;   numar = 0;   meniu = MENIU_STOP;   }  }  contor_aux = contor_ms;  contor_ms = 0; INTCON.INTF = 0;}}void main() {PORTA = 0;TRISA = 0b00001110;PORTB = 0;TRISB = 0b00000001;CMCON = 7;  //disable comparatorsVRCON = 0;//Timer0 Registers Prescaler= 1 - TMR0 Preset = 56 - Freq = 10000.00 Hz - Period = 0.000100 secondsOPTION_REG.T0CS = 0;  // bit 5  TMR0 Clock Source Select bit...0 = Internal Clock (CLKO) 1 = Transition on T0CKI pinOPTION_REG.T0SE = 0;  // bit 4 TMR0 Source Edge Select bit 0 = low/high 1 = high/lowOPTION_REG.PSA = 1;   // bit 3  Prescaler Assignment bit...0 = Prescaler is assigned to the WDTOPTION_REG.PS2 = 0;   // bits 2-0  PS2:PS0: Prescaler Rate Select bitsOPTION_REG.PS1 = 0;OPTION_REG.PS0 = 0;TMR0 = 55;             // preset for timer registerOPTION_REG.INTEDG = 1; // intrerupere pe front crescatorINTCON.T0IE = 0;        // bit2 clear timer 0 interrupt flagINTCON.INTE = 1; //RB0 external interrupt pic onINTCON.GIE = 1; // interrupt enableLcd_Init();                        // Initialize LCD   Lcd_Cmd(_LCD_CLEAR);               // Clear display   Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off   Lcd_Out(1,1,"RPM:");   Lcd_Out(2,1,"SET:");while(1){ //citire butoane  key = scan_taste();  if(key == key_old)         key = 0;    if(9003/(float)contor_aux <= 105) // 105 RPS     {     afisare_numar((float)(9009/(float)contor_aux)*10*60,1,5,1);     }    else    Lcd_Out(1,5,"ERR.");   afisare_numar(set_t,2,5,0);   afisare_numar(contor_nr,2,12,0); switch(meniu) {     case MENIU_STOP:     PORTA.F0 = 0;     contor_nr = 0;     numar = 0;      if(key == BUTON_ST)        meniu = MENIU_START;      if(key == BUTON_BK)             if(set_t > pas)             set_t-=pas;                    if(key == BUTON_FW)             if(set_t < 5000)             set_t+=pas;        Lcd_Out(1,12,"STOP ");     break;          case MENIU_START:      numar = 1;       if(key == BUTON_ST)        meniu = MENIU_STOP;        Lcd_Out(1,12,"NUMAR");             break;          default:     break; }key_old = scan_taste();delay_ms(100);}}
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.Terms of Use si Guidelines