Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

ps/2, pic external interrupt problem

Status
Not open for further replies.

v1r05

New Member
helllllllllo eveybody

i have this project where the use of ps2 mouse is required and i am having real problem interfacing it to the micro, i am using the 16f877a.
the clock of the ps/2 is pulled high by a pull-up resistor and connected to the external interrupt pin B0.
the data pin is connected to pin D2 and also pulled high

now i am able to monitor the signal using the pickit2, when the mouse is powered up it sends 0xAA 0x00 bytes, i am able to confirm that. here is the img

**broken link removed**

the problem is when i try read the signal using the microcontroller i faild, even when simply just trying to count the clock pulses at PIN B0 during mouse power up
Code:
#int_EXT
void  EXT_isr(void) 
{
   pulses++;
}
.
.
.
void main()
{
   pulses = 0;

   .
   .......PIC initialization code.........
   .
   ext_int_edge( H_TO_L ); //track high to low transitions on pin
   enable_interrupts(INT_EXT);// enable external interrupt
   enable_interrupts(GLOBAL);

   set_tris_b(0xff);
   while(true)
   {
      printf("pulses: %u\r\n",pulses);
      delay_ms(500);
   
   }


}

the output of the code:
pulses: 1
where it should be 22 i belive

here is what i tried to do :
- remove the pickit2 while the pic is doing its job trying to count them pulses
- remove the pullup resistors
- enable/disable portb weak pull ups
- re-enable the ext_int at the ISR
- simulating with protues isis gives correct result !!!

i dont know whats wrong + ive been trying to solve it for 2 days so any suggestions are highly appreciated !!

thanks for reading.
 
Post all your code instead of where you think the problem is. A few questions/suggestions, is the wdt turned off, how and where is pulses defined, which compiler are you using.

Mike.
 
ok this the code

Code:
#include <16F877A.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected

#use delay(clock=20000000)
#use rs232(baud=57600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#use fast_io (B)

volatile unsigned int x;

#int_EXT
void  EXT_isr(void) 
{
   disable_interrupts(INT_EXT);
   
   x++;
   
   clear_interrupt(INT_EXT);
   enable_interrupts(INT_EXT);
}


void main()
{
   x =0;
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);
   port_b_pullups (false);
   
   while(1)
   {
   
      printf("%u\r\n",x); 
      delay_ms(1000);
   
   }

}

this driving me crazy please help...
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top