'****************************************************************

'* Name
: LED_Two-Ports.BAS
*
'* Author : WIN HTET WIN
*
'* Notice : Copyright (c) 2012
*
'*
: All Rights Reserved
*
'* Date
: 13/3/2013 ; 14/3/2013
*
'* Version : 1.0
*
'* Notes : Processor: 16F877A
*
'*
: 4 MHz Crystal
*
'*
: Chasing LEDs in Step & Progressive Modes in PortB *
'*
: and PortD.
*
'****************************************************************
LED var Byte
'LED variable setup as byte
PortB
Trisb
PortD
Trisd

=
=
=
=

%00000000
%00000000
%00000000
%00000000

'Initiate all
'Setup port b
'Initiate all
'Setup port d

main:

port B
as all
port D
as all

pins to low
outputs
pins to low
outputs

'Label for beginning of main loop

' *********** Light LEDs in left direction in step mode ********************
for led = 0 to 7 'Loop through all LEDs
'turns the LED on
portB.0[LED] = 1 'Set each pin of portb high (5 volts) which
'which turns the LED on
PORTD.0[LED] = 1 'Set each pin of portb high (5 volts) which
'turns the LED on
pause 500

'Pause 1000 milliseconds (1 second) with

LED on
portb.0[LED] = 0 'Set each pin of portb low (0 volts) which
'turns the LED off
PORTD.0[LED] = 0
next
'Continue until all 7 have been lit once
portb = %00000000 'Set all port B pins to low
PORTD = %00000000 'Set all port D pins to low
pause 500
'Delay 1/2 second
' *********** Light LEDs in right direction in step mode ********************
for led = 7 to 0 step -1
'Loop through all LEDs backwards
portb.0[led] = 1 'Set pin 0 of portb high (5 volts)
'which turns the LED on
PORTD.0[LED] = 1 'Set each pin of portb high (5 volts) which
'turns the LED on
pause 500
portb.0[led] = 0
'the
PORTD.0[LED] = 0
next
portb = %00000000
PORTD = %00000000
pause 500

'Pause 1000 milliseconds (1 second) with LED on
'Set pin 0 of portb low (0 volts) which turns
LED off
'Continue until all 7 have been lit once
'Set all port B pins to low
'Set all port D pins to low
'Delay 1/2 second

' *********** Light LEDs in right direction in progressive mode ***********

for led = 0 to 7 'Loop through all LEDs
portB.0[LED] = 1 'Set each pin of portb high (5 volts) which
'turns the LED on
portD.0[LED] = 1 'Set each pin of portb high (5 volts) which
'turns the LED on
pause 500

'Pause 500 milliseconds (1/2 second)with

LED on
next
PortB = %00000000
PORTD = %00000000
pause 500

'Continue until all 7 have been lit
'Set all port B pins to low
'Set all port D pins to low
'Delay 1/2 second

' *********** Light LEDs in left direction in progressive mode ************
for led = 7 to 0 step -1
'Loop through all LEDs backwards
portb.0[led] = 1 'Set pin 0 of portb high (5 volts)
'which turns the LED on
portD.0[LED] = 1 'Set each pin of portb high (5 volts) which
'turns the LED on
pause 500
'Pause 500 milliseconds(1/2 second)with LED on
next
'Continue until all 7 have been lit
PortB = %00000000
'Set all port B pins to low
PORTD = %00000000 'Set all port D pins to low
pause 500
'Delay 1/2 second
' ***************PORTB ON & PORTD OFF *****************************************
PORTB = %11111111
PORTD = %00000000
PAUSE 500
PORTB = %00000000
PORTD = %00000000
PAUSE 500
' ***************PORTB OFF & PORTD ON******************************************
PORTB = %00000000
PORTD = %11111111
PAUSE 500
PORTB = %00000000
PORTD = %00000000
PAUSE 500
' ***************PORTB OFF & PORTD ON******************************************
PORTB = %00000000
PORTD = %11111111
PAUSE 500
PORTB = %00000000
PORTD = %00000000
PAUSE 500
' ***************PORTB ON & PORTD OFF *****************************************
PORTB
PORTD
PAUSE
PORTB
PORTD
PAUSE

= %11111111
= %00000000
500
= %00000000
= %00000000
500

' ***************PORTB ON & PORTD ON X THREE TIMES***************************
PORTB = %11111111
PORTD = %11111111
PAUSE 500
PORTB = %00000000
PORTD = %00000000
PAUSE 500
PORTB = %11111111
PORTD = %11111111
PAUSE 500
PORTB = %00000000
PORTD = %00000000
PAUSE 500
PORTB = %11111111
PORTD = %11111111
PAUSE 500
PORTB = %00000000
PORTD = %00000000
PAUSE 500
' ****************************************************************************
goto main
END
to put it

'Jump to the main label and do it all again and
'again
'This line is not needed but its safe
'here just in case the program gets lost.

Sign up to vote on this title
UsefulNot useful