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.

[SOLVED] About timer and counter

Status
Not open for further replies.

erwin4838

Member level 1
Joined
Mar 4, 2012
Messages
32
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Tangerang-indonesia
Activity points
1,478
dear all my friend
i have a sample source code in BASCOM,this fungtion only for on/off
Code:
$regfile = "attiny2313.dat"
$crystal = 1000000
Ddrb = &B11111111              'output
Ddrd = &B00000000              'input
Portd = &B11111111             'pull up
Do
If Pind.5 = 0 Then
Portb = &B11111111
End If
If Pind.2 = 0 Then
Portb = &B00000000
End If
Loop

please guide me to change this source code,for the fungtion :
portb is active after wait 3 sec,and then portb is inactive after pind.5 NC(Normaly Close) repeat in 7 times

thanks for u attention:smile:
 

So, we don't need second switch to turn it off, right? Try this

Code Basic4GL - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
$regfile = "attiny2313.dat"
$crystal = 1000000
Dim X As Byte
Ddrb = &B11111111              'output
Ddrd = &B00000000              'input
Portd = &B11111111             'pull up
For X = 1 To 7
Do
Loop Until Pind.5 = 0             'wait till key is pressed
Do
Loop Until Pind.5 = 1             'wait till key is released
Wait 3
Portb = &B00000000             'portb will be off after 3 seconds the key is released
Next X

 
Last edited:
Yes,don't have second switch
ok i'll try,thks

- - - Updated - - -

sory sir it doesn't work,this code fungtion only for active portd,just that,


i need in the first time power on,portb is inactive until 3 second,and then active
an then when pind.5 is counting 7 times then portb is inactive
please guide me:sad:
 

After waiting for 3 second, portd will be active.
Then if key has been pressed 7 times, portd will be inactive.
Is it right?

Code Basic4GL - [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
$regfile = "attiny2313.dat"
$crystal = 1000000
Dim X As Byte
 
Ddrb = &B11111111   'output
Ddrd = &B00000000   'input
Portd = &B11111111  'pull up
 
Portb = &B00000000  'portb inactive
Wait 3
Portb = &B11111111  'portb active
 
For X = 1 To 7
Do
Loop Until Pind.5 = 0  'wait till key is pressed
Waitms 50                'small delay to reduce bounce effect when key is pressed
 
Do
Loop Until Pind.5 = 1  'wait till key is released
Waitms 50                'small delay to reduce bounce effect when key is released
 
Next X
 
Portb = &B00000000   'after 7 times, turn portb off.

 
It still doesn't work,this fungtion :
in start portb is direct active,not waiting 3sec,and then if i press pind.5 times portb is direct off,not count after 7times
 

hi erwin,

could you please explain you what you exactly want to do???

give me your project idea...
 

in start portb is direct active,not waiting 3sec
Have you checked your hardware? F = 1 MHz? Or you tried it at simulation software?

,and then if i press pind.5 times portb is direct off,not count after 7times
Maybe you need more debouncing time. try waitms with larger value.
 
Your RIGHT SIR,this is the final source code :
Code:
$regfile = "attiny2313.dat"
$crystal = 11059200                                          'this value 0% nothing efect for a timer
Dim X As Byte
Ddrb = &B11111111                                           'output
Ddrd = &B00000000   'input
Portd = &B11111111  'pull up
Portb = &B00000000                                          'portb inactive
Wait 3
Portb = &B11111111  'portb active
For X = 1 To 7
Do
Loop Until Pind.5 = 0  'wait till key is pressed
Waitms 200                                                       'small delay to reduce bounce effect when key is pressed
Do
Loop Until Pind.5 = 1  'wait till key is released
Waitms 200                                                       'small delay to reduce bounce effect when key is released
Next X
Portb = &B00000000                                            'after 7 times, turn portb off.
Return                                                              'for back to timer (wait 3)

THANKS ALOT SIR,YOUR ARE MY BEST TEACHER:-D
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top