- #1
masteredison
- 2
- 0
Hello,
can someone help me in programming our PIC16F84A, we need to make a program that will show only a three output like a traffic light,..but I am not quite familiar in programming this. I examined a 7 output LED program but i can't figure out what to changed.. I also want to changed the delay for each LED and then go back to the start of the program...Thnx
;****set up constans and variables****
INCLUDE "P16F84.INC" ;look up file for MPASM
LIST P=16F84
ERRORLEVEL -302 ;SUPPRESS BANK SELECTION MESSAGES
__config _RC_OSC&_PWRTE_ON & _WDT_OFF ;RC oscillator, power on timer
;and watchdog timer off
status equ h'03' ;status register
trisb equ h'86' ;set up register for port B
trisa equ h'85' ;set up register for port B
count1 equ h'0e' ;general purpose register
count2 equ h'0f' ;general purpose register
leds equ h'06' ;portB is 7seg display content
porta equ h'05' ;portA is not used
;****set up portA and portB****
bsf status,5 ;switch to bank1 to set up ports
movlw h'00'
movwf trisb ;portB is all output
movlw h'00'
movwf trisa ;portA is all output
bcf status,5 ;switch back to bank0 to use ports
;****main program****
start movlw b'00000001' ;load pattern into W
movwf leds ;load W into portB (switch on rightmost LED)
call delay ;wait for some time
movlw b'00000010' ;new pattern
movwf leds
call delay ;wait
movlw b'00000100' ;new pattern
movwf leds ;
call delay ;wait
movlw b'00001000' ;new pattern
movwf leds ;
call delay ;wait
goto start ;do it all over again
;****delay subroutine****
;****delay = wait (delay count value 1) x (delay count value 2) cycles****
delay movlw h'EE' ;setup delay count value 1
movwf count1 ;count1 is slow counter
loop1 decfsz count1,1 ;
goto label ;still > 0
return ;count1 < 0 so get out of the delay loop
label movlw h'EE' ;setup delay count value 2
movwf count2 ;count2 is fast counter inside count1 loop
loop2 decfsz count2,1 ;
goto loop2 ;still > 0 so stay in loop2
goto loop1 ;count1 < 0 go to loop1
end;
can someone help me in programming our PIC16F84A, we need to make a program that will show only a three output like a traffic light,..but I am not quite familiar in programming this. I examined a 7 output LED program but i can't figure out what to changed.. I also want to changed the delay for each LED and then go back to the start of the program...Thnx
;****set up constans and variables****
INCLUDE "P16F84.INC" ;look up file for MPASM
LIST P=16F84
ERRORLEVEL -302 ;SUPPRESS BANK SELECTION MESSAGES
__config _RC_OSC&_PWRTE_ON & _WDT_OFF ;RC oscillator, power on timer
;and watchdog timer off
status equ h'03' ;status register
trisb equ h'86' ;set up register for port B
trisa equ h'85' ;set up register for port B
count1 equ h'0e' ;general purpose register
count2 equ h'0f' ;general purpose register
leds equ h'06' ;portB is 7seg display content
porta equ h'05' ;portA is not used
;****set up portA and portB****
bsf status,5 ;switch to bank1 to set up ports
movlw h'00'
movwf trisb ;portB is all output
movlw h'00'
movwf trisa ;portA is all output
bcf status,5 ;switch back to bank0 to use ports
;****main program****
start movlw b'00000001' ;load pattern into W
movwf leds ;load W into portB (switch on rightmost LED)
call delay ;wait for some time
movlw b'00000010' ;new pattern
movwf leds
call delay ;wait
movlw b'00000100' ;new pattern
movwf leds ;
call delay ;wait
movlw b'00001000' ;new pattern
movwf leds ;
call delay ;wait
goto start ;do it all over again
;****delay subroutine****
;****delay = wait (delay count value 1) x (delay count value 2) cycles****
delay movlw h'EE' ;setup delay count value 1
movwf count1 ;count1 is slow counter
loop1 decfsz count1,1 ;
goto label ;still > 0
return ;count1 < 0 so get out of the delay loop
label movlw h'EE' ;setup delay count value 2
movwf count2 ;count2 is fast counter inside count1 loop
loop2 decfsz count2,1 ;
goto loop2 ;still > 0 so stay in loop2
goto loop1 ;count1 < 0 go to loop1
end;