Title induction cooker controller ;OSC:16.000MHz chip SN8P1706 //{{SONIX_CODE_OPTION .Code_Option OSG Enable .Code_Option High_Clk 12M_X'tal .Code_Option High_Clk/2 Disable .Code_Option Security Enable .Code_Option LVD Enable .Code_Option Watch_Dog Enable //}}SONIX_CODE_OPTION ;\\\\\\\\\\\\\\\\\\\\\\\\\\\\ InitPort macro MOV a,#01110000b ;p4.7,p4.3 as A/D input b0MOV P4M,a MOV a,#00111111b b0MOV P5M,a MOV a,#0xff b0MOV P2M,a MOV a,#11000000b b0MOV P1M,a @set_pur 0x23 clr P1 clr P2 clr P4 clr P5 MOV a,#0x44 b0MOV TC1M,a MOV a,#225 ;225 b0MOV TC1R,a b0bset FTC1OUT ;buzzer on b0bset FTC1ENB MOV a,#11110101b ;1:16 16uS b0MOV TC0M,a MOV a,#0xff b0MOV TC0R,a MOV a,#11110000b ;1:2 1uS b0MOV T0M,a MOV a,#00010000b b0MOV INTEN,a clr INTRQ endm ;\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ;***************************** ;clear ram (00h-->7fh) ;***************************** ClearRam macro clr Y b0MOV Z,#0x7f Clear_Ram01: clr @YZ decms Z jmp Clear_Ram01 endm ;\\\\\\\\\\\\\\\\\\\\\\ BuzzerActive macro b0bts1 BuzzerEnable jmp BuzzerStop b0MOV a,BuzNumber b0bts0 FZ jmp BuzzerStop b0bts1 BuzzerShort jmp BuzNormal01 MOV a,#50 jmp BuzNormal02 BuzNormal01: MOV a,#100 BuzNormal02: sub a,TimerBuz b0bts0 FC jmp BuzzerRet ;else buzzer time over BuzzerTimeOver: clr TimerBuz b0bts1 BuzzerIsOn jmp BuzzerTimeOver01 b0bclr BuzzerIsOn ;buzzer on b0bset BUZZER jmp BuzzerTimeOver02 BuzzerTimeOver01: b0bclr BUZZER ;buzzer off b0bset BuzzerIsOn BuzzerTimeOver02: b0bts0 BuzzerIsOn jmp BuzzerRet decms BuzNumber jmp BuzzerRet BuzzerStop: b0bclr BuzzerEnable b0bclr BuzzerIsOn BuzzerRet: endm ;***************************** include define.asm .CODE org 0x00 jmp Reset org 0x08 jmp Interrupt
org 0x10 ;******************* Multiplication: ; b0MOV a,CurrentL b0MOV a,VoltageL mul a,VoltageL b0MOV ELO,a b0MOV a,R b0MOV ALO,a ; b0MOV a,CurrentH b0MOV a,VoltageH mul a,VoltageL add a,ALO b0MOV EHI,a b0MOV a,R b0MOV DLO,a b0bts0 FC incms DLO nop clr DHI
; b0MOV a,CurrentL b0MOV a,VoltageL mul a,VoltageH b0MOV CLO,a b0MOV a,R b0MOV ALO,a ; b0MOV a,CurrentH b0MOV a,VoltageH mul a,VoltageH add a,ALO b0MOV CHI,a b0MOV a,R b0MOV BLO,a b0bts0 FC incms BLO nop b0bclr FC b0MOV a,CLO adc EHI,a b0MOV a,CHI adc DLO,a b0MOV a,BLO adc DHI,a b0MOV a,ELO mul a,CurrentH b0MOV CLO,a b0MOV a,R b0MOV ALO,a b0MOV a,EHI mul a,CurrentH add a,ALO b0MOV CHI,a b0MOV a,R b0MOV ALO,a b0MOV a,DLO mul a,CurrentH add a,ALO b0MOV BLO,a b0MOV a,R b0MOV BHI,a
b0MOV a,ELO mul a,CurrentL b0MOV ELO,a b0MOV a,R b0MOV ALO,a b0MOV a,EHI mul a,CurrentL add a,ALO b0MOV EHI,a b0MOV a,R b0MOV ALO,a b0MOV a,DLO mul a,CurrentL add a,ALO b0MOV DLO,a b0MOV a,R b0MOV DHI,a b0bclr FC b0MOV a,CLO adc EHI,a b0MOV a,CHI adc DLO,a b0MOV a,BLO adc DHI,a b0bts0 FC incms BHI nop ret ;;;;;==================================== Mpy16: ;;;INPUT (BY MULTIPLIER)AHI,ALO;(MULTIPLIER)BHI,BLO ;;;OUT DHI,DLO,EHI,ELO ;;;====================================== MOV a,#10h b0MOV counter,a clr DHI clr DLO b0bclr FC ;;;;; Mpyloop: rrcm BHI rrcm BLO b0bts1 FC jmp Notadd ;;;; MOV a,ALO add DLO,a b0bts0 FC incms DHI nop MOV a,AHI add DHI,a ;;;; Notadd: rrcm DHI rrcm DLO rrcm EHI rrcm ELO decms counter jmp Mpyloop ret ;;========================================== Div32: ;;;INPUT :(DIVID)AHI,ALO;(BY DIVID)DHI,DLO,EHI,ELO ;;;OUTPUT :(RESULT)BHI,BLO;(REST)CHI,CLO ;;========================================== MOV a,#20h b0MOV counter,a clr BHI clr BLO clr CHI clr CLO ;;;;;;;;;;; Divloop: b0bclr FC rlcm ELO rlcm EHI rlcm DLO rlcm DHI rlcm CLO rlcm CHI b0MOV a,CHI sub a,AHI b0bts1 FZ jmp Nochk b0MOV a,CLO sub a,ALO b0bts1 FC jmp Nogo jmp Nochk01 Nochk: b0bts1 FC jmp Nogo b0MOV a,CLO sub a,ALO b0bts1 FC decms CHI nop Nochk01: b0MOV a,CLO sub a,ALO b0MOV CLO,a b0MOV a,CHI sub a,AHI b0MOV CHI,a b0bset FC Nogo: rlcm BLO rlcm BHI decms counter jmp Divloop ret ;********* ;*************************** CalculatePower: ; CLR AHI ; MOV a,#0xdc ; b0MOV ALO,a ;220V ; b0MOV a,CurrentL ; b0MOV BLO,a ; b0MOV a,CurrentH ; b0MOV BHI,a ; call Mpy16 b0MOV a,CurrentH sub a,#3 b0bts1 FC ; jmp $+5 ; b0MOV a,CurrentL ; sub a,#0xf0 ; b0bts1 FC jmp CalculatePowerError clr errorcounter1 b0bclr CurrentError call Multiplication
b0MOV a,BHI b0bts1 FZ jmp DecTime b0MOV a,DHI sub a,PowerBufferHH b0bts1 FZ jmp NotAdj
b0MOV a,DLO sub a,PowerBufferH b0bts1 FZ jmp NotAdj AdjMiddle: b0MOV a,EHI sub a,PowerBufferM b0bts1 FZ jmp NotAdj AdjLow: b0MOV a,ELO sub a,PowerBufferL NotAdj: b0bts1 FC jmp IncTime DecTime: b0MOV a,TimerDrvH sub a,#0x30 b0bts1 FC ret decms TimerDrvH nop ret IncTime: b0MOV a,TimerDrvH sub a,#0xf0 b0bts0 FC ret incms TimerDrvH nop ret CalculatePowerError: b0MOV a,errorcounter1 sub a,#250 b0bts0 FC jmp $+3 incms errorcounter1 ret b0bset CurrentError ret ;**************************** BuzShort_10: b0bset BuzzerShort MOV a,#10 jmp BuzActive BuzLong_5: b0bclr BuzzerShort MOV a,#5 jmp BuzActive BuzShort_3: MOV a,#3 jmp $+2 BuzShort_1: MOV a,#1 b0bset BuzzerShort BuzActive: b0MOV BuzNumber,a b0bset BuzzerIsOn clr TimerBuz b0bclr BUZZER b0bset BuzzerEnable ret
;**************************** ;Test temperature subroutine ;**************************** TestTemperature: ; b0bclr TestTemperatureEnable b0bclr FADLEN MOV a,#0x93 b0MOV ADM,a MOV a,#0x20 b0MOV ADR,a b0bset FADS b0bts1 FEOC jmp $-1 b0MOV a,ADB b0MOV resultH,a b0MOV a,ADR and a,#00001111b b0MOV resultL,a swap resultH and a,#11110000b or resultL,a swapm resultH MOV a,#00001111b and resultH,a b0MOV a,resultH b0bts1 FZ jmp $+5 b0MOV a,resultL sub a,#0x10 b0bts1 FC jmp TestTemperature01 b0MOV a,resultH sub a,#0x0f b0bts0 FC jmp TestTemperature01
clr errorcounter b0bclr TempError ret TestTemperature01: b0MOV a,errorcounter sub a,#5 b0bts0 FC jmp $+3 incms errorcounter ret b0bset TempError ret ;**************************** ;Test current subroutine ;**************************** TestCurrent: b0bclr FADLEN MOV a,#0x97 b0MOV ADM,a MOV a,#0x20 b0MOV ADR,a b0bset FADS b0bts1 FEOC jmp $-1 b0MOV a,ADB b0MOV CurrentH,a b0MOV a,ADR and a,#00001111b b0MOV CurrentL,a swap CurrentH and a,#11110000b or CurrentL,a swapm CurrentH MOV a,#00001111b and CurrentH,a ret ;**************************** ;Test voltage subroutine ;**************************** TestVoltage: b0bclr FADLEN MOV a,#0x91 b0MOV ADM,a MOV a,#0x20 b0MOV ADR,a b0bset FADS b0bts1 FEOC jmp $-1 b0MOV a,ADB b0MOV VoltageH,a b0MOV a,ADR and a,#00001111b b0MOV VoltageL,a swap VoltageH and a,#11110000b or VoltageL,a swapm VoltageH MOV a,#00001111b and VoltageH,a ret ;********************* SystemTimerEnd: b0bclr F4mS incms TimerBuz nop incms Timer nop b0bclr Flash b0MOV a,Timer sub a,#125 b0bts1 FC jmp SystemTimerEnd01 b0bset Flash b0MOV a,Timer sub a,#250 b0bts1 FC jmp SystemTimerEnd01 clr Timer b0bts1 FanActive jmp $+5 decms FanTime jmp $+3 b0bclr FanActive b0bclr Fan b0bts1 Timering jmp SystemTimerEnd01 incms Second nop b0MOV a,Second sub a,#60 b0bts1 FC jmp SystemTimerEnd01 clr Second decms Minute nop SystemTimerEnd01: incms TestTemperatureTime nop b0MOV a,TestTemperatureTime sub a,#125 b0bts1 FC jmp $+3 clr TestTemperatureTime b0bset TestTemperatureEnable incms TestCurrentTime nop MOV a,TestCurrentTime sub a,#10 b0bts1 FC jmp $+3 clr TestCurrentTime b0bset TestCurrentEnable
incms KeyScanTime nop MOV a,KeyScanTime sub a,#10 b0bts1 FC jmp $+3 clr KeyScanTime b0bset KeyScanEnable DisplayScan: clr P2 call TimeDisplay incms commbuffer nop b0MOV a,commbuffer sub a,#0x05 b0bts1 FC jmp DisplayScan01 clr commbuffer ; clr keyactivebuffer DisplayScan01: b0MOV a,commbuffer cmprs a,#1 jmp $+2 jmp DisplayScan03 cmprs a,#2 jmp $+2 jmp DisplayScan04 cmprs a,#3 jmp $+2 jmp DisplayScan05 cmprs a,#4 jmp $+2 jmp DisplayScan06 DisplayScan02: b0bset COM0 b0MOV a,data0 jmp DisplayScanEnd DisplayScan03: b0bset COM1 b0MOV a,data1 jmp DisplayScanEnd DisplayScan04: b0bset COM2 b0MOV a,data2 jmp DisplayScanEnd DisplayScan05: b0bset COM3 b0MOV a,data3 jmp DisplayScanEnd DisplayScan06: b0bset COM4 b0bts0 On jmp DisplayScan07 b0bclr DisplayOnOff b0bts0 Flash b0bset DisplayOnOff DisplayScan07: b0MOV a,data4 DisplayScanEnd: xor a,#0xff b0MOV displaybuffer,a MOV a,#10001111b and P4,a MOV a,displaybuffer and a,#01110000b or P4,a b0bclr P5.0 b0bts0 displaybuffer.0 b0bset P5.0 ret ;*************************** ;interrput subroutine ;********************* Interrupt: b0bset FWDRST push b0MOV accbuf,a b0bclr FGIE b0bts0 FT0IRQ jmp SystemTimer b0bts0 FP02IRQ jmp IntZero b0bts0 FP01IRQ jmp IntTest clr INTRQ jmp InterruptEnd ;********************* SystemTimer: b0bclr FT0IRQ MOV a,#192 ;156 ;50uS b0MOV T0C,a incms Timer200uS nop b0MOV a,Timer200uS sub a,#125 ;64 b0bts1 FC jmp SystemTimer01 clr Timer200uS b0bset F4mS SystemTimer01: b0MOV a,TimerDrv b0bts0 FZ jmp SystemTimer02 decms TimerDrv nop jmp InterruptEnd SystemTimer02: b0bts1 Fdrv jmp SystemTimer03 b0bclr Fdrv b0MOV a,TimerDrvH b0MOV TimerDrv,a b0bset DRV jmp InterruptEnd SystemTimer03: b0bclr DRV InterruptEnd: b0MOV a,accbuf pop reti ;********************************** IntTest: b0bclr FP01IRQ clr TestTime jmp InterruptEnd ;********************************** IntZero: b0bclr FP02IRQ b0bclr DRV b0bset Fdrv MOV a,#0xff sub a,TimerDrvH b0MOV TimerDrv,a jmp InterruptEnd ;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ;*************** KeyScan: b0MOV a,P1 xor a,#0xff b0MOV buffer,a rrcm buffer rrcm buffer b0MOV a,buffer and a,#00001111b b0MOV keybuffer,a b0MOV buffer,a clr keycounter2 MOV a,#4 b0MOV keycounter1,a KeyScan01: rrcm buffer b0bts0 FC incms keycounter2 decms keycounter1 jmp KeyScan01 b0bclr KeyActive MOV a,keycounter2 b0bts0 FZ jmp KeyScan02 cmprs a,#1 ret b0MOV a,keybuffer cmprs a,keyactivebuffer jmp $+2 ret b0bset KeyActive b0MOV a,keybuffer b0MOV keyactivebuffer,a ret KeyScan02: clr keyactivebuffer clr keybuffer ret ;***************** DataVerify: clr Y b0MOV Z,#0x0e MOV a,#0x00 DataVerify01: add a,@YZ decms Z jmp DataVerify01 add a,@YZ ret ;****************** TimeDisplay: clr data0 clr data1 b0MOV a,Minute b0bts0 FZ ret sub a,#11 b0bts1 FC jmp D10 b0MOV a,Minute sub a,#21 b0bts1 FC jmp D20 b0MOV a,Minute sub a,#31 b0bts1 FC jmp D30 b0MOV a,Minute sub a,#41 b0bts1 FC jmp D40 b0MOV a,Minute sub a,#51 b0bts1 FC jmp D50 D60: b0bset DisplayTime60 ret D50: b0bset DisplayTime50 ret D40: b0bset DisplayTime40 ret D30: b0bset DisplayTime30 ret D20: b0bset DisplayTime20 ret D10: b0bset DisplayTime10 ret ;*************** ;Main program ;****************
Reset: b0bclr FGIE InitPort call DataVerify cmprs a,sumbuffer jmp Init02 b0MOV Z,#0eh Init01: b0MOV a,@YZ b0bts1 FZ jmp Init06 decms Z jmp Init01 Init02: ClearRam clr flag0 b0bset BUZZER b0bclr DRV call BuzShort_3 ;****** ;****** Init06: b0MOV a,port1copy b0MOV P1,a b0MOV a,port2copy b0MOV P2,a b0MOV a,port4copy b0MOV P4,a b0MOV a,port5copy b0MOV P5,a b0bset FGIE clr INTRQ Main: b0bset FWDRST call DataVerify b0MOV sumbuffer,a b0MOV a,P1 b0MOV port1copy,a b0MOV a,P2 b0MOV port2copy,a b0MOV a,P4 b0MOV port4copy,a b0MOV a,P5 b0MOV port5copy,a
BuzzerActive
b0bts0 F4mS call SystemTimerEnd
b0bts0 CurrentError jmp $+10 b0bts0 TempError jmp $+8 b0bts1 Timering jmp $+8 b0MOV a,Minute b0bts1 FZ jmp $+5 call BuzLong_5 jmp $+2 call BuzShort_10 jmp OnOff01 b0bts1 KeyScanEnable jmp NotKeyScan b0bclr KeyScanEnable call KeyScan NotKeyScan: b0bts0 KeyActive jmp ReadKey b0bts1 On jmp Main b0bts1 TestTemperatureEnable jmp NotTestTemperature call TestTemperature b0bclr TestTemperatureEnable b0MOV a,resultH sub a,TemperatureH b0bts1 FZ jmp $+3 b0MOV a,resultL sub a,TemperatureL b0bts1 FC jmp $+6 b0bclr DRV b0bset Off b0bclr FP02IEN b0bclr FP02IRQ jmp Main b0bts1 Off jmp NotTestTemperature b0bclr Off b0bset FP02IEN MOV a,#0x40 b0MOV TimerDrvH,a jmp Main NotTestTemperature: ; b0bts1 On ; jmp Main b0bts1 TestCurrentEnable jmp Main call TestCurrent b0bclr TestCurrentEnable call TestVoltage call CalculatePower NotTestCurrent: jmp Main ;************ ReadKey: b0bclr KeyActive b0bts0 Konoff jmp OnOff b0bts1 On jmp Main call BuzShort_1 b0bts0 Kmode jmp Mode b0bts0 Kpower jmp Power ;******************* Time: incms TimeBuffer nop b0MOV a,TimeBuffer sub a,#7 b0bts1 FC jmp Time01 clr TimeBuffer Time01: MOV a,TimeBuffer b0MOV Y,#TimeTable$m b0MOV Z,#TimeTable$l add Z,a MOVc b0MOV Minute,a clr Second b0bset Timering b0MOV a,TimeBuffer b0bts0 FZ b0bclr Timering jmp Main ;**************************** OnOff: call BuzShort_1 b0bts1 On jmp OnOff02 OnOff01: b0bclr On b0bclr Timering call Close clr data0 clr data1 clr data2 clr data3 clr data4 clr ModeBuffer clr PowerBuffer clr TimeBuffer clr Minute clr errorcounter b0bclr TempError b0bclr CurrentError clr errorcounter1 b0bclr FP02IEN b0bclr FP01IEN jmp Main OnOff02: b0bset On call Open b0bset DisplayOnOff b0bset DisplayMode1 b0bset DisplayPower3 MOV a,#3 b0MOV ModeBuffer,a b0MOV PowerBuffer,a clr TimeBuffer b0bset FP02IEN b0bset FP01IEN MOV a,#0x80 b0MOV TimerDrvH,a ; MOV a,#100 ; b0MOV TimerDrv,a jmp Mode01 ;**************************** Mode: incms ModeBuffer nop b0MOV a,ModeBuffer sub a,#6 b0bts1 FC jmp Mode01 MOV a,#1 b0MOV ModeBuffer,a Mode01: b0bclr DisplayMode1 b0bclr DisplayMode2 b0bclr DisplayMode3 b0bclr DisplayMode4 b0bclr DisplayMode5 MOV a,ModeBuffer cmprs a,#1 jmp $+2 jmp Mode1 cmprs a,#2 jmp $+2 jmp Mode2 cmprs a,#3 jmp $+2 jmp Mode3 cmprs a,#4 jmp $+2 jmp Mode4 Mode5: b0bset DisplayMode5 MOV a,#5 jmp ModeEnd Mode1: b0bset DisplayMode1 MOV a,#3 jmp ModeEnd Mode2: b0bset DisplayMode2 MOV a,#3 jmp ModeEnd Mode3: b0bset DisplayMode3 MOV a,#3 jmp ModeEnd Mode4: b0bset DisplayMode4 MOV a,#4 ModeEnd: b0MOV PowerBuffer,a jmp Power01 ;**************************** Power: incms PowerBuffer nop b0MOV a,PowerBuffer sub a,#7 b0bts1 FC jmp Power01 MOV a,#1 b0MOV PowerBuffer,a Power01: clr data2 b0bclr DisplayPower6 b0bclr DisplayPower5 MOV a,PowerBuffer cmprs a,#1 jmp $+2 jmp Power1 cmprs a,#2 jmp $+2 jmp Power2 cmprs a,#3 jmp $+2 jmp Power3 cmprs a,#4 jmp $+2 jmp Power4 cmprs a,#5 jmp $+2 jmp Power5 Power6: b0bset DisplayPower6 Power5: b0bset DisplayPower5 Power4: b0bset DisplayPower4 Power3: b0bset DisplayPower3 Power2: b0bset DisplayPower2 Power1: b0bset DisplayPower1 b0MOV a,PowerBuffer b0MOV Y,#PowerTable$m b0MOV Z,#PowerTable$l add Z,a MOVc b0MOV PowerBufferL,a b0MOV a,R b0MOV PowerBufferM,a b0MOV a,PowerBuffer b0MOV Y,#PowerTableH$m b0MOV Z,#PowerTableH$l add Z,a MOVc b0MOV PowerBufferH,a b0MOV a,R b0MOV PowerBufferHH,a b0MOV a,PowerBuffer b0MOV Y,#TemperatureTable$m b0MOV Z,#TemperatureTable$l add Z,a MOVc b0MOV TemperatureL,a b0MOV a,R b0MOV TemperatureH,a jmp Main ;************** Close: b0bset FanActive MOV a,#120 b0MOV FanTime,a ret ;************** Open: b0bset FAN b0bclr FanActive ret PowerTable: ; dw 0x0000,0x45d1,0x8342,0xc0b2,0xfe23,0x3b94,0x7904 dw 0x0000,0x0ed6,0x8601,0xfd2c,0x7457,0xeb85,0x62ad PowerTableH: ; dw 0x00,0x17,0x21,0x2b,0x35,0x40,0x4a dw 0x0000,0x4a6b,0x6b29,0x8be7,0xaca6,0xcd64,0xee23 TimeTable: dw 0x00,10,20,30,40,50,60 TemperatureTable: ; dw 0x0000,0x013e,0x03a2,0x0674,0x0940,0x0b5c,0x0c4b dw 0x0000,0x00e7,0x02e3,0x0578,0x085c,0x0ad0,0x0bdb
|