ايران ويج

نسخه‌ی کامل: LED با میکرو
شما در حال مشاهده‌ی نسخه‌ی متنی این صفحه می‌باشید. مشاهده‌ی نسخه‌ی کامل با قالب بندی مناسب.
سلام!

لطفا یه نقشه ی خوب بدید که 2 تا LED و یک کلید داشته باشد که وقتی کلید را فشار میدهیم LED1 روشن و LED2 خاموش و با فشار دوباره عکس این عملیات صورت پذیرد

با شرح کار و کد برنامه نویسی به زبان بیسیک یا FastAVR

با تشکر
وحید :wink:
آقا اصلا یک نقشه ی ساده و گیرا و یک برنامه که به زبون Basic یا همون FastAVR که فرقی نداره بده

مثل چشمک زن LED که کلید و اینا هم داشته باشه
تا من انجامش بدم و برای اولین بار یک نقشه و یک برنامه برای یادگیری داشته باشم

برای ATMega16

من میخام طریقه ی ورودی و خروجی رو بفهمم

مثلا با فشار کلید، مد چشمک زدن تغییر کنه

ممنون
وحید :wink:
این مثال رو از تو مثال های خودش پیدا کردم بد نیست ببینش نقشه هم نمی خواد روی برد برد ببند یه 5 ولت هم بهش بده و پایه هایی که می خوای نشون بدی رو هم با یه مقاومت و LED وصل کن به زمین
کد:
'--------------------------------------------------------------
'                 (c) 1999-2003 MCS Electronics
'--------------------------------------------------------------
'  file: PORT.BAS
'  demo: PortB and PortD
'--------------------------------------------------------------
Dim A As Byte , Count As Byte

'configure PORT D for input mode
Config Portd = Input

'reading the PORT, will read the latch, that is the value
'you have written to the PORT.
'This is not the same as reading the logical values on the pins!
'When you want to know the logical state of the attached hardware,
'you MUST use the PIN register.
A = Pind

'a port or SFR can be treated as a byte
A = A And Portd

Print A                                                       'print it

Bitwait Pind.7 , Reset                                        'wait until bit is low


'We will use port B for output
Config Portb = Output

'assign value
Portb = 10                                                    'set port B to 10
Portb = Portb And 2

Set Portb.0                                                   'set bit 0 of port B to 1

Incr Portb

'Now a light show on the STK200
Count = 0
Do
  Incr Count
  Portb = 1
  For A = 1 To 8
    Rotate Portb , Left                                       'rotate bits left
    Wait 1
  Next
  'the following 2 lines do the same as the previous loop
  'but there is no delay
'  Portb = 1
'  Rotate Portb , Left , 8
Loop Until Count = 10
Print "Ready"

'Again, note that the AVR port pins have a data direction register
'when you want to use a pin as an input it must be set low first
'you can do this by writing zeros to the DDRx:
'DDRB =&B11110000  'this will set portb1.0,portb.1,portb.2 and portb.3 to use as inputs.

'So : when you want to use a pin as an input set it low first in the DDRx!
'     and read with PINx
'     and when you want to use the pin as output, write a 1 first
'     and write the value to PORTx

End