Something is strange. Now it work with the same variable in init and in main loops. Yesterday I tried a many time and don't worked.
@ richard : thx for your suggestions
Here is working code :
Code:#CONFIG __CONFIG _CONFIG1, _FCMEN_OFF & _FOSC_INTOSC & _WDTE_OFF & _MCLRE_OFF & _CP_ON & _IESO_OFF & _BOREN_OFF & _PWRTE_OFF __CONFIG _CONFIG2, _PLLEN_OFF & _STVREN_OFF & _LVP_OFF #ENDCONFIG DEfine OSC 4 OSCCON = %01101010 'sets the internal oscillator to 4Mhz ADCON0 = %00000000 ADCON1 = %00000000 FVRCON = %11000010 'turn fixed voltage reference on & set it to 2.048V (last two bits set the voltage ...01 =1.024V,10=2.048 CM1CON0 = 0 ' COMPARATORS OFF CM1CON1 = 0 CM2CON0 = 0 ' COMPARATORS OFF CM2CON1 = 0 CPSCON0 = 0 'CAPACTIVE SENSE MODULE OFF RCSTA.7 = 0 'SERIAL PORT OFF TRISA = %00000000 TRISC = %00000100 ANSELA = %00000000 ANSELC = %00000000 OPTION_REG.7 = 0 WPUA = %00000000 PORTA = 0 PORTC = 0 Symbol front = PORTA.4 x var byte varb var byte divf var byte x = 0 varb = 0 divf = 0 pause 100 init: pulsin portc.2 , 1, varb if (varb < 140) or (varb > 160) then init pause 100 pulsin portc.2 , 1, varb if (varb < 140) or (varb > 160) then init if (varb > 140) and (varb < 160) then goto beep goto init beep: hpwm 1 , 10, 3000 high front pause 80 low front pause 200 hpwm 1 , 5, 1200 high front pause 80 low front pause 200 hpwm 1 , 10, 3000 high front pause 80 low front '************************************************************ main: pulsin portc.2 , 1, varb hpwm 1 , x, 1954 '=======================miss signal========================= if varb < 50 then varb = 150 x=0 low front endif '============================================================ '========================front=============================== if varb> 160 then high front if varb > 190 then varb = 190 divf=255*(varb-160)/30 if x > 255 then x = 255 if divf > 255 then divf = 255 if divf >x then x=x+2 if divf <x then x=x-6 endif '============================================================ '==================== stay ================================== if varb < 160 and varb > 140 then low front x= 0 endif '============================================================= '==========================light============================== if varb < 140 and varb > 50 then high PORTA.0 else low PORTA.0 endif goto main end






Bookmarks