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.

Lock output port in attiny 2313 with bascom avr

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

i have simple source code :

Code:
$regfile = "attiny2313.dat"
$crystal = 1000000
$hwstack = 32
$swstack = 20
$framesize = 32
'------------------------ Configuration
Ddrd = &B11111111                                           'Port D output
Ddrb = &B00000000                                           'Port B input
Portb = &B11111111                                          'PULL-UP internal
'------------------------

Do
 If Pinb.0 = 0 Then
 Portd = &B11111111
 Wait 3
 Portd = &B00000000
 Wait 5
 End If
 Loop


in this code explaint if pinb.0 is NC then portd is active loop with a timer and if pinb.0 NO aoutomatic portd is inactive.
My question :
how to build instruction if input with push button principle(NC then NO) if pinb.0 NC then NO portd is stay active,but if start push botton(pinb.0)noting a touch/respon ,portd is inactive
thanks for you attention
 
Last edited by a moderator:


Code - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$regfile = "attiny2313.dat"
$crystal = 1000000
$hwstack = 32
$swstack = 20
$framesize = 32
'------------------------ Configuration
Ddrd = &B11111111 'Port D output
Ddrb = &B00000000 'Port B input
Portb = &B11111111 'PULL-UP internal
'------------------------
Do
  Do
  Loop Until Pinb.0 = 0
  Do
    Portd = &B11111111
  Loop Until Pinb.0 = 1
  Portd = &B00000000
Loop
End

 

Sory sir it does't work,portd is active when pinb.0=0 if pinb.0=1 portd is inactive
i want to portd is still active,but when start power portd is inactive
 

no,i want portd's stay on(active) each button is pressed and released,but begine start portd's off inactive
 

next example, condition is changed when button is pressed, and no change when it is released.


Code - [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
25
26
27
$regfile = "attiny2313.dat"
$crystal = 1000000
$hwstack = 32
$swstack = 20
$framesize = 32
'------------------------ Configuration
Ddrd = &B11111111 'Port D output
Ddrb = &B00000000 'Port B input
Portb = &B11111111 'PULL-UP internal
'------------------------
DIM Last_Value As Byte
 
Last_Value = &B00000000
Portd = Last_Value 'Port D is inactive when power on
 
Do
 
  Do
  Loop Until Pinb.0 = 1     ' no change while button is released
 
  Last_Value =  not Last_Value
  Portd = Last_Value  ' change condition
  Do
  Loop Until Pinb.0 = 0 'wait till button is released
 
Loop
End

 

Thanks alot sir, your sorce code is work,but i was change Last_Value = &B00000000 to &B11111111 to get start inactive condition,by the way where i insert place timer fungtion,to control portd (active and inactive) like my first sorce code ?
thakns for you attention
 

So, inactive condition is 0B11111111?
When the button is pressed, will Port D be active immediately? (*)
and if it is released, after 5 seconds Port D will be inactive? This will make the Port D can be active more than 5s if you press and hold the button for example for the 2s, 2s+5s= 7s. Or Port D is only active for 5s although the button is pressed and held?
What is the purpose of 3 seconds delay? Only for the interval between each press a button? It will be opposed to the the first statement (*), or you need a short delay to reduce bounce effect of button?
 
Yes sir,i have try write to micro
yes
yes i want to portd wait for inactive an active (flip-flop)but time to active and inactive can be adjusment,although pinb.0 press or realese,flip-flop in portd can be stop only with different pin,example with pina.0

this extra question(if you not a busy)
in your source code,pinb.0 is multi fungtion,can to active and inactive portd(if i press and then realease pinb.0 then portd active,next if press and then realease pinb.0 again portd off,can you modify how to make pinb.0 the fungction only for active (flip-flop) and inactive with pina.0 like top question
 

Please try this code, it uses two buttons, button 1 = start flip-flop, button 2 = stop.

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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
$regfile = "attiny2313.dat"
$crystal = 1000000
$hwstack = 32
$swstack = 20
$framesize = 32
Ddrd = &B11111111
Ddrb = &B00000000
Portb = &B11111111
Dim Time_on As Word
Portd = &B11111111
Do
  While Pinb.0 = 1 'wait here if button 1 still unpressed
  Wend
  While Pinb.0 = 0 'wait till button 1 is released
  Wend
 
  While Pinb.1 = 1  'while button 2 is not pressed, do following job
      Portd = &B00000000
      Time_on = 0
      While Time_on < 2000
          If Pinb.1 = 0 Then
            Exit While
          End If
 
          Waitms 1
          Incr Time_on
      Wend
 
      Portd = &B11111111
      Time_on = 0
      While Time_on < 1000
          If Pinb.1 = 0 Then
            Exit While
          End If
 
          Waitms 1
          Incr Time_on
      Wend
 
      'Edited - these lines is not necessary
      'If Pinb.1 = 0 Then
      '   Exit While
      ' End If
 
  Wend
 
  While Pinb.1 = 0 'wait till button 2 is released
  Wend
 
Loop
End


Sorry if it's still not what you want, at least, you can learn from it.
 
Last edited:
your souce code is work 100% all i need:razz:,after i modify Portd after code Dim Time_on As Word
thanks alot sir,by the way don't be borring to help me next:lol:
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top