aadhyatm
Member level 1
- Joined
- Jan 30, 2007
- Messages
- 36
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- Kanpur, Uttar Pradesh, India
- Activity points
- 1,537
Dear all,
I need to program 12F675 using Mikrobasic, Program should count key press on gp5 and should give 2 short pulses on gp0 when counter=8, counter is reset at 10.
so far I had written this, As I am thinking of using a timer later, hence that code is included as well, Trying to simulate on proteus but output gp0 is always low.
program Count_12F675
dim cnt,EN as byte
Dim PP as longint
sub procedure interrupt
cnt = cnt + 1
TMR0 = 96
INTCON = 0x20
end sub
main:
OPTION_REG = 0x84
ANSEL = 0
TRISIO.5 = 1
TRISIO.4 = 0
TRISIO.3 = 0
TRISIO.2 = 0
TRISIO.1 = 0
TRISIO.0 = 0
CMCON=7
GPIO=0
TMR0 = 96
INTCON = 0xA0
cnt = 0
EN=0
While true
IF (GPIO.5=1) AND (EN=0) THEN 'check for high
DELAY_uS(500)
IF (GPIO.5=1) AND (EN=0) THEN
PP=PP+1 'count pulses
EN=1
END IF
END IF
IF (GPIO.5=0) AND (EN=1) THEN 'Check for low
DELAY_uS(500)
IF (GPIO.5=0) AND (EN=1) THEN
EN=0
END IF
END IF
IF PP>10 THEN 'Reset Count
PP=0
END IF
IF PP=8 THEN 'give two blinks
GPIO.0=1
Delay_ms(800)
GPIO.0=0
Delay_ms(800)
GPIO.0=1
Delay_ms(800)
GPIO.0=0
ELSE
GPIO.0=0
END IF
Wend
end.
And here is schematic from proteus
Edit:-Sorry for mistake in proteus it is working Well after adding PP=PP+1 after giving 2 pulses, but it is not working on board
I need to program 12F675 using Mikrobasic, Program should count key press on gp5 and should give 2 short pulses on gp0 when counter=8, counter is reset at 10.
so far I had written this, As I am thinking of using a timer later, hence that code is included as well, Trying to simulate on proteus but output gp0 is always low.
program Count_12F675
dim cnt,EN as byte
Dim PP as longint
sub procedure interrupt
cnt = cnt + 1
TMR0 = 96
INTCON = 0x20
end sub
main:
OPTION_REG = 0x84
ANSEL = 0
TRISIO.5 = 1
TRISIO.4 = 0
TRISIO.3 = 0
TRISIO.2 = 0
TRISIO.1 = 0
TRISIO.0 = 0
CMCON=7
GPIO=0
TMR0 = 96
INTCON = 0xA0
cnt = 0
EN=0
While true
IF (GPIO.5=1) AND (EN=0) THEN 'check for high
DELAY_uS(500)
IF (GPIO.5=1) AND (EN=0) THEN
PP=PP+1 'count pulses
EN=1
END IF
END IF
IF (GPIO.5=0) AND (EN=1) THEN 'Check for low
DELAY_uS(500)
IF (GPIO.5=0) AND (EN=1) THEN
EN=0
END IF
END IF
IF PP>10 THEN 'Reset Count
PP=0
END IF
IF PP=8 THEN 'give two blinks
GPIO.0=1
Delay_ms(800)
GPIO.0=0
Delay_ms(800)
GPIO.0=1
Delay_ms(800)
GPIO.0=0
ELSE
GPIO.0=0
END IF
Wend
end.
And here is schematic from proteus
Edit:-Sorry for mistake in proteus it is working Well after adding PP=PP+1 after giving 2 pulses, but it is not working on board
Last edited: