Help needed for simply code

General discussion on mikroBasic for AVR.
Post Reply
Author
Message
Draketornado
Posts: 3
Joined: 17 Oct 2008 18:38

Help needed for simply code

#1 Post by Draketornado » 18 Oct 2008 15:08

Hello

I'm absolutely new on coding microcontrollers. I'm actually using MikroBasic for AVR.

I was trying to make a code for a running light, but i think i go to complicated...Can somebody write me code who is smaller but has the same effect that my-one please?

Code: Select all

program running_led
sub procedure wait1
  delay_ms(100)
end sub
main:
  DDRA  = $FF
  DDRB  = $FF
  DDRC  = $FF
  DDRD  = $FF
  PORTA = $00
  PORTB = $00
  PORTC = $00
  PORTD = $00

  while true
PORTA.0 = 1
wait1
PORTA.0 = 0
PORTA.1 = 1
wait1
PORTA.1 = 0
PORTA.2 = 1
wait1
PORTA.2 = 0
PORTA.3 = 1
wait1
PORTA.3 = 0
PORTA.4 = 1
wait1
PORTA.4 = 0
PORTA.5 = 1
wait1
PORTA.5 = 0
PORTA.6 = 1
wait1
PORTA.6 = 0
PORTA.7 = 1
wait1
PORTA.7 = 0
PORTB.7 = 1
wait1
PORTB.7 = 0
PORTB.6 = 1
wait1
PORTB.6 = 0
PORTB.5 = 1
wait1
PORTB.5 = 0
PORTB.4 = 1
wait1
PORTB.4 = 0
PORTB.3 = 1
wait1
PORTB.3 = 0
PORTB.2 = 1
wait1
PORTB.2 = 0
PORTB.1 = 1
wait1
PORTB.1 = 0
PORTB.0 = 1
wait1
PORTB.0 = 0
PORTC.0 = 1
wait1
PORTC.0 = 0
PORTC.1 = 1
wait1
PORTC.1 = 0
PORTC.2 = 1
wait1
PORTC.2 = 0
PORTC.3 = 1
wait1
PORTC.3 = 0
PORTC.4 = 1
wait1
PORTC.4 = 0
PORTC.5 = 1
wait1
PORTC.5 = 0
PORTC.6 = 1
wait1
PORTC.6 = 0
PORTC.7 = 1
wait1
PORTC.7 = 0
PORTD.7 = 1
wait1
PORTD.7 = 0
PORTD.6 = 1
wait1
PORTD.6 = 0
PORTD.5 = 1
wait1
PORTD.5 = 0
PORTD.4 = 1
wait1
PORTD.4 = 0
PORTD.3 = 1
wait1
PORTD.3 = 0
PORTD.2 = 1
wait1
PORTD.2 = 0
PORTD.1 = 1
wait1
PORTD.1 = 0
PORTD.0 = 1
wait1
PORTD.0 = 0
  wend
end.
Thank you verry much...

Christian

stevech
Posts: 38
Joined: 20 Aug 2007 16:47

#2 Post by stevech » 19 Oct 2008 04:49

read about loops, such as
for and next
do and while

read about bit-shifts and using divide by 2 and multiply by 2 that will move a single bit between the 8 bits of a byte

I think you'll learn if you do your own research rather than getting verbatim code here.

Also, there are some great tutorials and beginner's sections on avrfreaks.net

Post Reply

Return to “mikroBasic for AVR General”