10-17-2015, 08:27 PM
Pozdrav svima.Potrebno mi je bilo neto da moze da se menja frekvencija i perioda i napiso sam ovako za 16f628 i u proteusu radi sve kako treba ali kad sam povezao na plocici javlja se problem.Kad menjam frekvenciju menja se i perioda.U donjem redu mi pokazeje PR2 ali to cu da izmenim da pokazuje frekvenciju ako ovo gore navedeno resim.Evo koda:
cmcon=7
Define OSC 4
DEFINE LCD_BITS 4
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 2
DEFINE LCD_RWREG PORTB
DEFINE LCD_RWBIT 1
DEFINE LCD_LINES 2
pause 100
duty VAR WORD
milan var word
milan=245
duty = 100
trisa=%00111111
trisb.3=0
portb.3=0
CCP1CON = %00001100
T2CON = %00000101
lcdout $FE, 1
mainloop:
PR2 = milan
if porta.0=0 then
milan=milan-1
endif
if porta.1=0 then
milan=milan+1
endif
opet:
CCP1CON.4 = duty.0
CCP1CON.5 = duty.1
CCPR1L = DUTY >> 2
if porta.2=0 then
duty = duty + 1
lcdout $FE, $80, "DUTY=", #duty
pause 10
IF ( duty < 500) Then opet:
duty = 500
endif
if porta.3=0 then
duty=duty-1
lcdout $FE, $80, "DUTY=", #duty
pause 10
if duty > 101 then opet:
duty=100
endif
lcdout $FE, $80, "DUTY=", #duty
lcdout $fe,$c0
lcdout "f=",#milan
GoTo mainloop
End
cmcon=7
Define OSC 4
DEFINE LCD_BITS 4
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 2
DEFINE LCD_RWREG PORTB
DEFINE LCD_RWBIT 1
DEFINE LCD_LINES 2
pause 100
duty VAR WORD
milan var word
milan=245
duty = 100
trisa=%00111111
trisb.3=0
portb.3=0
CCP1CON = %00001100
T2CON = %00000101
lcdout $FE, 1
mainloop:
PR2 = milan
if porta.0=0 then
milan=milan-1
endif
if porta.1=0 then
milan=milan+1
endif
opet:
CCP1CON.4 = duty.0
CCP1CON.5 = duty.1
CCPR1L = DUTY >> 2
if porta.2=0 then
duty = duty + 1
lcdout $FE, $80, "DUTY=", #duty
pause 10
IF ( duty < 500) Then opet:
duty = 500
endif
if porta.3=0 then
duty=duty-1
lcdout $FE, $80, "DUTY=", #duty
pause 10
if duty > 101 then opet:
duty=100
endif
lcdout $FE, $80, "DUTY=", #duty
lcdout $fe,$c0
lcdout "f=",#milan
GoTo mainloop
End