Its PWM code using a lookup table.. If I run it through mplab sim, it follows the code through. However, in real life the LED just stays full on...
Code:
;PWM test using a lookup table.
list P=16f676
#include <p16f676.inc>
__config _HS_OSC & _BODEN_OFF & _WDT_OFF & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _CP_OFF
cblock 20h
BH,BL,wait,del_clk1,del_clk2,run,runn,pc,tmp,count
endc
t equ 0x02
RESET_VECTOR CODE 0X000
goto main
main
bsf STATUS,RP0 ;bank 1
movlw 0x00
movwf OSCCAL
movlw 0x00
movwf TRISC ;make all PORTC outputs
movlw 0xff
movwf TRISA ;make all PORTA inputs
movlw 0x07
movwf OPTION_REG
bcf STATUS,RP0
CLRF TMR0
BCF INTCON,5
movlw 0x07 ;turn off comparitors
movwf CMCON
clrf pc
start
movlw 0xff ;adjustment for speed of fade
movwf runn
l1 btfsc PORTA,0 ;call to see if low, if low make fade slower
goto l1
call loopfi
goto start
loopfi
call loop20
return
loopfo
call firstt
return
loop20
movf runn,0
movwf run
on
movlw 0xff
movwf PORTC ;turn on leds
movf tmp,BH ;set on time of duty cycle
loopon
decfsz BH,1 ;count down the on time
goto loopon
movlw 0x00 ;turn leds off
movwf PORTC
movf tmp,BH ;set off time of duty cycle
loopoff
incfsz BH,1 ;count up to the off time
goto loopoff
decfsz run,1 ;run the PWM for a moment
goto on
incf pc
movf pc,w
sublw .10
btfsc STATUS,2
clrf pc
movf pc,w
call value
movwf tmp
goto loop20
return
value
addwf t
retlw 0x08
retlw 0x0f
retlw 0x16
retlw 0x1d
retlw 0x24
retlw 0x2b
retlw 0x32
retlw 0x39
retlw 0x40
retlw 0x47
retlw 0x4e
retlw 0x55
retlw 0x5c
retlw 0x63
retlw 0x6a
retlw 0x71
retlw 0x78
retlw 0x7f
retlw 0x86
retlw 0x8d
retlw 0x94
retlw 0x9b
retlw 0xa2
retlw 0xa9
retlw 0xb0
retlw 0xb7
end
Last edited by a moderator: