Anda di halaman 1dari 53

Examples 21 - 30

21 Full Step Left (Table)

22 Full Step Right (Table)

23 Full Step Left ~ Right (Table)

24 Rotate Led Left (Simple)

25 Rotate Led Right (Simple)

26 Rotate Led Left ~ Right (Simple)

27 Rotate Led Left (Multiply by 2)

28 Rotate Led Right (Divide by 2)

29 Rotate Led Left ~ Right (Multiply~Divide)

30 Rotate Any 4 bit pattern Left ~ Right (Table)


;21 Full Step Leds Left (Table)

;Alt+F2 View as Text

;Alt+F1 Ctrl+D
;Chip Settings
#chip 16F690,4

;Alt+F1 Ctrl+Q
;Defines (Constants)
#define Leds PortC

;Alt+F1 Ctrl+R
;Variables
Dim Delay As word
Dim Leds As byte

;Program Data Tables


;Data tables
Table StepLeft
0
0
b'1001'
0
0
b'0011'
0
0
b'1100'
0
0
b'0110'
End Table

'21 Full Step Leds Left (Table)


'Configure Leds as Outputs
Dir Leds Out

'Define Delay as Length


Delay = 500

'Initialize Leds
Leds = b'0011'

'Full Step Leds Left


Do Forever

'Step Delay
Wait Delay ms

'Read Leds at Row number Leds


ReadTable StepLeft, Leds, Leds
Loop
Alt+F1 View as Icons
Subroutine/Function
Main
Icons, Category

Miscellaneous Icon Settings


Comment
21 Full Step Leds Left (Table)

Comment
Configure Leds as Outputs

Input/Output IO pin or port


Leds
Direction
Out

Miscellaneous Comment
Define Delay Length

Variables Variable
Delay
New Value
500

Miscellaneous Comment
Initialize Leds

Variables Variable
Leds
New Value
b'0011'

Miscellaneous Comment
Full Step Leds Left
Continued
Flow Control Mode
Forever

Miscellaneous Comment
Step Delay

Flow Control Length


Delay
Units
ms

Miscellaneous Comment
Read Leds at Row number
Leds

Miscellaneous Table
StepLeft
Table Location
Leds
Output Variable
Leds
This Icon was created This Icon has no settings
when thse Do Icon was
selected

Name & Save File


Tools .... Compile & Download F9
;22 Full Step Leds Right (Table)

;Alt+F2 View as Text

;Alt+F1 Ctrl+D
;Chip Settings
#chip 16F690,4

;Alt+F1 Ctrl+Q
;Defines (Constants)
#define Leds PortC

;Alt+F1 Ctrl+R
;Variables
Dim Delay As word
Dim Leds As byte

;Program Data Tables


;Data tables
;Data tables
Table StepRight
0
0
6
0
0
12
0
0
3
0
0
9
End Table

'22 Full Step Leds Right (Table)


'Configure Leds as Outputs
Dir Leds Out

'Define Delay as Length


Delay = 500

'Initialize Leds
Leds = b'0011'

'Full Step Leds Right


Do Forever

'Step Delay
Wait Delay ms

'Read Leds at Row number Leds


ReadTable StepRight, Leds, Leds
Loop
Alt+F1 View as Icons
Subroutine/Function
Main
Icons, Category

Miscellaneous Icon Settings


Comment
22 Full Step Leds Right (Table)

Comment
Configure Leds as Outputs

Input/Output IO pin or port


Leds
Direction
Out

Miscellaneous Comment
Define Delay Length

Variables Variable
Delay
New Value
500

Miscellaneous Comment
Initialize Leds

Variables Variable
Leds
New Value
b'0011'

Miscellaneous Comment
Full Step Leds Right
Continued
Flow Control Mode
Forever

Miscellaneous Comment
Step Delay

Flow Control Length


Delay
Units
ms

Miscellaneous Comment
Read Leds at Row number
Leds

Miscellaneous Table
StepRight
Table Location
Leds
Output Variable
Leds
This Icon was created This Icon has no settings
when thse Do Icon was
selected

Name & Save File


Tools .... Compile & Download F9
;23 Full Step Leds Left ~ Right (Table)

;Alt+F2 View as Text

;Alt+F1 Ctrl+D
;Chip Settings
#chip 16F690,4

;Alt+F1 Ctrl+Q
;Defines (Constants)
#define SW1 PortA.3
#define SW1up PortA.3=1
#define SW1down PortA.3=0
#define Leds PortC

;Alt+F1 Ctrl+R
;Variables
Dim Delay As word
Dim Leds As byte

;Alt+F1 Program Data Tables


;Data tables
Table StepLeft
0
0
6
0
0
12
0
0
3
0
0
9
End Table

Table StepRight
0
0
9
0
0
3
0
0
12
0
0
6
End Table

'23 Full Step Left ~ Right (Table)


'Configure SW1 as an Input
Dir SW1 In

'Configure Leds as Outputs


Dir Leds Out

'Define Delay Length


Delay = 500

'Wait for PowerUp


Wait 1 s

'Initialize Leds
Leds = b'0011'
Start:

'Full Step Left


Do Until SW1down

'Step Delay
Wait Delay ms

'Read Leds at Row number Leds


ReadTable StepLeft, Leds, Leds
Loop
Wait Until SW1up

'Full Step Right


Do Until SW1down

'Step Delay
Wait Delay ms

'Read Leds at Row number Leds


ReadTable StepRight, Leds, Leds
Loop
Wait Until SW1up
Goto Start
Alt+F1 View as Icons
Subroutine/Function
Main
Icons, Category

Miscellaneous Icon Settings


Comment
23 Full Step Left~Right (Table)

Comment
Configure SW1 as an Input

Input/Output IO pin or port


SW1
Direction
In

Miscellaneous Comment
Configure Leds as Outputs

Input/Output IO pin or port


Leds
Direction
Out

Miscellaneous Comment
Define Delay Length

Variables Variable
Delay
New Value
500

Miscellaneous Comment
Wait for PowerUp
Continued
Flow Control Length
1
Units
s

Miscellaneous Comment
Initialize Leds

Variables Variable
Leds
New Value
b'0011'

Flow Control Label


Start

Miscellaneous Comment
Full Step Left

Flow Control Mode


Until
Condition
SW1down

Miscellaneous Comment
Step Delay

Flow Control Length


Delay
Units
ms

Miscellaneous Comment
Read Leds at Row number
Leds
Miscellaneous Table
StepLeft
Table Location
Leds
Output Variable
Leds
This Icon was created This Icon has no settings
when thse Do Icon was
selected

Flow Control Mode


Until
Condition
SW1up

Miscellaneous Comment
Full Step Right

Flow Control Mode


Until
Condition
SW1down

Miscellaneous Comment
Step Delay

Flow Control Length


Delay
Units
ms

Miscellaneous Comment
Read Leds at Row number
Leds

Continued
Table
StepRight
Table Location
Leds
Output Variable
Leds
This Icon was created This Icon has no settings
when thse Do Icon was
selected

Flow Control Destination


Start

Name & Save File


Tools .... Compile & Download F9
;24 Rotate Leds Left (Simple)

;Alt+F2 View as Text

;Alt+F1 Ctrl+D
;Chip Settings
#chip 16F690,4

;Alt+F1 Ctrl+Q
;Defines (Constants)
#define Leds PortC

;Alt+F1 Ctrl+R
;Variables
Dim Leds As Byte
Dim Delay As Word

'24 Rotate Leds Left (Simple)


'Configure Leds as Outputs
Dir Leds Out

'Initialize Leds
LEDs = b'00010001'

'Define Delay Length


Delay = 500

Start:
'Step Delay
Wait Delay ms

'Rotate Left
Rotate Leds Left Simple
Goto Start
Alt+F1 View as Icons
Subroutine/Function
Main
Icons, Category

Miscellaneous Icon Settings


Comment
24 Rotate Leds Left (Simple)

Comment
Configure Leds as Outputs

Input/Output IO pin or port


Leds
Direction
Out

Miscellaneous Comment
Initialize Leds

Variables Variable
Leds
New Value
b'00010001'

Miscellaneous Comment
Define Delay Length

Variables Variable
Delay
New Value
500

Flow Control Label


Start

Continued
Miscellaneous Comment
Step Delay

Flow Control Length


Delay
Units
ms

Miscellaneous Comment
Rotate Left

Variables Variable
Leds
Direction
Left
Alt+F2 Edit text to read:
Rotate Leds Left Simple
Flow Control Destination
Start

Name & Save File


Tools .... Compile & Download F9
;25 Rotate Leds Right (Simple)

;Alt+F2 View as Text

;Alt+F1 Ctrl+D
;Chip Settings
#chip 16F690,4

;Alt+F1 Ctrl+Q
;Defines (Constants)
#define Leds PortC

;Alt+F1 Ctrl+R
;Variables
Dim Leds As Byte
Dim Delay As Word

'25 Rotate Leds Right (Simple)


'Configure Leds as Outputs
Dir Leds Out

'Initialize Leds
LEDs = b'00010001'

'Define Delay Length


Delay = 500

Start:
'Step Delay
Wait Delay ms

'Rotate Right
Rotate Leds Right Simple
Goto Start
Alt+F1 View as Icons
Subroutine/Function
Main
Icons, Category

Miscellaneous Icon Settings


Comment
25 Rotate Leds Right (Simple)

Comment
Configure Leds as Outputs

Input/Output IO pin or port


Leds
Direction
Out

Miscellaneous Comment
Initialize Leds

Variables Variable
Leds
New Value
b'00010001'

Miscellaneous Comment
Define Delay Length

Variables Variable
Delay
New Value
500

Flow Control Label


Start

Continued
Miscellaneous Comment
Step Delay

Flow Control Length


Delay
Units
ms

Miscellaneous Comment
Rotate Right

Variables Variable
Leds
Direction
Right
Alt+F2 Edit text to read:
Rotate Leds Right Simple
Flow Control Destination
Start

Name & Save File


Tools .... Compile & Download F9
;26 Rotate Leds Left ~ Right (Simple)

;Alt+F2 View as Text

;Alt+F1 Ctrl+D
;Chip Settings
#chip 16F690,4

;Alt+F1 Ctrl+Q
;Defines (Constants)
#define SW1 PortA.3
#define SW1up PortA.3=1
#define SW1down PortA.3=0
#define Leds PortC

;Alt+F1 Ctrl+R
;Variables
Dim Delay As word
Dim Leds As byte

'26 Rotate Leds Left~Right (Simple)


'Configure SW1 as an Input
Dir SW1 In

'Configure Leds as Outputs


Dir Leds Out

'Define Delay Length


Delay = 500

'Wait for PowerUp


Wait 1 s

'Initialize Leds
Leds = b'00010001'
Start:

'Rotate Leds Left (Simple)


Do Until SW1down
'Step Delay
Wait Delay ms
Rotate Leds Left Simple
Loop

Wait Until SW1up

'Rotate Leds Right (Simple)


Do Until SW1down

'Step Delay
Wait Delay ms
Rotate Leds Right Simple
Loop

Wait Until SW1up


Goto Start
Alt+F1 View as Icons
Subroutine/Function
Main
Icons, Category

Miscellaneous Icon Settings


Comment
26 Rotate Leds Left~Right
(Simple)

Comment
Configure SW1 as an Input

Input/Output IO pin or port


SW1
Direction
In

Miscellaneous Comment
Configure Leds as Outputs

Input/Output IO pin or port


Leds
Direction
Out

Miscellaneous Comment
Define Delay Length

Variables Variable
Delay
New Value
500

Miscellaneous Comment
Wait for PowerUp
Flow Control Length
1
Units
s

Miscellaneous Comment
Initialize Leds

Variables Variable
Leds
New Value
B'00010001'

Flow Control Label


Start

Miscellaneous Comment
Rotate Leds Left (Simple)

Flow Control Mode


Until
Condition
SW1down

Miscellaneous Comment
Step Delay

Flow Control Length


Delay
Units
ms

Variables Variable
Leds
Direction
Left
Alt+F2 Edit text to read:
Rotate Leds Left Simple
This Icon was created This Icon has no settings
when thse Do Icon was
selected

Flow Control Mode


Until
Condition
SW1up

Miscellaneous Comment
Rotate Leds Right (Simple)

Flow Control Mode


Until
Condition
SW1down

Miscellaneous Comment
Step Delay

Flow Control Length


Delay
Units
ms

Variables Variable
Leds
Direction
Right
Alt+F2 Edit text to read:
Rotate Leds Right Simple
This Icon was created This Icon has no settings
when thse Do Icon was
selected

Flow Control Mode


Until
Condition
SW1up
Destination
Start

Name & Save File


Tools .... Compile & Download F9
;27 Rotate Leds Left (Multiple by 2)

;Alt+F2 View as Text

;Alt+F1 Ctrl+D
;Chip Settings
#chip 16F690,4

;Alt+F1 Ctrl+Q
;Defines (Constants)
#define Leds PortC

;Alt+F1 Ctrl+R
;Variables
Dim Delay As word
Dim Leds As byte

'27 Rotate Leds Left (Multiply by 2)


'Configure Leds a Outputs
Dir Leds Out

'Define Delay Length


Delay = 500

'Wait for PowerUp


Wait 1 s

'Initialize Leds
Leds = b'0001'

'Rotate Left
Do Forever

'Step Delay
Wait Delay ms
If Leds = b'1000' Then
Leds = b'0001'
Else
'Shift Left
Leds = Leds *2
End If
Loop
Alt+F1 View as Icons
Subroutine/Function
Main
Icons, Category

Miscellaneous Icon Settings


Comment
27 Rotate Leds Left (Multiply
by 2)

Comment
Configure Leds as Outputs

Input/Output IO pin or port


Leds
Direction
Out

Miscellaneous Comment
Define Delay Length

Variables Variable
Delay
New Value
500

Miscellaneous Comment
Wait for PowerUp

Flow Control Length


1
Units
s

Miscellaneous Comment
Initialize Leds
Variables Variable
Leds
New Value
b'0001'

Miscellaneous Comment
Rotate Left

Flow Control Mode


Forever

Miscellaneous Comment
Step Delay

Flow Control Length


Delay
Units
ms

Condition
Leds = b'1000'

Variables Variable
Leds
New Value
b'0001'

Flow Control This icon has no settings

Miscellaneous Comment
Shift Left
Variables Variable
Leds
New Value
Leds *2

This icon was created This icon has no settings


when the
If icon was created
This icon was created This icon has no settings
when the Do icon was
created

Name & Save File


Tools .... Compile & Download F9
;28 Rotate Leds Right (Divide by 2)

;Alt+F2 View as Text

;Alt+F1 Ctrl+D
;Chip Settings
#chip 16F690,4

;Alt+F1 Ctrl+Q
;Defines (Constants)
#define Leds PortC

;Alt+F1 Ctrl+R
;Variables
Dim Delay As word
Dim Leds As byte

'28 Rotate Leds Right (Divide by 2)


'Configure Leds as Outputs
Dir Leds Out

'Define Delay Length


Delay = 500

'Wait for PowerUp


Wait 1 s

'Initialize Leds
Leds = b'1000'

'Rotate Right
Do Forever
'Step Delay
Wait Delay ms

If Leds = 1 Then

Leds = b'1000'
Else
'Shift Right
Leds = Leds / 2

End If
Loop
Alt+F1 View as Icons
Subroutine/Function
Main
Icons, Category

Miscellaneous Icon Settings


Comment
28 Rotate Leds Right (Divide
by 2)

Comment
Configure Leds as Outputs

Input/Output IO pin or port


Leds
Direction
Out

Miscellaneous Comment
Step Delay

Variables Variable
Delay
New Value
500

Miscellaneous Comment
Wait for PowerUp

Flow Control Length


1
Units
s

Miscellaneous Comment
Initialize Leds
Variables Variable
Leds
New Value
b'1000'

Miscellaneous Comment
Rotate Right

Flow Control Mode


Forever

Miscellaneous Comment
Step Delay

Flow Control Length


Delay
Units
ms

Condition
Leds = 1

Variables Variable
Leds
New Value
b'1000'

Flow Control This icon has no settings

Miscellaneous Comment
Shift Right

Continued
Variables Variable
Leds
New Value
Leds /2

This icon was created This icon has no settings


when the
If icon was created
This icon was created This icon has no settings
when the Do icon was
created

Name & Save File


Tools .... Compile & Download F9
;29 Rotate Leds Left ~ Right (Mult ~ Div)

;Alt+F2 View as Text

;Alt+F1 Ctrl+D
;Chip Settings
#chip 16F690,4

;Alt+F1 Ctrl+Q
;Defines (Constants)
#define SW1 PortA.3
#define SW1up PortA.3=1
#define SW1down PortA.3=0
#define Leds PortC

;Alt+F1 Ctrl+R
;Variables
Dim Delay As word
Dim Leds As byte
'29 Rotate Leds Left ~ Right (Multiply ~ Divide by 2)
'Configure SW1 as an Input
Dir SW1 In

'Configure Leds as Outputs


Dir Leds Out

'Define Delay Length


Delay = 500

'Wait for PowerUp


Wait 1 s

'Initialize Leds
Leds = b'0001'
Start:

'Rotate Left
Do While SW1up
'Step Delay
Wait Delay ms
If Leds = b'1000' Then
Leds = b'0001'
Else

'Shift Left
Leds = Leds *2
End If
Loop
Wait Until SW1up

'Rotate Right
Do While SW1up

'Step Delay
Wait Delay ms
If Leds = b'0001' Then
Leds = b'1000'
Else

'Shift Right
Leds = Leds / 2
End If
Loop
Wait Until SW1up
Goto Start
Alt+F1 View as Icons
Subroutine/Function
Main
Icons, Category

Miscellaneous Icon Settings


Comment
29 Rotate Leds Left ~ Right
(Multiply ~ Divide by 2)

Comment
Configure SW1 as an Input

Input/Output IO pin or port


SW1
Direction
In

Miscellaneous Comment
Configure Leds as Outputs

Input/Output IO pin or port


Leds
Direction
Out

Miscellaneous Comment
Define Delay Length

Variables Variable
Delay
New Value
500

Miscellaneous Comment
Wait for PowerUp

Continued
Flow Control Length
1
Units
s

Miscellaneous Comment
Initialize Leds

Variables Variable
Leds
New Value
b'1000'

Flow Control Label


Start

Miscellaneous Comment
Rotate Left

Flow Control Mode


While
Condition
SW1up

Miscellaneous Comment
Step Delay

Flow Control Length


Delay
Units
ms

Condition
Leds = b'1000'

Continued
Variables Variable
Leds
New Value
b'0001'

Flow Control This icon has no settings

Miscellaneous Comment
Shift Left

Variables Variable
Leds
New Value
Leds *2

This icon was created This icon has no settings


when the
If icon was created
This icon was created This icon has no settings
when the Do icon was
created

Flow Control Mode


Until
Condition
SW1up

Miscellaneous Comment
Rotate Right

Flow Control Mode


While
Condition
SW1up

Continued
Miscellaneous Comment
Step Delay

Flow Control Length


Delay
Units
ms

Condition
Leds = b'0001'

Variables Variable
Leds
New Value
b'1000'

Flow Control This icon has no settings


This icon has no
settings

Miscellaneous Comment
Shift Right

Variables Variable
Leds
New Value
Leds /2

This icon was created This icon has no settings


when the
If icon was created
This icon was created This icon has no settings
when the Do icon was
created

Continued
Flow Control Mode
Until
Condition
SW1up

Destination
Start

Name & Save File


Tools .... Compile & Download F9
;30 Variable Speed Rotate Any 4 bit Pattern

;Alt+F2 View as Text

;Alt+F1 Ctrl+D
;Chip Settings
#chip 16f690,4

;Alt+F1 Ctrl+Q
;Defines (Constants)
#define SW1 PortA.3
#define Sw1up PortA.3=1
#define Sw1down PortA.3=0
#define Leds PortC
#define Adjust ReadAD10(AN0)

;Alt+F1 Ctrl+R
;Variables
Dim Adjust As word

;Program Data Tables


;Data tables
Table StepLeft
b'0010'
b'0100'
b'0110'
b'1000'
b'1010'
b'1100'
b'1110'
b'0001'
b'0011'
b'0101'
b'0111'
b'1001'
b'1011'
b'1101'
b'1111'
b'0000'
End Table
Table StepRight
b'1000'
b'0001'
b'1001'
b'0010'
b'1010'
b'0011'
b'1011'
b'0100'
b'1100'
b'0101'
b'1101'
b'0110'
b'1110'
b'0111'
b'1111'
b'0111'
End Table

'30 Variable Speed Rotate Any 4 bit Number


'Configute SW1 as an Input
Dir SW1 in

'Configure Leds as Outputs


Dir Leds Out

'Turn = 0 = Left Turn = 1 = Right


Turn = 0

'Wait for PowerUp


Wait 1 s

'Rotate Any 4 bit Pattern


'Initialize Pattern to Rotate
Leds = b'0111'

Start:
Do Forever

'Wait Delays Subroutine


Delays

'Change Direction?
If SW1down Then

'Change Direction
Turn = 1 xor Turn
Wait Until SW1up
End If
If Turn=0 Then

'Rotate Left
'Read Leds Row number Leds
ReadTable StepLeft, LEDs, LEDs
Else

'Rotate Right
'Read Leds Row number Leds
ReadTable StepRight, LEDs, LEDs
End If
Loop
Goto Start

'''Wait + Adjust
Sub Delays
Wait 500 ms
Wait Adjust ms
End Sub
Alt+F1 View as Icons
Subroutine/Function
Main
Icons, Category

Miscellaneous Icon Settings


Comment
30 Variable Speed Rotate Any
4 bit Number

Comment
Configure SW1 as an Input

Input/Output IO pin or port


SW1
Direction
In

Miscellaneous Comment
Configure Leds as Outputs

Input/Output IO pin or port


Leds
Direction
Out

Miscellaneous Comment
Turn=0=Left
Turn=1=Right

Variables Variable
Turn
New Variable
0

Continued
Miscellaneous Comment
Wait for PowerUp

Variables Length
1
Units
s

Miscellaneous Comment
Rotate Any 4 bit Pattern

Comment
Initialize Pattern to Rotate

Variables Variable
Leds
New Variable
b'0111'

Flow Control Label


Start

Mode
Forever

Miscellaneous Comment
Wait Delays Subroutine

Subroutines Main ADD


Add Subroutine Delays to
display
Delays Icon Under Subroutines
Click Main to return to Main
Screen
Continued
Miscellaneous Comment
Change Direction?

Flow Control Condition


SW1down

Miscellaneous Comment
Change Direction

Variables Variable
Turn
New Variable
Turn = 1 xor Turn

Flow Control Mode


Until
Condition
SW1up

This Icon was created This Icon has no settings


when the If Icon was
selected

Flow Control Condition


Turn = 0

Miscellaneous Comment
Rotate Left

Comment
Read Leds at Row number
Leds
Table
StepLeft
Table Location
Leds
Output Variable
Leds
Flow Control This Icon has no settings

Miscellaneous Comment
Rotate Right

Comment
Read Leds at Row number
Leds

Miscellaneous Table
StepRight
Table Location
Leds
Output Variable
Leds
This Icon was created This Icon has no settings
when the If Icon was
selected
Subroutines This Subroutine has no
parameters

This Icon was created This Icon has no settings


when the Do Icon was
selected

Flow Control Destination


Start

Continued
Subroutine Delays
Main

Delays

Flow Control Length


100
Units
ms

Length
Adjust
Units
ms

Name & Save File


Tools .... Compile & Download F9

Anda mungkin juga menyukai