16f877 3 Tane Pwm 3 Timer0 Timer1 Timer2

Başlatan Tarik konca, 30 Ağustos 2023, 15:50:20

Tarik konca

16f877 3 tane pwm

anlatilacak her sey onceki yazilarda olanlarla ayni

timer0 timer1 ve timer2 unitelerini kullandim

fazla konusmaya gerek yok bu sefer 16f877 de adc oldugu icin

3 tane pot bagladim onlarla pwm leri kontrol edebiliyorsunuz

yine farkindayim 16f877 de 2 tane donanimsal pwm var onlari simdi kullanmadim

bir sonraki yazida

mikrobasic ve proteus dosyalari ekde




program MyProject
dim pwm0_duty ,pwm1_duty ,pwm2_duty ,tmr0_duty,tmr0_tmp ,tmr1_duty,tmr1_tmp ,tmr2_duty ,tmr2_tmp,adc_sec,adc_sayac as byte

sub procedure interrupt() iv 0x0004 ics ICS_AUTO
 if  intcon.TMR0IF=1 then
  intcon.TMR0IF=0
  intcon.tmr0ie=0
   if portb.0=1 then
     tmr0_tmp=tmr0_duty
   end if
   if portb.0=0 then
     tmr0_tmp=255-tmr0_duty
     tmr0_duty=pwm0_duty
   end if
   portb.0=not portb.0
   tmr0=tmr0_tmp
    intcon.tmr0ie=1
end if


 if  PIR1.TMR1IF =1 then
     PIR1.TMR1IF = 0
     pie1.tmr1ie=0
   if portb.1=1 then
     tmr1_tmp=tmr1_duty
   end if
   if portb.1=0 then
     tmr1_tmp=255-tmr1_duty
     tmr1_duty=pwm1_duty
   end if
   portb.1=not portb.1
   tmr1h=255
   tmr1l=tmr1_tmp
   pie1.tmr1ie=1
end if

if  PIR1.TMR2IF =1 then
   PIR1.TMR2IF = 0
   pie1.tmr2ie=0
   if portb.2=1 then
     tmr2_tmp=tmr2_duty
   end if
   if portb.2=0 then
     tmr2_tmp=255-tmr2_duty
     tmr2_duty=pwm2_duty
   end if
   portb.2=not portb.2
   tmr2=tmr2_tmp
   pie1.tmr2ie=1
end if
end sub
main:
trisb=0
portb.0=1
portb.2=1
portb.5=1
portb=0
trisc=0
trisd=0

INTCON = %11100000
OPTION_REG = %00001000

T1CON = %00000101
PIR1.TMR1IF = 0
PIE1.TMR1IE  = 1

T2CON=%10000100
PIE1.TMR2IE = 1

adcon1.adfm=0
adcon1.3=0
adcon1.2=0
adcon1.1=0
adcon1.0=0

adcon0.adon=1
adcon0.3=0
adcon0.4=0
adcon0.5=0
adcon0.1=1
adcon0.7=0
adcon0.6=1
adc_sec=0

adc_set:
adcon0.2=1
while adcon0.2=1
wend

if adc_sec=0 then
tmr0_duty=adresh
adcon0.3=1
adcon0.4=0
adcon0.5=0
end if

if adc_sec=1 then
tmr1_duty=adresh
adcon0.3=0
adcon0.4=1
adcon0.5=0
end if

if adc_sec=2 then
tmr2_duty=adresh
adcon0.3=0
adcon0.4=0
adcon0.5=0
end if

adc_sec=adc_sec+1

if adc_sec=3 then
adc_sec=0
end if

goto adc_set
end.

Tek Care Format C:

Powered by EzPortal