編寫下面的實驗程序實現的功能是讓RC口所帶的8個LED一個接一個的全亮起來,最后達到全亮后再一個一個的滅下去,這樣反復循環,使用定時器查詢方式控制延時,而不使用定時器的中斷。中斷程序會在以后陸續寫到上面來
tmr0 equ 01h
pcl equ 02h
status equ 03h
option_reg equ 81h
intcon equ 0bh
portc equ 07h
trisc equ 87h
tmr0data equ 15h
count equ 20h
rp0 equ 5h
org 0000h
nop
goto main
org 0005h
main
nop
bsf status,rp0
movlw 00h
movwf trisc
movlw 07h
movwf option_reg
bcf status,rp0
clrf count
loop1
movf count,0
call read
movwf portc
incf count,1
movlw 0fh
andwf count,1
call delay
call delay
call delay
call delay
call delay
call delay
call delay
goto loop1
delay
bcf intcon,2
movlw tmr0data
movwf tmr0
delay1
btfss intcon,2
goto delay1
return
read
addwf pcl,1
retlw b'10000000'
retlw b'11000000'
retlw b'11100000'
retlw b'11110000'
retlw b'11111000'
retlw b'11111100'
retlw b'11111110'
retlw b'11111111'
retlw b'11111110'
retlw b'11111100'
retlw b'11111000'
retlw b'11110000'
retlw b'11100000'
retlw b'11000000'
retlw b'10000000'
retlw b'00000000'
end
本程序利用的16F877A的TMR0,具體如何設置請查找16F877C中的INTCON、OPTION_REG 、TMR0等相關特殊工作寄存器的功能說明。推薦李學海老師編寫的PIC單片機實用教程。
