- A running light going 1 direction using three LEDs.
- Every single LED will be light up after 1ms.
- When SW1 is pressed, the running light will reverse direction.
while (True) {
int pattern=1;
int direction=1;
for(int loop; 0; loop+direction) {
if(direction>0) {
pattern=(pattern<<1)||1;
} elseif {
Pattern=(pattern>>1)||4;
}
}
direction=-direction;
}
Yup!sorry, u meant what website
sorry, u meant what website
The websites that your lecturer gave you or the ones that you found....ok, i try and see but now my problem is i dont know how to use the delay in pic16f877 because my lecturer call us to do the research based on the website but i look through of the website, the information for pic16f877 is quite least.
;PIC Time Delay = 1.0000020 s with Osc = 4.000000 MHz
delay1s movlw D'6'
movwf CounterC
movlw D'24'
movwf CounterB
movlw D'168'
movwf CounterA
loop decfsz CounterA,1
goto loop
decfsz CounterB,1
goto loop
decfsz CounterC,1
goto loop
retlw
; ***** Program Header ***********************************************
LIST P=16F877a,
#include <p16f877a.inc>
__CONFIG 0x3D72 ; HS MODE,WDT OFF, BOREN
; ***** Definitions **************************************************
BANK_0 EQU 0x00
BANK_1 EQU 0x80
BANK_2 EQU 0x100
BANK_3 EQU 0x180
PortB equ 0x06 ; Port B
STATUS equ 0x03 ; Status Register
; ***** Main Program ***********************************************
Org 0
Init
movlw 0x0F ; prepare data for TRISB
; "PIN_B0 to PIN_B3 are
; input pins and
; PIN_B4 and PIN_B7 are
; output pins"
BANKSEL BANK_1 ; "activate" Bank 1
Movwf TRISB ; copy W to TRISB
BANKSEL BANK_0 ; "activate" Bank 0
Start clrf PortB
Set1 btfsc PortB,0
goto Set1
LEDIn clrf RB5
clrf RB6
clrf RB7
movlw 01h
movwf RB5
movlw 02h
movwf RB6
movlw 04h
movwf RB7
Delay_0
decfsz RB5,f
goto $+2
decfsz RB6,f
goto $+2
decfsz RB7,f
goto Delay_0
;3 cycles
goto $+1
nop
EndTest goto EndTest
END
This program would not work because it got too many errors.; ***** Program Header ***********************************************
LIST P=16F877a,
#include <p16f877a.inc>
__CONFIG 0x3D72 ; HS MODE,WDT OFF, BOREN
; ***** Definitions **************************************************
BANK_0 EQU 0x00
BANK_1 EQU 0x80
BANK_2 EQU 0x100
BANK_3 EQU 0x180
PortB equ 0x06 ; Port B
STATUS equ 0x03 ; Status Register
; ***** Main Program ***********************************************
Org 0
Init
movlw 0x0F ; prepare data for TRISB
; "PIN_B0 to PIN_B3 are
; input pins and
; PIN_B4 and PIN_B7 are
; output pins"
BANKSEL BANK_1 ; "activate" Bank 1
Movwf TRISB ; copy W to TRISB
BANKSEL BANK_0 ; "activate" Bank 0
Start clrf PortB
Set1 btfsc PortB,0 ; NOT SURE WHAT YOU'RE
goto Set1 ; TRYING TO DO HERE...
LEDIn clrf RB5
clrf RB6
clrf RB7
movlw 01h
movwf RB5
;<- INSERT DELAY HERE
movlw 02h
movwf RB6
;<- INSERT DELAY HERE
movlw 04h
movwf RB7
;<- INSERT DELAY HERE
LOOP BACK TO MAIN PROGRAM.
Delay_0
decfsz RB5,f
goto $+2
decfsz RB6,f
goto $+2
decfsz RB7,f
goto Delay_0
;3 cycles
goto $+1
nop
EndTest goto EndTest
END