pic16f887 as counter

Status
Not open for further replies.

Chirag R. Patel

Newbie level 3
Joined
Apr 9, 2014
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
18
hello everyone
i want to make the programme on pic16f887.
i want to press RA4 pin 5 times and at fifth time RD0 should be on.
how to do that i tried too much but i couldnt do that
olz hepl me
thanks

#include <htc.h>
#define _XTAL_FREQ 4000000
void main()
{
ANSEL = 0;
ANSELH = 0;
PORTA=0;
TRISA = 1;
TMR0 = 0;
GIE = 0;
PEIE = 0;
T0IE = 0;
T0IF = 0;
T0CS = 1;
T0SE = 0;
PSA= 0;
PS0 = 0;
PS1 = 0;
PS2 = 0;

while(1)
{
}
static void interrupt isr();
{

if (T0IF==1)
GIE=0;
//if(TMR0==5) {
RD0=1;
//{
//RD0 = 1;
//}

}
}
 

Try this.


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
#include <htc.h>
 
#define _XTAL_FREQ 4000000 
 
#define LED PORTDbits.RD0
 
 
unsigned char counter = 0;
 
void main() {
 
    ANSEL = 0x00;
    ANSELH = 0x00;
 
    TRISA = 0x10;
    PORTA = 0x00;
    
    TRISB = 0x00;
    PORTB = 0x00;
 
    TRISC = 0x80;
    PORTC = 0x00;
    
    TRISD = 0x00;
    PORTD = 0x00;   
 
    while(1) {
        
        if((PORTA & 0x10) && (counter < 5)) {
            _delay_ms(50);
            while((PORTA & 0x10) && (counter < 5));
            ++counter;
        }
 
        if(counter == 5) {
            LED = 1;
            counter = 0;
        }
 
    }
}

 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…