MICROPROCESSOR BASIC COMPILER PROGRAMS
7 segment HELLO WORLD SHORTCUT
Dim digit As Byte
Dim mask As Byte
loop:
TRISC = %00000000
For digit = 0 To 0x0b
mask = LookUp(0x74, 0x79, 0x38, 0x00, 0x38, 0x5c, 0x00, 0x4f, 0x5c, 0x77, 0x38,
0x5e), digit
PORTC = mask
WaitMs 300
Next digit
Goto loop
7 segment HELLO WORLD LONG METHOD
TRISC = 0x00
loop:
PORTC = %01110110
WaitMs 300
PORTC = %01111001
WaitMs 300
PORTC = %00111000
WaitMs 300
PORTC = %00000000
PORTC = %00111000
WaitMs 300
PORTC = %01011100
WaitMs 300
PORTC = %01001111
WaitMs 300
PORTC = %01011100
WaitMs 300
PORTC = %01110111
WaitMs 300
PORTC = %00111000
WaitMs 300
PORTC = %01011110
WaitMs 300
Goto loop
UP COUNTER (TO LIGHT ALL LED)
Dim a As Byte
TRISC = 0x00
a = 0
While a < 255
PORTC = a
a = a + 1
WaitMs 300
Wend
PORTC = a
DOWN COUNTER (ON TO OFF LED)
Dim a As Byte
TRISC = 0x00
a = 255
While a > 0
PORTC = a
a = a - 1
WaitMs 300
Wend
PORTC = a
LED ON OFF (BLINKING)
TRISC = 0x00
loop:
PORTC = %1111
WaitMs 100
PORTC = %0000
WaitMs 100
Goto loop
End
ROTATING LED (0 to 8 then 0)
TRISC = 0x00
PORTC = %00000001
loop:
PORTC = %00000001
WaitMs 500
PORTC = %00000010
WaitMs 500
PORTC = %00000100
WaitMs 500
PORTC = %00001000
WaitMs 500
PORTC = %10000000
WaitMs 500
PORTC = %01000000
WaitMs 500
PORTC = %00100000
WaitMs 500
PORTC = %00010000
WaitMs 500
Goto loop
End
RUNNING LED (0 to 8 then 8 to 0)
TRISC = 0x00
PORTC = %00000001
goleft:
WaitMs 500
PORTC = ShiftLeft(PORTC, 1)
If PORTC.7 Then Goto goright
Goto goleft
goright:
WaitMs 500
PORTC = ShiftRight(PORTC, 1)
If PORTC.0 Then Goto goleft
Goto goright
End
4 LED LIGHT
TRISC = 0x00
loop:
PORTC = %0.0.0.0.1.1.1.1
WaitMs 0
PORTC = %11110000
Goto loop
End
LED ON OFF
TRISC = 0x00
loop:
PORTC = %1111
WaitMs 100
PORTC = %0000
WaitMs 100
Goto loop
End
TOGGLE SWITCH
TRISA = %00000001
TRISC = %00000000
Symbol toggle1 = PORTA.0
toggle1 = 1
Symbol led1 = PORTC.0
loop:
If toggle1 Then
led1 = 1
Else
led1 = 0
Endif
Goto loop
ZERO TO NINE IN 7 SEGMENT LONG METHOD
TRISC = 0x00
loop:
PORTC = %00111111
WaitMs 500
PORTC = %00000110
WaitMs 500
PORTC = %01011011
WaitMs 500
PORTC = %01001111
WaitMs 500
PORTC = %01100110
WaitMs 500
PORTC = %01101101
WaitMs 500
PORTC = %01111101
WaitMs 500
PORTC = %00100111
WaitMs 500
PORTC = %01111111
WaitMs 500
PORTC = %01101111
WaitMs 500
Goto loop
ZERO TO NINE 7 SEGMENT SHORTCUT
Dim digit As Byte
Dim mask As Byte
loop:
TRISC = %00000000
For digit = 0 To 9
mask = LookUp(0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x67), digit
PORTC = mask
WaitMs 300
Next digit
Goto loop
ALTERNATE 4 LED
TRISC = 0x00
loop:
PORTC = %00001111
WaitMs 300
PORTC = %11110000
WaitMs 300
Goto loop
SHORTCUT 0 TO B
DIM digit as byte
DIM mask as byte
loop:
TRISC = %00000000
for digit = 0 to b
mask = lookup(0x3f, 0x79, 0x38, 0x38, 0x5c, 0x00, 0x4f, 0x5c, 0x77, 0x38, 0x4e), digit
portc = mask
waitms 200
next digit
goto loop
end
SHORTCUT 0 TO F
DIM digit as byte
DIM mask as byte
loop:
TRISC = %00000000
for digit = 0 to f
mask = lookup(0x73, 0x1c, 0x6d, 0x74, 0x00, 0x78, 0x74, 0x79, 0x00, 0x7c, 0x1c,
0x78, 0x78, 0x5c, 0x54), digit
portc = mask
waitms 200
next digit
goto loop
end