好的,所以我写了一个 .asm 来操作 3 个 LED,但我很久以前就做过了,对命令/结构非常生疏。我什至无法弄清楚这个脚本到底是做什么的!
据我所知,它以 0-7 的二进制计数(3 个 LED = 0-7?)。
我的问题是:如何在 LED 开启之间添加约 1 秒的延迟,以使其充当基本的视觉二进制时钟?
非常感谢。
; WRITTEN BY JL
; DATE 28/03/05
; FILE SAVED AS SAMPLE6.ASM
; DEVICE PIC16F684
; OSCILLATOR XT (4MHZ)
; WATCHDOG DISABLED
; FUNCTION LEDs are switched ON in a binary sequence
list p=16f684 ; list directive to define processor
#include <p16f684.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF &_PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _CPD_OFF
;*******************************Equates****************************************
PORTA EQU 05h
COUNT1 EQU 20h; Set up two counters to count down a delay
COUNT2 EQU 21h
;*******************************Defines****************************************
; define input/output designation for LEDs (what TRISA will equal)
#define TRIS_D0_D1 B'00001111' ; TRISIO setting for D0 and D1
#define TRIS_D2_D3 B'00101011' ; TRISIO setting for D2 and D3
#define TRIS_D4_D5 B'00011011' ; TRISIO setting for D4 and D5
; define LED state (what PORTA will equal)
#define D0_ON B'00010000' ; D0 LED
#define D1_ON B'00100000' ; D1 LED
#define D2_ON B'00010000' ; D2 LED
;****************************** Start of Program ******************************
org 0x000 ; processor reset vector
;************* Initialize PortA **********
movlw B'00111111' ; Set all I/O pins of PORTA as inputs
TRIS PORTA
clrf PORTA ; clear all outputs
;************** LED0 ON *********************
START movlw TRIS_D0_D1 ; move predefined value to TRISA to switch ON LED0
TRIS PORTA
movlw D0_ON ; move predefined value to PORTA TO switch ON LED0
movwf PORTA
decfsz COUNT1,1 ;Subtract 1 from 00h (this gives 255 or FFh)
goto START ;If COUNT is zero, carry on.
decfsz COUNT2,1 ;Subtract 1 from 00h
goto START ;Go back to the start of our loop
;************** LED1 ON *********************
LOOP2 movlw D1_ON ; move predefined value to PORTA TO switch ON LED1
movwf PORTA
decfsz COUNT1,1 ;Subtract 1 from 00h (this gives 255 or FFh)
goto LOOP2 ;If COUNT is zero, carry on.
decfsz COUNT2,1 ;Subtract 1 from 00h
goto LOOP2 ;Go back to the start of our loop
;************** LED0 and LED1 ON **************
LOOP3 movlw D0_ON ; move predefined value to PORTA TO switch ON LED0
movwf PORTA
movlw D1_ON ; move predefined value to PORTA TO switch ON LED1
movwf PORTA
decfsz COUNT1,1 ;Subtract 1 from 00h (this gives 255 or FFh)
goto LOOP3 ;If COUNT is zero, carry on.
decfsz COUNT2,1 ;Subtract 1 from 00h
goto LOOP3 ;Go back to the start of our loop
;************** LED2 ON *********************
LOOP4 movlw TRIS_D2_D3 ; move predefined value to TRISA to switch ON LED2
TRIS PORTA
movlw D2_ON ; move predefined value to PORTA TO switch ON LED2
movwf PORTA
decfsz COUNT1,1 ;Subtract 1 from 00h (this gives 255 or FFh)
goto LOOP4 ;If COUNT is zero, carry on.
decfsz COUNT2,1 ;Subtract 1 from 00h
goto LOOP4 ;Go back to the start of our loop
;************** LED0 and LED2 ON **************
LOOP5 movlw TRIS_D0_D1 ; move predefined value to TRISA to switch ON LED0
TRIS PORTA
movlw D0_ON ; move predefined value to PORTA TO switch ON LED0
movwf PORTA
movlw TRIS_D2_D3 ; move predefined value to TRISA to switch ON LED2
TRIS PORTA
movlw D2_ON ; move predefined value to PORTA TO switch ON LED2
movwf PORTA
decfsz COUNT1,1 ;Subtract 1 from 00h (this gives 255 or FFh)
goto LOOP5 ;If COUNT is zero, carry on.
decfsz COUNT2,1 ;Subtract 1 from 00h
goto LOOP5 ;Go back to the start of our loop
;************** LED1 and LED2 ON **************
LOOP6 clrf PORTA ; clear all outputs
movlw TRIS_D0_D1 ; move predefined value to TRISA to switch ON LED1
TRIS PORTA
movlw D1_ON ; move predefined value to PORTA TO switch ON LED1
movwf PORTA
movlw TRIS_D2_D3 ; move predefined value to TRISA to switch ON LED2
TRIS PORTA
movlw D2_ON ; move predefined value to PORTA TO switch ON LED2
movwf PORTA
decfsz COUNT1,1 ;Subtract 1 from 00h (this gives 255 or FFh)
goto LOOP6 ;If COUNT is zero, carry on.
decfsz COUNT2,1 ;Subtract 1 from 00h
goto LOOP6 ;Go back to the start of our loop
;************** LED0,LED1 and LED2 ON **************
LOOP7 movlw TRIS_D0_D1 ; move predefined value to TRISA to switch ON LED0 and LED1
TRIS PORTA
movlw D0_ON ; move predefined value to PORTA TO switch ON LED0
movwf PORTA
movlw D1_ON ; move predefined value to PORTA TO switch ON LED1
movwf PORTA
movlw TRIS_D2_D3 ; move predefined value to TRISA to switch ON LED2
TRIS PORTA
movlw D2_ON ; move predefined value to PORTA TO switch ON LED2
movwf PORTA
decfsz COUNT1,1 ;Subtract 1 from 00h (this gives 255 or FFh)
goto LOOP7 ;If COUNT is zero, carry on.
decfsz COUNT2,1 ;Subtract 1 from 00h
goto LOOP7 ;Go back to the start of our loop
;**********End of program *****************
goto START ; indefinite loop
END ; End instruction is needed by some compilers and also useful in case we miss goto instruction
;*********************************************************************************