编写下面的实验程序实现的功能是让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单片机实用教程。
