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.

Help needed to program 12F675 using Mikrobasic

Status
Not open for further replies.

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
 
Last edited:

I was having hard time to count pulses, when I configure an output to switch on when pulse count is >50, it get high only after 4 or 5 key press, however after visiting that link in previous post, I got to know that I will have to use mikrobasic built in button routine, and to my surprise it works ( however i still think that my logic was right as I had used even longer delays) . Now counting is as expected and I am trying to code other logic. thank you for your attention, I'll be back with more questions.

ps - would be helpful if anyone could provide tmr0 code specif to 16f676 in mikrobasic. I am a newbie and trying to get things working
 
Last edited:

When you use the button routine, you are using switch debouncing. But in your code, you most probably didn't use it. That was what caused the problem. What kind of TMR0 code do you need? Just incrementing, using interrupt,etc?
 

I want a free running timer triggering interrupt to increase counter value, which I will reset when needed. say timer is increasing count once every 150usec and is reset to zero when count is 250 i.e. every 37.5 msec.
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top