This is a basic program for flashing led using inbuilt pwm of PIC IC
PROGRAM
#chip 16f877a, 16; ----- Constants
#define LED PORTC.2
' Adjust for Beacon Effect
#define Max_Duty 120 '~50 %
#define Flash_ON 110 ' ms
#define Flash_OFF 110 ' ms
#define Delay 20 ' ramp delay
; ----- Define Hardware settings
'CCP1 Pin Direction
DIR LED OUT 'CCP1/P1A ( Pin 13)
; ----- Variables
Dim Duty as Byte
Duty = 10 'starting Value
; ----- Main body of program commences here.
DO Forever
''' Ramp UP
Do while duty < Max_Duty
Duty = Duty + 4
HPWM 1,2, duty
wait delay ms
loop
''' Flash
HPWM 1,2, 255
Wait FLASH_ON Ms
HPWM 1,2,max_duty
Wait FLASH_OFF ms
HPWM 1, 2, 255
Wait FLASH_ON Ms
HPWM 1, 2, max_duty
Wait Flash_OFF ms
'Ramp Dowm
Do while duty > 10
Duty = Duty - 4
HPWM 1,2, duty
wait delay ms
loop
LOOP
end
0 Comments