program fors_cleaner symbol F1 = PORTB.0 symbol F2 = PORTB.1 symbol F3 = PORTB.2 symbol F4 = PORTB.3 Symbol Led1 = PORTC.0 symbol Key1 = PORTA.1 symbol Key2 = PORTA.2 symbol Key3 = PORTA.3 symbol Key4 = PORTA.4 symbol Key5 = PORTA.5 symbol StartStop = PORTB.4 const Menutxt1="Eeprom read " const Menutxt2="Eeprom write " const Menutxt3="Set inj time " const Menutxt4="Set free time " const Menutxt5="Set default " const Menutxt6=" " const Menutxt7=" " const Menutxt8=" " const Menutxt9=" " dim text, text1, text2 as char[20] dim MyPause as word Dim MyPause1 as word Dim StartStop1 as byte Dim Mode, ByteH, ByteL as byte 'mode dim i, MenuIndex, LastMenuIndex, Otvet as byte dim counter as word sub procedure Startkey() if StartStop=0 then ' proverka keyb StartStop Delay_ms(300) 'drebezg kontaktov if StartStop1=0 then StartStop1=1 goto Next1 end if if StartStop1=1 then StartStop1=0 goto Next1 end if end if Led1=StartStop1 Next1: end sub sub procedure Pause(dim value as byte) 'delay_ms(100) while value>1 dec(value) delay_ms(1) wend end sub sub procedure interrupt if PIR1.TMR1IF=1 then inc(counter) if counter > 100 then counter=0 ' LATB.6 = not (PORTB.6) ' PORTB.7=not PORTB.7 end if Startkey() PIR1.TMR1IF = 0 ' clear TMR1IF TMR1H = $80 TMR1L = $00 'T1CON = 1 ' timer1 settings 'INTCON = $C0 ' set GIE, PEIE 'PIE1.TMR1IE = 1 ' enable Timer1 interrupt end if end sub main: TRISA=%11111111 ADCON1=%00001110 TRISB=%00110000 TRISC=0 portc=0 PORTB=0 counter=0 T1CON = 1 ' timer1 settings PIR1.TMR1IF = 0 ' clear TMR1IF TMR1H = $80 ' initialize Timer1 register TMR1L = $00 PIE1.TMR1IE = 1 ' enable Timer1 interrupt INTCON = $C0 ' set GIE, PEIE MenuIndex=1 StartStop=0 Mode=0 F1=0 F2=0 F3=0 F4=0 DELAY_ms(100) Lcd_Config(PORTC,7,6,5,4,PORTC,1,2,3) DELAY_ms(100) Lcd_Cmd(Lcd_CURSOR_OFF) ' Turn off cursor text = "by vv (ver.1.6)" Lcd_Out(2, 1, text) text = " Cleaner force" Lcd_Out(1, 1, text) ByteH=Eeprom_Read($00) delay_ms(20) ByteL=Eeprom_Read($01) MyPause=ByteH*256 + ByteL delay_ms(20) ByteH=Eeprom_Read($10) delay_ms(20) ByteL=Eeprom_Read($11) MyPause1=ByteH*256 + ByteL delay_ms(1000) while startstop=1 asm nop end asm wend delay_ms(500) StartStop1=0 text = " " Lcd_Out(1, 1, text) Lcd_Out(2, 1, text) Start1: if Key1=0 then delay_ms(300) inc(mode) if Mode>=4 then Mode=0 end if end if if key2=0 then delay_ms(300) StartStop1=0 gosub Menu01 end if gosub OnOff select case Mode case 0 text = " 1-2-3-4 " text[0]=chr(%11001001) Lcd_Out(1, 1, text) ' Print text at LCD wordtostr(MyPause,text) lcd_out(1,10,text) wordtostr(MyPause1,text) lcd_out(2,5,text) lcd_out(1,15,"ms") lcd_out(2,10,"ms") if StartStop1=1 then goto cleaner1 end if case 1 text = " 4-4-4-4 " text[0]=chr(%11001001) Lcd_Out(1, 1, text) ' Print text at LCD wordtostr(MyPause,text) lcd_out(1,10,text) lcd_out(1,15,"ms") wordtostr(MyPause1,text) lcd_out(2,5,text) lcd_out(2,10,"ms") if StartStop1=1 then goto cleaner2 end if case 2 text = " 1-2-3-4* " text[0]=chr(%11001001) Lcd_Out(1, 1, text) ' Print text at LCD wordtostr(MyPause,text) lcd_out(1,10,text) lcd_out(1,15,"ms") wordtostr(MyPause1,text) lcd_out(2,5,text) lcd_out(2,10,"ms") if StartStop1=1 then goto cleaner3 end if case 3 text = " 4-4-4-4 1 sec " text[0]=chr(%11001001) Lcd_Out(1, 1, text) ' Print text at LCD lcd_out(2,4," ") if StartStop1=1 then goto cleaner4 end if end select goto start1 Cleaner1: gosub Stop1 gosub OnOff F1=1 gosub led2 Pause(MyPause) gosub Stop1 F1=0 F2=0 F3=0 F4=0 gosub led2 Pause(mypause1) gosub Stop1 F2=1 gosub led2 Pause(MyPause) gosub Stop1 F1=0 F2=0 F3=0 F4=0 gosub led2 Pause(mypause1) gosub Stop1 F3=1 gosub led2 Pause(MyPause) gosub Stop1 F1=0 F2=0 F3=0 F4=0 gosub led2 Pause(mypause1) gosub Stop1 F4=1 gosub led2 Pause(MyPause) gosub Stop1 F1=0 F2=0 F3=0 F4=0 gosub led2 Pause(mypause1) goto start1 Cleaner2: gosub OnOff gosub Stop1 F1=1 F2=1 F3=1 F4=1 gosub led2 Pause(MyPause) F1=0 F2=0 F3=0 F4=0 gosub led2 gosub Stop1 Pause(mypause1) goto start1 Cleaner3: gosub OnOff gosub Stop1 F1=0 F2=0 F3=0 F4=0 gosub led2 for i=1 to 5 gosub Stop1 F1=1 gosub led2 Pause(MyPause) gosub Stop1 F1=0 gosub led2 Pause(MyPause1) next i for i=1 to 5 F2=1 gosub led2 gosub Stop1 Pause(MyPause) F2=0 gosub led2 gosub Stop1 Pause(MyPause1) next i for i=1 to 5 F3=1 gosub led2 gosub Stop1 Pause(MyPause) F3=0 gosub led2 gosub Stop1 Pause(MyPause1) next i for i=1 to 5 F4=1 gosub led2 gosub Stop1 Pause(MyPause) F4=0 gosub led2 gosub Stop1 Pause(MyPause1) next i F1=0 F2=0 F3=0 F4=0 gosub led2 goto start1 Cleaner4: gosub OnOff gosub Stop1 F1=0 F2=0 F3=0 F4=0 gosub led2 F1=1 F2=1 F3=1 F4=1 gosub led2 Delay_ms(1000) F1=0 F2=0 F3=0 F4=0 gosub led2 StartStop1=0 goto start1 Stop1: if StartStop1=0 then F1=0 F2=0 F3=0 F4=0 gosub OnOff gosub led2 goto start1 end if return Led2: text="" if F1=1 then text[0]=chr(217) Lcd_Out(2, 13,text) end if if F1=0 then text[0]=chr(218) Lcd_Out(2, 13, text) end if if F2=1 then text[0]=chr(217) Lcd_Out(2, 14, text) end if if F2=0 then text[0]=chr(218) Lcd_Out(2, 14, text) end if if F3=1 then text[0]=chr(217) Lcd_Out(2, 15, text) end if if F3=0 then text[0]=chr(218) Lcd_Out(2, 15, text) end if if F4=1 then text[0]=chr(217) Lcd_Out(2, 16, text) end if if F4=0 then text[0]=chr(218) Lcd_Out(2, 16, text) end if return Menu01: MenuIndex=1 PIE1.TMR1IE = 0 Menu02: 'главная ветка text=menutxt1 Lcd_out(2,1,text) while true 'бесконечный цикл - перебор вариантов меню if MenuIndex>9 then 'переход на подветки goto menu03 end if 'проход по главному меню if Key2=0 then 'exit menu delay_ms(300) lcd_out(2,1," ") lcd_out(1,1," ") PIE1.TMR1IE = 1 goto start1 end if text="Menu: " LCD_out(1,1, text) text=" " if Key3=0 then delay_ms(300) inc(menuindex) if MenuIndex>5 then MenuIndex=5 end if end if if Key4=0 then delay_ms(300) dec(menuindex) if MenuIndex<1 then MenuIndex=1 end if end if select case MenuIndex case 1 lcd_out(1,10,"<+---->") text=menutxt1 lcd_out(2,1,text) if Key5=0 then delay_ms(300) LastMenuIndex=1 Otvet=0 MenuIndex=13 end if case 2 lcd_out(1,10,"<-+--->") text=menutxt2 lcd_out(2,1,text) if Key5=0 then delay_ms(300) LastMenuIndex=2 Otvet=0 MenuIndex=14 end if case 3 lcd_out(1,10,"<--+-->") text=menutxt3 lcd_out(2,1,text) if Key5=0 then delay_ms(300) LastMenuIndex=3 MenuIndex=11 end if case 4 lcd_out(1,10,"<---+->") text=menutxt4 lcd_out(2,1,text) if Key5=0 then delay_ms(300) LastMenuIndex=4 MenuIndex=12 end if case 5 'default lcd_out(1,10,"<----+>") text=menutxt5 lcd_out(2,1,text) if Key5=0 then delay_ms(300) LastMenuIndex=5 MenuIndex=15 end if case else end select menu03: 'подветки установки времени впрыска - времени паузы - чтения записи значений еепром select case MenuIndex case 11 'установка времени впрыска lcd_out(1,1,"Set inj time ") if Key3=0 then delay_ms(300) if MyPause <50000 then Mypause=mypause+1 end if end if if Key4=0 then delay_ms(300) if MyPause > 1 then Mypause=MyPause-1 end if end if if Key5=0 then delay_ms(300) MenuIndex=LastMenuIndex goto menu02 end if wordtostr(MyPause,text) Strcat(text," ms ") lcd_out(2,1,text) case 12 'установка времени паузы lcd_out(1,1,"Set free time ") if Key5=0 then delay_ms(300) MenuIndex=LastMenuIndex goto menu02 end if if Key3=0 then delay_ms(300) if MyPause1 <5000 then Mypause1=Mypause1+10 end if end if if Key4=0 then delay_ms(300) if MyPause1 > 10 then Mypause1=MyPause1-10 end if end if wordtostr(MyPause1,text) Strcat(text," ms ") lcd_out(2,1,text) case 13 lcd_out(1,1,"Read from eprom?") if Key3=0 then delay_ms(300) Otvet=1 end if if Key4=0 then delay_ms(300) Otvet=0 end if if Otvet=1 then text="Yes" end if if Otvet=0 then text="No " end if if Otvet=0 then 'выход из подменю без чтения if Key5=0 then delay_ms(300) MenuIndex=LastMenuIndex goto menu02 end if end if if Otvet=1 then 'чтение еепром if Key5=0 then delay_ms(300) ByteH=Eeprom_Read($00) delay_ms(20) ByteL=Eeprom_Read($01) MyPause=ByteH*256 + ByteL delay_ms(20) ByteH=Eeprom_Read($10) delay_ms(20) ByteL=Eeprom_Read($11) MyPause1=ByteH*256 + ByteL lcd_out(1,1,"Read Ok ") wordtostr(MyPause,text1) wordtostr(MyPause1,text2) Strcat(text1," ") Strcat(text2," ") Strcat(text1,text2) Strcat(text1,text) lcd_out(2,1,text1) delay_ms(2000) MenuIndex=LastMenuIndex goto menu02 end if end if wordtostr(MyPause,text1) wordtostr(MyPause1,text2) Strcat(text1," ") Strcat(text2," ") Strcat(text1,text2) Strcat(text1,text) lcd_out(2,1,text1) case 14 lcd_out(1,1,"Write to eeprom?") if Key3=0 then delay_ms(300) Otvet=1 end if if Key4=0 then delay_ms(300) Otvet=0 end if if Otvet=1 then text="Yes" end if if Otvet=0 then text="No " end if wordtostr(MyPause,text1) wordtostr(MyPause1,text2) Strcat(text1," ") Strcat(text2," ") Strcat(text1,text2) Strcat(text1,text) lcd_out(2,1,text1) if Otvet=0 then 'выход из подменю без чтения if Key5=0 then delay_ms(300) MenuIndex=LastMenuIndex goto menu02 end if end if if Otvet=1 then 'запись еепром if Key5=0 then delay_ms(300) i=lo(MyPause) eeprom_write($01,i) i=Hi(MyPause) eeprom_write($00,i) i=lo(MyPause1) eeprom_write($11,i) i=Hi(MyPause1) eeprom_write($10,i) lcd_out(1,1,"Write Ok ") wordtostr(MyPause,text1) wordtostr(MyPause1,text2) Strcat(text1," ") Strcat(text2," ") Strcat(text1,text2) Strcat(text1,text) lcd_out(2,1,text1) delay_ms(2000) MenuIndex=LastMenuIndex goto menu02 end if end if case 15 'значения по дефолту lcd_out(1,1," Set default? ") if Key3=0 then delay_ms(300) Otvet=1 end if if Key4=0 then delay_ms(300) Otvet=0 end if if Otvet=1 then text1="Yes" end if if Otvet=0 then text1="No " end if text=" 5ms - 50ms " Strcat(text, text1) lcd_out(2,1,text) if Otvet=0 then 'выход из подменю без сброса if Key5=0 then delay_ms(300) MenuIndex=LastMenuIndex goto menu02 end if end if if Otvet=1 then 'set default if Key5=0 then delay_ms(300) MyPause=5 MyPause1=50 lcd_out(1,1," Default Ok ") wordtostr(MyPause,text1) wordtostr(MyPause1,text2) Strcat(text1," ") Strcat(text2," ") Strcat(text1,text2) Strcat(text1,text) lcd_out(2,1,text1) delay_ms(2000) MenuIndex=LastMenuIndex goto menu02 end if end if case else end select wend return OnOff: if StartStop1=0 then text="Off" end if if StartStop1=1 then text=" On" end if Lcd_Out(2, 1, text) return end.