;ledsrun.asm
;example program with PIC16F84 µcontroller
;connect four leds with a 470 ohm series resistor to RB0 TO 3
;and a 10k / 27pF RC-oscillator
;the LEDS will light up as a running light
;written in MPASM MICROCHIP assembler
;****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;
asic1984 said:hi
thanks too much C-man for your help.....but i already do that ........and i have same strange problem
i wanna ask is that possible that pic be burned by some how and the ic-prog verifying the memory only!!!!
thanks too much
processor 16f877
radix hex
#include <p16f877.inc>
org 0x00
goto start
org 0x06
start bsf 03h,5 ;bank 1
movlw 0x00
movwf 86h ;portb output
bcf 83h,5 ;bank 0
movlw 0xff
movwf PORTB
end
asic1984 said:so does this pic needs any other configurations or what ?
PROCESSOR 16f84
radix hex
#include "p16f84a.inc"
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
org 0x00
goto start1
;*****Set up the Constants****
org 0x06
COUNT1 equ 0x09 ;First counter for our delay loops
COUNT2 equ 0x10 ;Second counter for our delay loops
Count3 equ 0x11
;****Set up the port****
start1 bsf STATUS,5 ;Switch to Bank 1
movlw 00h ;Set the Port A pins
movwf TRISA ;to output.
bcf STATUS,5 ;Switch back to Bank 0
;****Turn the LED on****
Start movlw 0xff ;Turn the LED on by first putting
movwf PORTA ;it into the w register and then
;on the port
;****Start of the delay loop 1****
Loop1 decfsz COUNT1,1 ;Subtract 1 from 255
goto Loop1 ;If COUNT is zero, carry on.
decfsz COUNT2,1 ;Subtract 1 from 255
goto Loop1 ;Go back to the start of our loop.
decfsz Count3,1
goto Loop1
;This delay counts down from
;255 to zero, 255 times
;****Delay finished, now turn the LED off****
movlw 00h ;Turn the LED off by first putting
movwf PORTA ;it into the w register and then on
;the port
;****Add another delay****
Loop2 decfsz COUNT1,1 ;This second loop keeps the
goto Loop2 ;LED turned off long enough for
decfsz COUNT2,1 ;us to see it turned off
goto Loop2 ;
decfsz Count3,1
goto Loop2
;****Now go back to the start of the program
goto Start ;go back to Start and turn LED
;on again
;****End of the program****
end ;Needed by some compilers,
;and also just in case we miss the goto instruction.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?