Well I'm going out to one of the weekly theatre set build evenings in an hour, so just enough time to update the program so that we can flash the LED... A little lookign through the assembly commands, and looking back at some of my old applications which were probably based on the PICkit examples, I did the following:
1) Added two new variables so we can have a loop which loops a certain number of times before we next change the LED. Since the Processor will be running many many commands a second, we need to wait a number of oscillator ticks before changing the LED state. So adding two variables after the UDATA_ACS line:
UDATA_ACS
CNT_INNER RES 1 ; Inner Loop Count
CNT_OUTER RES 1 ; Outer Loop Count
2) Added code to the Mains ection of the program which initializes the LED, (we have that code already), then to turn the LED on, followed by a call to a Delay procedure to wait a bit. This is followed by turning the LED off and another delay procedure call...
Main:
Initialize
clrf WREG ; Clear the W-Register
movwf TRISA ; W-REG to PORTA to set as all outputs
Turn_LED_ON
movlw 0xFF ; Set all bits in the WREG
movwf PORTA ; Update PORTA to turn the LED on
call Delay ; Call the Delay procedure to wait a bit
Turn_LED_OFF
clrf WREG ; Clear the WREG
movwf PORTA ; Update PORTA to turn the LED off
call Delay ; Call the Delay procedure to wait a bit
goto Turn_LED_ON ; Go back to the LED ON for an Infinite loop
3) Of course we then need to have the Delay procedure somewhere, so I'll place it after the command to go back to the turning the LED on label...
Delay
movlw 0x40 ; Initialize outer loop counter (0x40 - 128)
movwf CNT_OUTER,A ; Set outer loop variable to the counter
DelayOuter
movlw 0xFF ; Initialize inner loop counter (0xFF - 255)
movwf CNT_INNER,A ; Set inner loop variable to the counter
DelayInner
decfsz CNT_INNER,F,A ; Decrease Inner counter, skip next on 0
goto DelayInner ; Go to the next Inner count, (NOP on 0 CNT_INNER)
DelayInner_End
decfsz CNT_OUTER,F,A ; Decrease Outer counter, skip next on 0
goto DelayOuter ; Go to the next Outer count, (NOP on 0 CNT_OUTER)
DelayOuter_End
return ; Return back to the place which called this proc
Compiling it, it succeeded! So program the chip, then release from reset, and yay a flashing LED...
No comments:
Post a Comment