Hi there,
I'm trying to make an LED blinking program with controlled brightness by PWM, I'm using 16f690 low pin count demo board of Microchip, four LEDs connected at PORTC (<0-3>), Here is my code, please ignore those routines labled timer<1-4> I really messed up with that but that will give you an idea of what I'm trying to do.........
now I know the problem (I think so) and the solution too, but don't know how to implement it. The problem is that the "bright" routine.........
SHOULD KEEP RUNNING during the "delay" period
, now I can either use TIMER set for time equal to delay and loop the "bright" until the T0IF flag get set (that is what I tried with those ugly timer<1-4> routine, ps ignore them)...............
OR,
I can compare the value of "d2" with comparator but, that too uses timer values to compare and the "delay " routine is of 24mSec so don't know how to do these both.
If any one have good links (with .ASM not C) to learn comparator and PWM then please guide me. I'll really appreciate any help.
I'm trying to make an LED blinking program with controlled brightness by PWM, I'm using 16f690 low pin count demo board of Microchip, four LEDs connected at PORTC (<0-3>), Here is my code, please ignore those routines labled timer<1-4> I really messed up with that but that will give you an idea of what I'm trying to do.........
Code:
List p=16f690
#include<p16f690.inc>
__CONFIG _MCLRE_ON & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT
ERRORLEVEL-302
;**********************************************************************
cblock 0x20
temp
d1
d2
don
doff
dis
endc
;***********************************************************************
org 0x00
goto main
;***********************************************************************
main:
portset:
bsf STATUS,RP0
clrf TRISA
clrf TRISB
clrf TRISC
movlw b'00000111'
movwf OPTION_REG
bcf STATUS,RP0
start:
call bright
movlw b'00000000'
movwf PORTC
call delay
goto start
delay:
decfsz d1
goto delay
decfsz d2
goto delay
return
bright:
movlw d'56'
movwf don
movlw b'00000001'
movwf PORTC
call delayon
movlw d'200'
movwf doff
movlw b'00000000'
movwf PORTC
call delayoff
timer1:
btfss INTCON,T0IF
goto timer1
banksel OPTION_REG
bsf OPTION_REG,T0CS
banksel INTCON
bcf INTCON,T0IF
timer2:
banksel OPTION_REG
bcf OPTION_REG,T0CS
btfss INTCON,T0IF
goto timer2
bsf OPTION_REG,T0CS
banksel INTCON
bcf INTCON,T0IF
timer3:
banksel OPTION_REG
bcf OPTION_REG,T0CS
btfss INTCON,T0IF
goto timer3
bsf OPTION_REG,T0CS
banksel INTCON
bcf INTCON,T0IF
timer4:
banksel OPTION_REG
bcf OPTION_REG,T0CS
btfss INTCON,T0IF
goto timer4
bsf OPTION_REG,T0CS
banksel INTCON
bcf INTCON,T0IF
return
delayon:
decfsz don
goto delayon
return
delayoff:
decfsz doff
goto delayoff
return
end
Code:
bright:
movlw d'56'
movwf don
movlw b'00000001'
movwf PORTC
call delayon
movlw d'200'
movwf doff
movlw b'00000000'
movwf PORTC
call delayoff
Code:
delay:
decfsz d1
goto delay
decfsz d2
goto delay
return
OR,
I can compare the value of "d2" with comparator but, that too uses timer values to compare and the "delay " routine is of 24mSec so don't know how to do these both.
If any one have good links (with .ASM not C) to learn comparator and PWM then please guide me. I'll really appreciate any help.