![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| hi guys i've just tried writing a simple program to flash some LED's On/Off Code: STATUS equ 03 PORTA equ 05 PORTB equ 06 TRISA equ 85 TRISB equ 86 RP0 equ 05 CNTR equ 0C CNTR1 equ 0D ;Program START org 0 bsf STATUS,RP0 movlw b'00000000' movwf TRISA movlw b'00000000' movwf TRISB bcf STATUS,RP0 MAIN movlw b'00000000' movwf PORTB movlw b'00000011 movwf CNTR LOOP DECFSZ CNTR,0 GOTO LOOP movlw b'11111111' movwf PORTB movlw b'00000011' movwf CNTR1 LOOP2 DECFSZ CNTR1,0 GOTO LOOP2 END is it the simulator...or is there something simple i just cant see? thanks Kane | |
| |
| | (permalink) |
| ah sorry ...i know the problem...how silly am i ..... (no dont answer that) :P the DECFSZ f,d ...i set the d to 0 instead of 1 Kane | |
| |
| | (permalink) |
| sorry another question now... how does this give a 500ms delay? Code: Delay500 clrf DelayL ; clear DelayL to 0 clrf DelayM ; clear DelayM to 0 movlw 3h ; set DelayH to 3 movwf DelayH Wait1 decfsz DelayL ; subtract 1 from DelayL goto Wait1 ; if not 0, goto Wait1 decfsz DelayM ; subtract 1 from DelayM goto Wait1 ; if not 0, goto Wait1 decfsz DelayH ; subtract 1 from DelayH goto Wait1 ; if not 0, goto Wait1 return ; finished the delay and the same for DelayM how can i calculate a delay and how many loops i need to do? say i have a 4mhz clock. that means the pic will do 4mill instructions a second? So to get a delay of 1s i would have to loop 4 million times? :? Kane | |
| |
| | (permalink) |
| Hi, If you have a look at : http://www.piclist.com you will find a delay generator there that produces code for any delay you want. I also found a neat little program that you can download that also produces the code for delay loops. Yhis can be downloaded from: http://www.mnsi.net/~boucher/picloops.html Cheers, Barry. | |
| |
| | (permalink) | |
| Quote:
Kane | ||
| |
| | (permalink) | |
| Quote:
| ||
| |
| | (permalink) | |
| Quote:
| ||
| |
| | (permalink) | |
| Quote:
http://www.piclist.com/cgi-bin/delay.exe | ||
| |
| | (permalink) |
| today is really my first day that i've actually started to program pics. and so i have quite a few questions (as you can see) so rather than start a new topic i will just add another question in here. this time... i have 2 almost identical programs....1 works whereas the other doesnt. the first one i wrote myself and with this...all the LED's came on...but it didnt seem to loop...they just stayed on. So with the second one...i copied the delay routine from a help file ...and changed nothing else (but this one works) .... they all use the same routine ... just in the one i created they have different names. Could this be anything to do with it? Below are the 2 files: File 1: Code: Title "Sequence" ;5 LEDs flash up and down ;BIT LOW = LED ON ;BIT HIGH = LED OFF ;Declarations STATUS equ 0x03 PORTA equ 0x05 PORTB equ 0x06 TRISA equ 0x85 TRISB equ 0x86 RP0 equ 0x05 LPL equ 0x0C LPM equ 0x0D LPH equ 0x0E ;Main Program START org 0x00 ;start address BSF STATUS,RP0 ;set status to page1 movlw 0x0F ;load b'1111' movwf TRISA ;move b'1111' to trisa - set all to inputs movlw 0x00 ;load b'0000000' movwf TRISB ;move b'00000000' to trisb - set all to outputs BCF STATUS,RP0 ;return to page0 BEGIN movlw 0x00 movwf PORTB CALL DoDelay movlw b'11111110' movwf PORTB CALL DoDelay movlw b'11111101' movwf PORTB CALL DoDelay movlw b'11111011' movwf PORTB CALL DoDelay movlw b'11110111' movwf PORTB CALL DoDelay movlw b'11101111' movwf PORTB CALL DoDelay GOTO BEGIN DoDelay CLRF LPL CLRF LPM movlw 0x06 movwf LPH again DECFSZ LPL GOTO again DECFSZ LPM GOTO again DECFSZ LPH GOTO again END File 2: the edited one (working) Code: Title "Sequence" ;5 LEDs flash up and down ;BIT LOW = LED ON ;BIT HIGH = LED OFF ;Declarations STATUS equ 0x03 PORTA equ 0x05 PORTB equ 0x06 TRISA equ 0x85 TRISB equ 0x86 RP0 equ 0x05 DelayL equ 0x0C DelayM equ 0x0D DelayH equ 0x0E ;Main Program START org 0x00 ;start address BSF STATUS,RP0 ;set status to page1 movlw 0x0F ;load b'1111' movwf TRISA ;move b'1111' to trisa - set all to inputs movlw 0x00 ;load b'0000000' movwf TRISB ;move b'00000000' to trisb - set all to outputs BCF STATUS,RP0 ;return to page0 BEGIN movlw 0x00 movwf PORTB CALL Delay200 movlw b'11111110' movwf PORTB CALL Delay200 movlw b'11111101' movwf PORTB CALL Delay200 movlw b'11111011' movwf PORTB CALL Delay200 movlw b'11110111' movwf PORTB CALL Delay200 movlw b'11101111' movwf PORTB CALL Delay200 GOTO BEGIN Delay200 clrf DelayL clrf DelayM movlw 1h movwf DelayH Wait1 decfsz DelayL goto Wait1 decfsz DelayM goto Wait1 decfsz DelayH goto Wait1 return Kane | |
| |
| | (permalink) |
| first off i see that your first program has no return statement.. | |
| |
| | (permalink) |
| yes ...i realised that now ... i've changed it...but still something strange is happening instead of the lights scrolling across (like they do with file2) ...they all just blink on and off :? | |
| |
| | (permalink) |
| hmmmm interesting..... i just rewrote the subroutine using lowercase instructions....and it worked :? although the call statements are in capital...they seem to work fine. oh well i guess i'll just stick to lowercase from now on Thanks Kane | |
| |
| | (permalink) |
| Hello williB, Thanks. Was in rather a hurry when I posted. :lol: Cheers, Barry. | |
| |
| | (permalink) |
| Kane ya Assembler is case sensitive.. Barry that site is 8) .. i just used a half second delay on my robo car .. lol..and it works..!! now all i have to do is transform the pascal code to assembler , to drive the steppers.. | |
| |
| | (permalink) |
| would this code work to debounce a switch? Code: START bsf STATUS,RP0 movlw 0x01 movwf TRISA movlw 0x00 movwf TRISB bcf STATUS,RP0 MAIN movlw 0x00 movwf PORTB GETPORT movlw PORTA movwf PORTSTATUS1 btfss PORTSTATUS1,0 goto GETPORT call DELAY10MS movlw PORTA movwf PORTSTATUS2 btfss PORTSTATUS2,0 goto GETPORT movlw 0xFF xorwf PORTB,1 goto GETPORT DELAY10MS clrf DelayL movlw 0x03 movwf DelayM LOOP decfsz DelayL,1 goto LOOP decfsz DelayM,1 goto LOOP return Kane | |
| |