Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to make 3Second TURN (ON/OFF) Button for PIC16F877A ??

Status
Not open for further replies.

wilker_dias

Newbie level 3
Joined
Oct 20, 2009
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
brazil
Activity points
1,309
HI, good nigth everyone ..

I´m making a memory gam with 8 button and a need a help how to make a C program in CCS COMPILER

for to make such task :
- if the button D1 is pressed Hold during 3 seconds turn ON the PIC.
- and if the button D1 is pressed Hold again during 3 seconds turn OFF the PIC.


What kind of method should I use .. => INTERRUPTS, TIMERS , WDT, POWER UP ??

Thanks ya since now ...
 
Last edited:

Hi wilker ,

You can use any method as per your requirment ..

use timer for delay and hold.
Use external interrupt (button ), sleep and watchdog timer for turning on PIC.
try these link..

https://embedded-lab.com/blog/?p=3237

Best regards,
 

thank you mr. jinz .
I READ THAT article of link ..
BUT , I need something more specific that use tha same button and lesson me how measure the time that button is pressed... for turn ON and OFF in C language .. :-D :-D
 

If button is pressed and hold then start a timer immediately when button is pressed and count for 3 sec and check if button is pressed on every interrupt of say 10 ms till 3 sec. If yes then execute whatever code has to be executed. Similar for OFF button.
 

yeah its basicly like that , but when the time of button pressed taked 3 second turn on the micro , and only is possible to turn off if the button was released and pressed again during 3 second .... I just need a simple sample of how to make something like that THANKS !!
If button is pressed and hold then start a timer immediately when button is pressed and count for 3 sec and check if button is pressed on every interrupt of say 10 ms till 3 sec. If yes then execute whatever code has to be executed. Similar for OFF button.
 

This is not a complete code. You have to add codes for sleep and wakeup.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//PIC16F 4 MHz External Clock
 
 
#define SW PORTB.F0     //RB0 is used for SW
 
unsigned char time, buttonPressed = 0;
 
//Timer1
//Prescaler 1:1; TMR1 Preload = 60535; Actual Interrupt Time : 5 ms
 
//Place/Copy this part in declaration section
void InitTimer1(){
  T1CON  = 0x01;
  TMR1IF_bit     = 0;
  TMR1H  = 0xEC;
  TMR1L  = 0x77;
  TMR1IE_bit     = 1;
  INTCON     = 0xD8;
}
 
void Interrupt(){
  if (TMR1IF_bit){ 
    TMR1IF_bit = 0;
    
    
    //Enter your code here
    if((SW == 1) && (buttonPressed == 1)){
        time++;
        if(time == 200){
            // put code needed to put PIC in sleep mode here
        }       
    }
    else if((SW == 1) && (buttonPressed == 0)){
        time++;
        if(time == 200){
            // put code needed to wakeup PIC from sleep here
        }       
    }   
    
    TMR1H    = 0xEC;
    TMR1L    = 0x77;
  }
  
  if(INT0IF_bit){
      
      INT0IF_bit = 0;
      
      buttonPressed = ~buttonPressed;   // 0 = ON, 1 = OFF
      time = 0;
  }
} 
 
void main(){
    
    
    TRISB = 0x01;
    PORTB = 0x00;
    
    OPTION_REG = 0x40;
    
    InitTimer1();
    
    while(1){
        
        ;
        
    }   
}

 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top