#CHIP 16F877A,4
#CONFIG OSC=XT,WDT_OFF,PWRTE_ON,CP_OFF,DEBUG_OFF,WRT_OFF,CPD_OFF,LVP_OFF,BODEN_ON
On Interrupt ExtInt0 Call Interrupt_RB0
SUB Impulso(Cuenta AS BYTE)#NR
Ciclo_us:
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BSF PORTD,2
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BCF PORTD,2
DECFSZ Cuenta,F
GOTO Ciclo_us
END SUB
SUB Interrupt_RB0()#NR
IntOFF
DO
LOOP UNTIL PORTB.0=1
IF Flag=0 THEN
Flag=1
ELSE
Flag=0
END IF
IntON
END SUB
Inicio:
TRISA=b'000000'
TRISB=b'00000001'
TRISC=b'00000000'
TRISD=b'00000000'
TRISE=b'00000000'
PORTA=b'000000'
PORTB=b'00000000'
PORTC=b'00000000'
PORTD=b'00000000'
PORTE=b'00000000'
INTCON=b'10010000'
OPTION_REG=b'11000000'
CVRCON=b'00000000'
CCP1CON=b'00000000'
CCP2CON=b'00000000'
ADCON0=b'00000000'
ADCON1=b'10000110'
Flag=0
ALTO:
SET PORTB.1 OFF
IF Flag=0 THEN GOTO ALTO
SET PORTB.1 ON
DO
Impulso(0x0C)
LOOP UNTIL Flag=0
GOTO ALTO
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
work,but strangely using this soft pwm to 40 khz the ultrasonic sensor has less lift that when I use the PWM module hardware.
the two modules pwm hardware are in use to control a l298a mode in LAP.
sorry for my english
now it works.
even if you give me problems with the TMR1 interrupt.
all right with the interrupt INT0.
I'm thinking of a NE555 for a burst to 40Khz.
this is the code