PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Hat jemand mal ein paar Beispiele für BASCOM EInsteiger?



28.12.2003, 11:06
Hallo
ich bin auch AVR Anfänger und möchte einen Mega16 mit Basic programmieren. Wie sieht denn da so ein einfaches Programm aus? Hat jemand mal ein paar Beispiele?

- wie man LED blinken läst
- Motor mit PWM steuert

und sowas halt

HiTech
28.12.2003, 13:17
Ich habe das auch mal gesucht, hier ein paar Beispielcodes:


'-------------------------------------------------------------
' SOUND.BAS
' Copyright 1999-2003 MCS Electronics
'-------------------------------------------------------------
Dim Pulses As Word, Periods As Word
Pulses = 65535: Periods = 10000 'set variables
Speaker Alias Portb.1 'define port pin

Sound Speaker, Pulses, Periods 'make some noice
'note that pulses and periods must have a high value for high XTALS
'sound is only intended to make some noise!

'pulses range from 1-65535
'periods range from 1-65535

End



'-----------------------------------------------------------------------
' (c) 2001-2003 MCS Electronics
' servo.bas demonstrates the SERVO option
'-----------------------------------------------------------------------

'Servo's need a pulse in order to operate
'with the config statement CONFIG SERVOS we can specify how many servo's we
'will use and which port pins are used
'A maximum of 16 servos might be used
'The SERVO statements use one byte for an interrupt counter and the TIMER0
'This means that you can not use TIMER0 anymore
'The reload value specifies the interval of the timer in uS
'Config Servos = 2 , Servo1 = Portb.0 , Servo2 = Portb.1 , Reload = 10

Config Servos = 1 , Servo1 = Portb.0 , Reload = 10

'we use 2 servos with 10 uS resolution(steps)

'we must configure the port pins used to act as output
Config Portb = Output

'finally we must turn on the global interrupt
Enable Interrupts

'the servo() array is created automatic. You can used it to set the
'time the servo must be on
Servo(1) = 10 '10 times 10 = 100 uS on
'Servo(2) = 20 '20 times 10 = 200 uS on
Do
Loop

Dim I As Byte
Do
For I = 0 To 100
Servo(1) = I
Waitms 1000
Next

For I = 100 To 0 Step -1
' Servo(1) = I
Waitms 1000
Next
Loop
End



'---------------------------------------------------------------------
' TIMER0.BAS
' example that shows how to use TIMER0 related statements
'---------------------------------------------------------------------

'First you must configure the timer to operate as a counter or as a timer
'Lets configure it as a COUNTER now
'You must also specify if it will count on a rising or falling edge

Config Timer0 = Counter, Edge = Rising
'Config Timer0 = Counter , Edge = falling
'unremark the line aboven to use timer0 to count on falling edge

'To get/set the value from the timer access the timer/counter register
'lets reset it to 0
Tcnt0 = 0

Do
Print Tcnt0
Loop Until Tcnt0 >= 10
'when 10 pulses are count the loop is exited
'or use the special variable TIMER0
Timer0 = 0


'Now configire it as a TIMER
'The TIMER can have the systemclock as an input or the systemclock divided
'by 8,64,256 or 1024
'The prescale parameter excepts 1,8,64,256 or 1024
Config Timer0 = Timer, Prescale = 1

'The TIMER is started now automaticly
'You can STOP the timer with the following statement :
Stop Timer0

'Now the timer is stopped
'To START it again in the last configured mode, use :
Start Timer0

'Again you can access the value with the tcnt0 register
Print Tcnt0
'or
Print Timer0
'when the timer overflows, a flag named TOV0 in register TIFR is set
'You can use this to execute an ISR
'To reset the flag manual in non ISR mode you must write a 1 to the bit position
'in TIFR:
Set Tifr.1



'The following code shows how to use the TIMER0 in interrupt mode
'The code is block remarked with '( en ')

'(

'Configute the timer to use the clock divided by 1024
Config Timer0 = Timer, Prescale = 1024

'Define the ISR handler
On Ovf0 Tim0_isr
'you may also use TIMER0 for OVF0, it is the same

Enable Timer0 ' enable the timer interrupt
Enable Interrupts 'allow interrupts to occur
Do
'your program goes here
Loop

'the following code is executed when the timer rolls over
Tim0_isr:
Print "*";
Return

')

End

Beitere Beispiele unter http://www.mcselec.com/download_avr.htm

28.12.2003, 13:25
Und wer eine Einführung sucht, der findet diese hier http://www.rowalt.de/mc/

incertius
01.11.2004, 17:36
Hallo zusammen,
kann mir jemand sagen woher man das Programm BASCOM bekommt (nicht nur die Demo)?? Ist das teuer?

fzehner
02.11.2004, 12:55
hier kannst Du Bascom direkt für 79,- EUR bestellen

http://www.mcselec.com/commerce/product_info.php?products_id=33